Backing up sites on Dreamhost

I recently FUBAR’d a Concrete5 site during an upgrade process, and realized that the last time I nuke’n’paved my home computer, I also wiped all of my backups, and the backup script.

Oops.

So I recently put together the following shell script, living in my user directory on Dreamhost, to backup each site as a cronjob. I’m keeping 7 days on there for now, and will set up my home computer to download (and keep) even older archives.

This is a first-pass script; eventually, I may make it more flexible so that it can run from a list of sites & databases. Right now, you need to create a new copy of the script (and a new cronjob) for each site.

UPDATE 2014-04-02: I have moved from Dreamhost to DigitalOcean (private VPS) and the script is now substantially rewritten. I have yet to publish the revised version, but it is much more modular and flexible now.


_now=$(date +"%Y_%m_%d")
_site="[yourwebsite.com]"
_homePath="/home/[dreamhost ftp username]"
_backupPath=$_homePath"/backups"
_tarFile="$_backupPath/$_site-$_now.tar.gz"
_sqlFile="$_backupPath/$_site-$_now.sql"
_sqlHost="[SQL host]"
_sqlDb="[SQL Database]"
_sqlUser="[SQL Username]"
_sqlPass="[SQL Password]"
#
echo "Deleting old backups"
find $_backupPath/$_site* -mtime +8 -exec rm {} ;
echo "Backing up $_tarFile"
tar -zcf $_tarFile $_homePath/$_site
echo ""
echo "Backing up $_sqlFile"
mysqldump -c -h $_sqlHost --user=$_sqlUser --password=$_sqlPass $_sqlDb > $_sqlFile
echo ""
echo "Listing Backup Directory..."
ls -alht $_backupPath

Sources:

Related posts

2 thoughts on “Backing up sites on Dreamhost

  1. One approach to multi-folder & multi-database backup: http://www.dockstreetmedia.com/2011/03/alternative-cron-job-backups-in-dreamhost/

    Also, look into ADisk for FTP/SCP/RSYNC transfer off of Dreamhost servers

  2. Another nice function to add in the log: summarizing the sizes of the backup directories.

    http://www.codecoffee.com/tipsforlinux/articles/22.html

Leave a Reply