September 13th, 2007Cron job for database backup
This cron job allows you make automatic backups of your database and delete the backup files older than 7 days. You can set the backups to occur daily and use the following command for the cron:
cd BACKUPS_PATH; /usr/bin/mysqldump --opt -u DBUSER -pPASSWD DBNAME | gzip > DBNAME_`date "+%Y%m%d"`.sql.gz ; /usr/bin/find *.gz -mtime +7 | xargs /bin/rm -f
You should replace DBUSER, PASSWD, DBNAME with their respective values. Also BACKUPS_PATH should be replaced by the folder where you want to store your backup files (/home/yourdomain/public_html/backups or /var/www/vhosts/backups, …)
There is no space between -p and PASSWD.
One Response to “Cron job for database backup”
Leave a Reply
You must be logged in to post a comment.