Automate your database backups using cron jobs in cpanel
February 22nd, 2008
I’ve been trying to do this off and on for years. Finally, finally I found the answer, and it is actually working! This is for people hosting with a service that uses Cpanel. Quick step by step:
- Log into cpanel and choose the MySQL Database link
- Create a database user named “backup” and add that user with full permissions to each database you have
- Go back to the cpanel home and choose the Cron jobs link
- If you want to run your backup at midnight every night, then choose the Advanced option
- Advanced: Leave all of the “Minute Hour Day Month Weekday” options at their default
- Standard: Use the form fields to choose how often you would like to run your backups, and at what time.
- BOTH: Paste the following line into the Command field (There are only two changes that need to be made to the line below: change DBPASSWORD to the database password you created for your MySQL user “backup” and change YOURACCOUNT to your account username)
date=`date -I` ; mysqldump -ubackup -pPASSWORD -A | gzip > /home/YOURACCOUNT/xbackup_$date.sql.gz - Click Commit changes and you are all done.
This should create a gzipped file in the root directory of your account named something like xbackup_2008-02-21.sql.gz. Now you can use something cool like FTP Synchronizer to create your own backups. More on that later.
Filed under Website development |Leave a Reply