A few months ago Dreamhost disabled automatic snapshotting for their shared hosting users. There's a restore function in the domain listing in the control panel but it's rarely working.
So I set about restoring the old functionality. What follows is the result of this work, hopefully it may be of some help to others.
mysnapshots.sh
Copy this to a file mysnapshots.sh and set the executable bit (chmod +x mysnapshots.sh).
#!/bin/bash
### usage: ./mysnapshots.sh
### name_of_snapshot can be anything ("manual", "hourly", "nightly", "weekly", "monthly", etc.) IT MUST BE SPECIFIED!
### CONFIGURATION ###
### replace YOUR_USER_NAME with your user name (whoami)
home=/home/YOUR_USER_NAME
### snapshots directory
snapshots=/.mysnapshots
### replace DIR1 DIR2 DIR3 with the names of the directories you wish to backup
### DO NOT INCLUDE THE SNAPSHOTS DIRECTORY ($snapshots)!!!
dirs="DIR1 DIR2 DIR3"
### CONFIGURATION ###
### lower the load of this process (and of its children)
renice 19 -p $$ &>/dev/null
### chdir to home (so that rsync is executed from there)
cd $home
### ensure that the snapshots directory exists
mkdir $snapshots &>/dev/null
### remove the oldest snapshot and rotate the others
bset=$snapshots/$1
rm -r $bset.3 &>/dev/null
mv $bset.2 $bset.3 &>/dev/null
mv $bset.1 $bset.2 &>/dev/null
mv $bset.0 $bset.1 &>/dev/null
### create the new snapshot (warning! files unchanged from the previous snapshot
### are hardlinked to the ones in the previous snapshot!)
mkdir $bset.0 &>/dev/null
rsync -a --delete --link-dest=$bset.1 $dirs $bset.0/ &>/dev/null
exit 0
Usage
The script accepts a single compulsory parameter: the name of the snapshot. For each snapshot name, only the last 4 snapshots will be kept (e.g. if the name is "hourly" we will have hourly.0, hourly.1, hourly.2, hourly.3).
The best way to invoke it is obviously from a cronjob. Add the following lines to your cronjob (crontab -e on Dreamhost):
# snapshots
@hourly /home/YOUR_USER_NAME/mysnapshots.sh hourly &>/dev/null
@midnight /home/YOUR_USER_NAME/mysnapshots.sh nightly &>/dev/null
@weekly /home/YOUR_USER_NAME/mysnapshots.sh weekly &>/dev/null
@monthly /home/YOUR_USER_NAME/mysnapshots.sh monthly &>/dev/null
In this way you'll end up with the following directory structure:
/
home
YOUR_USER_NAME
.mysnapshots
hourly.0 (one hour ago)
DIR1
DIR2
DIR3
hourly.1
DIR1
DIR2
DIR3
hourly.2
DIR1
DIR2
DIR3
hourly.3 (four hours ago)
DIR1
DIR2
DIR3
nightly.0 (one day ago)
DIR1
DIR2
DIR3
nightly.1
DIR1
DIR2
DIR3
nightly.2
DIR1
DIR2
DIR3
nightly.3 (four days ago)
DIR1
DIR2
DIR3
weekly.0 (one week ago)
DIR1
DIR2
DIR3
weekly.1
DIR1
DIR2
DIR3
weekly.2
DIR1
DIR2
DIR3
weekly.3 (four weeks ago)
DIR1
DIR2
DIR3
monthly.0 (one month ago)
DIR1
DIR2
DIR3
monthly.1
DIR1
DIR2
DIR3
monthly.2
DIR1
DIR2
DIR3
monthly.3 (four months ago)
DIR1
DIR2
DIR3