|
I've searched for ways to automatically backup my MySQL databases on my shared godaddy Linux hosting and stumbled onto two articles that I used to formulate my own Cron job backup procedure. I tried a bash script and some php, but could not get it working - so anybody should be able to get this up and running on godaddy just as easily as I have. What I wanted:
- Automatic daily backups of specified MySQL database
- A backup kept for each day of the week, overwritten weekly
- Automatic monthly backups of last daily backup
- A backup kept for each month of the year, overwritten yearly
- All backups should be zipped
- Automatic download of archivesto my pc
What I have achieved thus far:
- Everything but the last point, but I have a scheduled backup of my whole web site to my pc and the backup files are included in that, so I'm fine with that
How did I do it:
Find the host name for my MySQL database - read this help article for godaddy instructions Read this article by "Quarterbore" to find out how to zip and automatically name and copy files with a Cron job. Read this article by Bala_Krishna to see how to set up my godaddy Cron job without a saved script
OK, so just incase these articles suddenly dissapear, I'll summarize here below:
MySQL Host Name Log in to your godaddy Account Manager. In the My Products section, select Hosting Account List. Next to the hosting account you want to modify, click Open. In the Databases section of the Hosting Control Center, click the MySQL icon. From your list of databases, click the Pencil icon next to the database you want more information about. The Database Information page displays. You will find the host name for your database on this page.
Define Cron Command Line Daily Backups mysqldump --opt -Q -h [your database host name] --user=[your database admin user name] --password=[your database password] [your database name] | gzip -v9 - > [your full path and file name - something like /home/content/a/b/c/abcdomain/html/_db_backups/MySQL-`/bin/date +\%a`.sql.gz] The file name in this case is MySQL-`/bin/date +\%a`.sql.gz which would result in a file called MySQL-Mon.sql.gz if run on a Monday. - Mine looks like this (I've changed the exact details of my own setup)
- mysqldump --opt -Q -h p8smysql66.secureserver.net --user=abc5687412957483 --password=MyPassword1 abc5687412957483 | gzip -v9 - > /home/content/a/b/c/abcdomain/html/_db_backups/MySQL-`/bin/date +\%a`.sql.gz
Monthly Backups cp [exact same path and file name as in the above example] [destination path and file name of copied backup fle - something like /home/content/a/b/c/abcdomain/html/_db_archives/MySQL-`/bin/date +\%m`.sql.gz] The file name of the month backup in this case is MySQL-`/bin/date +\%m`.sql.gz, which would result in a file name of MySQL-03.sql.gz if run in March. - Mine looks like this (I've changed the exact details of my own setup)
- cp /home/content/a/b/c/abcdomain/html/_db_backups/MySQL-`/bin/date +\%a`.sql.gz /home/content/a/b/c/abcdomain/html/_db_archives/MySQL-`/bin/date +\%m`.sql.gz
Set up GoDaddy Cron Job Log Into your GoDaddy.com account. Choose “My Hosting Account” from the “Hosting & Servers” menu on the top navigation bar. In the Hosting Account list, click the Open link beside the account you want to use for your website. In the Hosting Manager window, click the Cron Manager icon or “Cron Manager” menu item under content menu. Now you are on the page where you need to setup two cron jobs: one to run daily for the daily backups and one to run monthly for the monthly backups. The monthly one can run on any date of the month, just as long as the time it runs at is after the daily backup run. You need to know the following: Host Name: (Usually localhost but in case of godaddy account it will be look like mysql123.secureserver.net) Database Name: Name of the your database. User Name: User name of the database. In case of godaddy account it will be same as db name. DB Password: Database user password for authentication.
Use the various drop downs to schedule your Cron job and enter the Cron Command Line you have created.
And that's that!
|