A Simple MySQL Backup Script

It was time to deploy the project into the production server. Almost everything is complete. The pages are running smoothly, the scheduler for current weather forecast and the database is fully optimized.

One lacking is the daily database backup. I decided it to be daily since it is not that critical, so here is my script for the daily MySQL Backup.

date=`date +%Y-%m-%d-%H-%M-%S`
mysqldump rani -u db_user -pthePassw0rd | gzip -c > $backup

It simply backs up the database using mysqldump utility, and pipe it to gzip utility to compress the file and finally saves into the backup path. By the way it uses the current date and time appended to the filename.

Schedule it every midnight as specified by @daily here:

Leave a reply

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