Cron jobs for rotating backups on Rackspace Cloud

I had found several scripts to run as cron jobs to create rolling back ups of my sites. But I couldn’t get any of them to work. The rolling backs ups that is. I turned to RSC tech support and they referred me to this blog post:

It worked the first time. The only changes I made were to set the script with the proper variables for my site.

Then I went ahead and modified the scripts so I had 7 days of daily backups and created a second script and cron job for 8 weeks of weekly backups. What is great about this script is I can set the frequency of the Cron jobs such that I tested the full run in one day. I set the daily script to run every 5 minutes and the weekly script every hour.

Here is my daily script

 # Modeled after <a href="" target="_blank" rel="nofollow"></a>

 # ACCOUNT_ROOT can be found on the Features tab in the control panel for the site
 export ACCOUNT_ROOT="/mnt/stor2-wc2-dfw1/427054/"
 export WEB_ROOT="${ACCOUNT_ROOT}/web/content"
 export DB_NAME="DB_NAME"

 echo "Rotating daily backups..."
 rm -rf $ACCOUNT_ROOT/backup_daily/07
 mv $ACCOUNT_ROOT/backup_daily/06 $ACCOUNT_ROOT/backup_daily/07
 mv $ACCOUNT_ROOT/backup_daily/05 $ACCOUNT_ROOT/backup_daily/06
 mv $ACCOUNT_ROOT/backup_daily/04 $ACCOUNT_ROOT/backup_daily/05
 mv $ACCOUNT_ROOT/backup_daily/03 $ACCOUNT_ROOT/backup_daily/04
 mv $ACCOUNT_ROOT/backup_daily/02 $ACCOUNT_ROOT/backup_daily/03
 mv $ACCOUNT_ROOT/backup_daily/01 $ACCOUNT_ROOT/backup_daily/02
 mkdir $ACCOUNT_ROOT/backup_daily/01
 echo "... done rotating daily backups."

 echo "Starting database backup..."
 mysqldump --host=$DB_HOST --user=$DB_USER --password=$DB_PASSWORD --all-databases | bzip2 > $ACCOUNT_ROOT/backup_daily/01/mysql-`date +%Y-%m-%d`.bz2
 echo "... daily database backup complete."

 echo "Starting file system backup..."
 tar czf $ACCOUNT_ROOT/backup_daily/01/web_backup.tgz $ACCOUNT_ROOT/web/content/
 echo "... daily file system backup complete."

 exit 0

Here is my weekly script


 # ACCOUNT_ROOT can be found on the Features tab in the control panel for the site
 export ACCOUNT_ROOT="/mnt/stor2-wc2-dfw1/427054/"

 #### PROGRAM 
 echo "Rotating backups..."
 rm -rf $ACCOUNT_ROOT/backup_weekly/08
 mv $ACCOUNT_ROOT/backup_weekly/07 $ACCOUNT_ROOT/backup_weekly/08
 mv $ACCOUNT_ROOT/backup_weekly/06 $ACCOUNT_ROOT/backup_weekly/07
 mv $ACCOUNT_ROOT/backup_weekly/05 $ACCOUNT_ROOT/backup_weekly/06
 mv $ACCOUNT_ROOT/backup_weekly/04 $ACCOUNT_ROOT/backup_weekly/05
 mv $ACCOUNT_ROOT/backup_weekly/03 $ACCOUNT_ROOT/backup_weekly/04
 mv $ACCOUNT_ROOT/backup_weekly/02 $ACCOUNT_ROOT/backup_weekly/03
 mv $ACCOUNT_ROOT/backup_weekly/01 $ACCOUNT_ROOT/backup_weekly/02
 mv $ACCOUNT_ROOT/backup_daily/07 $ACCOUNT_ROOT/backup_weekly/01
 echo "... done rotating backups."

 exit 0

Each of theses scripts are stored in a cronjobs directory inside of web/content.

I created a backup_daily and backup_weekly directory at the root for the site. This is where the scripts will store the back up files.

Then I created two cronjobs. One that runs the daily backup each day at 3am and the other that runs the weekly backup every 7 days at 2:30 am.

From Rackspace Cloud Servers to Linode VPS – A move by Sacha Chua

Sacha Chua is a lovely girl hacker who knows computer, manages her own Linux server and developes in Emacs. She used to be on Rackspace Cloud Servers but later moved to Linode because the price is cheaper there. Both are unmanaged, which means you have to be the server administrator all on your own.

Check out her article about this move and how she likes Linode:

In my opinion, Linode is indeed a fine alternative to Rackspace Cloud Server, especially to people who don’t need provision so often and who don’t need to scale.

A very full-fledged review of Rackspace Cloud

Here’s a very comprehensive review of Rackspace Cloud that deals with many different aspects of the cloud hosting provider, such as products offered, support, performance, reliability, documentation and resources, etc.. It’s a bit old but it’s still true in many ways as an introductory guide to people who are new to or want to know about Rackspace Cloud.

Check it out: