Scheduling mySQL backups

I’m sure there is no need to explain the virtues of regular backups. Below are three steps to peace of mind

1) Configure a backup directory on the server

mkdir /var/lib/backupfolder
cd /var/lib/backupfolder

2) Make a backup script


# MySQL server username goes here
# MySQL server password goes here
# List of DBNAMES for Backup
#date timestamp used in the log
DATE=`/bin/date +%Y-%m-%d_%Hh%Mm`
# format the output file
#working directory
#cd $DIR
# Do the MySQL Backup
/usr/bin/mysqldump --database $DBNAME --opt --single-transaction -u$USERNAME -p$PASSWORD | /usr/bin/gzip -9 > $OUTDIR$OUTFILE

Dont forget to change permissions

chmod +x

3) Schedule the backup in crontab

crontab -e

Add something along the lines of:

30 23 * * * /var/lib/backupfolder/

To backup at 11:30PM every day. Just as important as to backup up is to test restores; – it’s no good having backups and feeling at ease if you cant recover in the event of catastrophe!

Leave a Reply

Your email address will not be published. Required fields are marked *