Python MySQL Backup Script

Here is a simple python based MySQL backup script. It will individually dump all your MySQL databases and then tar gzip them to a specified location.

Having Python installed is the only real prerequisite.

Script Details

Note, that the script isn’t verbose unless there is an error. This is so you can schedule it as a cron job, and only get an email when something goes wrong.

It also uses a configuration file as a security precaution. The reason for using a config file, it prevents the user and password being visible in the running processes list. So for example if you were running a mysqldump and put password into your command line, another user could query the running processes and see the password.

I typically store my scripts in the /usr/local/bin directory of my Linux systems. In general, it’s a good place to store custom scripts and applications.

You’ll also need to create your configuration file, like below:

In my case, I store the config file as /etc/mysql.cnf however make sure that it’s only readable by the root user.

Continue reading…