(gs):Create timestamped website backups
- This page was last modified on September 15, 2011, at 15:12.
From (mt) Community Wiki
Contents |
Ever wanted to make daily backups of your website, but didn't want to fiddle with doing it by hand every day? Ever made a bunch of daily backups, but couldn't remember which file was for which day? Well, fret no more!
Setup, configuration, and troubleshooting is not supported by (mt) Media Temple.
Requirements
This article requires using SSH, basic command-line scripting, vi (or your favorite text editor), chmod, and cron. The steps below are written with the assumption that you are connected to the server via SSH.
For (gs) Grid-Service users, when you see 00000, you need to insert your Site Number. This can be obtained from the Server Guide inside the AccountCenter.
For a (gs) Grid-Service
1. Decide which domain you want to back up. I want to back-up the alternate domain "foobar.com". The primary domain for this exercise is example.com. Let's change into the main directory for foobar, and use the vi text editor to create a new file called "backup.sh":
hostname:~$ cd domains/foobar.com hostname:~$:~/domains/foobar.com$ vi backup.sh
2. Add the following information into the backup.sh file, and then save:
#!/bin/sh cd ~/domains/foobar.com zip -r backup`date '+%Y-%m-%d'`.zip html/*
3. Run the command chmod 744 backup.sh, which will make the file executable by the owner (that's you!):
hostname:~$:~/domains/foobar.com$ chmod 744 backup.sh
4. Just to make sure it works, test it out:
hostname:~$s:~/domains/foobar.com$ ./backup.sh
5. You should see lines appearing on the screen as each file and folder is added to the archive. They will look something like this:
adding: html/Media.php (deflated 24%) adding: html/Temple.txt (deflated 61%) adding: html/Totally.ico (deflated 44%) adding: html/Rocks.mp3 (deflated 68%) adding: html/Yay/Media/Temple.html (deflated 51%)
When you perform a list directory command (ls), you should see a file called "backup08.02.10.zip", or whatever is the corresponding date. So now that we have a working script, it's time to make a regularly occurring job out of it.
6. From inside the AccountCenter, choose the admin button and then click Cron Jobs. Look for this icon:
8. Fill out the notification email field. This is important, so you are notified if the cron job fails.
9. Fill out the "Command or script to execute" field with the full path to your backup. In this example, it will be
/home/00000/domains/foobar.com/backup.sh
10. Choose what time you want the cron job to run. Since this will be a daily backup, you might want to specify 12:00am daily. Or perhaps you would rather back things up at 6:00pm, or at 8:45am; it is up to you.
11. Once you are satisfied, press the save button.
Notes
The (gs) only allows five cron jobs, and also institute restrictions into the length of time a cron job can be run.
- 5 minutes of CPU time
- 15 minutes of actual time
- 200 simultaneous file descriptors
- 100MB of RAM
- 5 simultaneous processes
Notes
The script provided can be made much more advanced, to include features like incremental backups, and automatic pruning of backups older than X number of days. Those modifications are beyond the scope of this document.