I’ve posted a couple of articles now on making MySQL backups using Cron, time-based scheduler, on Linux based hosting.
This is, currently, the last post on this subject. The examples so far have been on backing up single databases, but it is possible to backup multiple databases using one command.
The below example shows the syntax to make a compressed backup of all mySQL databases, with the sections to change highlighted:
/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk)
This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int).
*/
/usr/bin/mysqldump -u {username} -p'{password}' --all-databases | gzip -c > /home/{username}/backups/backup_{databasename}_$(date +\%Y\%m\%d\%H\%M\%S).sql.gz
The below example shows the syntax to make a compressed backup of multiple named mySQL databases, with the sections to change highlighted (any additional database names can be specified):
/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk)
This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int).
*/
/usr/bin/mysqldump -u {username} -p'{password}' --databases {databasename} {databasename} | gzip -c > /home/{username}/backups/backup_{databasename}_$(date +\%Y\%m\%d\%H\%M\%S).sql.gz
What should we write about next?
If there is a topic which fits the typical ones of this site, which you would like to see me write about, please use the form, below, to submit your idea.
1 thought on “Making compressed MySQL backups of multiple databases using Cron”