Having been on many shared hosting platforms before, I am fortunate enough to have a few (gs) Grid Services with (mt) Media Temple. Although no native backup tool currently exists for the (gs), I've created some simple backup scripts to backup the domain directories and MySQL databases. Both are very simple bash scripts that can be set up as cron jobs from with the AccountCenter. The first backup we'll create is for domain backups:
- If you haven't done so already, enable SSH from the (mt) Media Temple AccountCenter.
- Once you've logged in via SSH, navigate to the /data directory. Keep in mind you'll need to add your site number in the 00000 for this to work. You can find your site number in the Server Guide > Access Domain section of the AccountCenter.
- Run the following commands to create and set permissions of the backup directory:
- Create a file called backup.sh and make it executable:
- Open the file in a text editor or vim and paste in the following:
This really simple script creates a tar.gz backup of the example.com directory, stamps it with the current date and places it in the the backup folder we just created. It will also prune any backup older than 7 days old. This number can be adjusted by tweaking the
MaxFileAge value. Before saving the file, be sure to make the necessary adjustments for your site number after the /home directory. You'll also need to modify example.com for the actual domain you'll be backing up. Before adding it as a cron, run the script via SSH -- the output should look like this:
example.com@n10:/home/00000/data$ ./backup.sh * Performing domain backup... * Backed up...
Depending on the size, the backup may hesitate after the initialization while the domain directory is being compressed. You can now verify that the new backup is in the
/home/#####/data/backup/ directory with the today's date:
example.com_25_10_09.tar.gz. Once you've confirmed the backup works, add the backup.sh file as a cron within the AccountCenter following this KnowledgeBase article. You can schedule the cron as frequent as you would like.
Now, you've probably got at least 1 MySQL database that should be backed up as well. This can be accomplished just as easily.
SSH back into the /data directory and create a new bash script file:
Now, open the file in a text editor or vim and paste in the following:
This bash script uses mysqldump to dump a MySQL database which stamps it with the current date and places it in the the backup folder we created before. This will also prune any database backups that are older than 7 days. Before saving the file, be sure to make the necessary adjustments for your site number and database credentials -- all of this can be found under the Manage Databases section of the AccountCenter. Before adding it as a cron, run the script via SSH -- the output should look like this:
example.com@n10:/home/00000/data$ ./db-backup.sh * Performing SQL dump... * Backed up...
Once you've confirmed the script completes without errors, add it as a cron job so you'll never have to worry about losing your MySQL data again!