Automating WordPress Backups on Godaddy

If you have ever tried to backup a wordpress site on godaddy you are in for a treat, I decided to write this article in case I ever needed to go through this again and in the hopes that it may help someone else. If you’re like me, you have one or more wordpress sites that you would like to ensure are backed up before a disaster occurs and rather than use wordpress plugins which may break due to software upgrades I’d rather roll my own that leverages cron, tar, and scp.

Turn on SSH

If you want to test out your backup script before you add it to cron you will need to activate SSH. Godaddy doesnt have ssh on by default so you have to enable it. To do this go to the “Hosting Control Center” and select “SSH” under the “Settings” menu.

From here you can click the “Enable” button to turn on ssh access. SSH will use the same FTP username and password you have configured for the godaddy account. You should be able to connect using any ssh client, for you windows users I recommend putty. Once you have logged in you should be at a bask prompt. I should note that if you have an ultimate hosting account and are hosting more than one website you should be ssh’ing to the primary domain which is under “Settings” and “Hosted Domains”.

There are a million different ways to skin this cat, for me I like Godaddy’s built in file restore and database backup but always want to make sure I have a full off-site backup just in case. To accomplish this I will run a weekly cron job to back up all wordpress sites and the associated databases so that in case of an emergency they can be restored to Godaddy or even another hosting provider. The script below is an example of the script I run, you will need to customize this based on your environment.

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash

DATE=`date +%m%d%y`

/usr/bin/mysqldump -h databasehostaddress.db.hostedresource.com -u databaseusername -pdatabaseuserpassword databasename > $HOME/html/_db_backups/daily/databasename.$DATE.sql

cp -r $HOME/html/wordpressfolder $HOME/html/_db_backups/daily

# Zipping directory structure...
tar -cvzf $HOME/html/_db_backups/$DATE.tar.gz $HOME/html/_db_backups/daily/*

# Cleansing backup folder
rm -r $HOME/html/_db_backups/daily/*

To run this script you will need to create the _db_backups directory as well as the daily subdirectory otherwise the primitive script will fail. Using the FTP file manager from godaddy you should be able to create the backup.sh script file under the _db_backups folder. You will also need to mark it as executable so it may run. In FTP File Manager just click the check box of the shell script file and “permissions” at the top and make sure executable is checked you will see a additional graphic next to the file once you apply the change.

Now you are ready to create a Cron Job for your shell script to execute. To diagnose any errors you may get make sure when creating the Cron Job you include an email address for the errors to be delivered. Enable the Cron Job and change the Frequency to “Weekly” and Minute to whatever is closest for the script to execute.