Simple MySql Backup Script
December 30th, 2008 Category: PHP/MySQLThe following example scripts performs a simple backup of all MySQL databases. The resulting .sql file is automatically zipped. Using “find” backups older than 3 days are deleted, so you will get complete backups of the last 3 days.
This script is intended to be called periodically (e.g. every day) from cron:
2 2 * * * root /root/scripts/mysql_backup.sh
#/bin/sh
now=`date "+%Y-%m-%d"`
user="mysql_user"
password="mysql_password"
path="/home/backup/"
cd $path
mysqldump -u $user -p$password --all-databases | gzip -c > backup_all_$now.sql.gz
# delete files older than 3 days
find . -name "*.gz" -type f -mtime +3 -exec rm {} ";"













Leave a Reply