Backups using rsnapshot
Rsnapshot is a rsync-based program that will allow you to keep multiple
views of your desired directories based on whatever rules you set. In
order for it to be secure, some work must be done to wrap all of its
communication with ssh. Also, as is common with free software,
installation can be a tad bit difficult. Start by downloading the latest version (link may be broken), and installing with the following commands:
All of the work is done in the /etc/rsnapshot.conf configuration file; without the comment lines, here's how mine reads:
Next, we will want to start the first hourly backup. As every backup after this is incremental, this will take a very long time compared to future ones. Start off by opening a terminal and mounting compyg5.unl.edu's backup disk on /Volumes/compyg5:
While this is going (it'll probably take a couple of hours, especially if you have MP3's in your home directory), let's now setup ssh.
First, copy / paste the following script into a file named afptunnel, and put it in your system path (preferably /usr/bin if you are the only user, $HOME otherwise):
Make sure that you run chmod a+x afptunnel to make it executable. Also, note that you have to put your username and password for compyg5 in the file. Now, setup passwordless ssh for your computer to compyg5.unl.edu. To do this, make sure you have an ssh key (it would be found in $HOME/.ssh/id_dsa or $HOME/.ssh/id_rsa). If not, run ssh-keygen:
Finally, add the following lines to your crontab:
Note that you don't want to run two instances of afptunnel at once - they will interfere with each other. Make sure that the original backup is done - without any major errors - before having another one run. Finally, make sure that the "Backup disk" is not previously mounted when afptunnel is run.
./configure --sysconfdir=/etc --prefix=/usrIf configure doesn't work, most likely you don't have the developer's tools installed on your Mac - these can be found on the second CD of your OS X install.
su
make install
cp /etc/rsnapshot.conf.default /etc/rsnapshot.conf
All of the work is done in the /etc/rsnapshot.conf configuration file; without the comment lines, here's how mine reads:
config_version 1.2Warning: do not copy and paste from the webpage. This configuration file has strict rules, including tabs between elements, not spaces. Rather, edit the default file with the above options. Make sure you change all the instances of "brian" in the above configuration to your user name.
snapshot_root /Volumes/compyg5/brians-snapshots/
no_create_root 1
cmd_rm /bin/rm
cmd_rsync /usr/bin/rsync
cmd_logger /usr/bin/logger
interval hourly 6
interval daily 7
interval weekly 4
verbose 2
loglevel 3
backup /Users/brian/ localhost/
Next, we will want to start the first hourly backup. As every backup after this is incremental, this will take a very long time compared to future ones. Start off by opening a terminal and mounting compyg5.unl.edu's backup disk on /Volumes/compyg5:
mkdir -p /Volumes/compyg5Make sure that your laptop is plugged in the UNL network (don't backup your home directory over the Internet without encrypting!) and that you are physically on a wired connection. Trying to backup over wireless will take a long, long time. Now, first test your configuration file - if that is successful, go on and create your first hourly snapshot:
/sbin/mount_afp "afp://$USERNAME:$PASSWORD@compyg4.unl.edu/Backup disk" /Volumes/compyg5
ls /Volumes/compyg5/ #Make sure that the directory isn't empty (if it is, the mount may not have worked)
mkdir /Volumes/compyg5/$USERNAMEs-snapshots
rsnapshot configtestYou may have to check out rsnapshot.org's documentation if the first command fails. Note that rsnapshot will complain that it cannot chgrp on one of the directories it makes; this is ok to ignore. It may also fail on some of Firefox's cache files, but those aren't important either.
rsnapshot hourly
While this is going (it'll probably take a couple of hours, especially if you have MP3's in your home directory), let's now setup ssh.
First, copy / paste the following script into a file named afptunnel, and put it in your system path (preferably /usr/bin if you are the only user, $HOME otherwise):
#!/bin/sh
# script to make ssh tunnel and then connect to afp host
#
# Jan 02 2004 - W Penn - creation
# Aug 07 2005 - B Bockelman - customized for rsnapshot
#
LOCAL_PORT=10548;
LOCAL_HOST=127.0.0.1;
TARGET_PORT=548;
TARGET_HOST=compyg5.unl.edu;
USERNAME=
PASSWORD=
ssh -L $LOCAL_PORT:$TARGET_HOST:$TARGET_PORT -f -N $LOCAL_HOST;
TUN=`lsof -i:$LOCAL_PORT -Fp | head -1| sed s/p//`
mkdir -p /Volumes/compyg5
/sbin/mount_afp "afp://$USERNAME:$PASSWORD@127.0.0.1:$LOCAL_PORT/Backup disk" /Volumes/compyg5
rsnapshot $1
/sbin/umount /Volumes/compyg5
kill $TUN
Make sure that you run chmod a+x afptunnel to make it executable. Also, note that you have to put your username and password for compyg5 in the file. Now, setup passwordless ssh for your computer to compyg5.unl.edu. To do this, make sure you have an ssh key (it would be found in $HOME/.ssh/id_dsa or $HOME/.ssh/id_rsa). If not, run ssh-keygen:
ssh-keygen -t dsaUse all the default answers to the questions, and do not set a password - just hit enter when you are asked. Now, run cat ~/.ssh/id_dsa.pub to display your public key. Copy the returned contents, and append it to ~/.ssh/authorized_keys on compyg5.unl.edu. You should now be able to ssh to compyg5, and it will not ask you for a password.
Finally, add the following lines to your crontab:
0 */4 * * * brian /usr/bin/afptunnel hourlyAgain, adjust accordingly for your username. This will run the daily and weekly updates at night (if the laptop is on), and the hourly updates once every four hours. It will not run if <em>compyg5.unl.edu</em> fails to mount.
30 23 * * * brian /usr/bin/afptunnel daily
0 23 * * 1 brian /usr/bin/afptunnel weekly
Note that you don't want to run two instances of afptunnel at once - they will interfere with each other. Make sure that the original backup is done - without any major errors - before having another one run. Finally, make sure that the "Backup disk" is not previously mounted when afptunnel is run.