Backup MySQL via Bash Script

If you run your own LAMP server, you might want to check out this Bash script which perform backups of the MySQL database. The neat little script can be set to run independently or as part of a cron job. All you have to do is provide the backup directory, username, password, hostname and port number.

The backup script is quite simple. It checks if the backup directory exists and creates one if it’s missing. It will then list all databases and performs a MySQL dump of each database ignoring the mysql, information_schema, and test databases. The file is formatted in gzip and then stored in the backup directory.

The backup script can be set to run every day or once a week using cron. The backup will depend on your backup requirements. I recommend testing the backup and restore process to see if it works.