/kb

personal knowledgebase

Archive for September, 2008

Backing up my Macbook with rsync, SSH and Cron

without comments

I’ve created a simple script which syncs my documents folder with a remote computer. The files are transferred across the SSH protocol and the backup is performed daily with assistance of cron.

My rsync script is very simple:

#!/bin/bash
rsync -avzr --delete-excluded --exclude="*.log" --exclude="*.aux" --exclude=".svn" --exclude=".classpath" --exclude=".cache" --exclude=".project" --exclude="*.class" --exclude="*.swp" --exclude=".DS_Store" --exclude=".metadata" -e "ssh -c blowfish" /Users/USERNAME/Documents USER@REMOTE_COMPUTER:REMOTE_DIRECTORY

It was quite tricky to set up the cron job until i realized that cron does know very little of the user’s system. The trick was to add SSH_AUTH_SOCK=/tmp/501/SSHKeychain.socket in front of the script refrence in crontab, so that it looks like:

55 21 * * * SSH_AUTH_SOCK=/tmp/501/SSHKeychain.socket /Users/USERNAME/etc/backup.sh

This will cause the backup script to run at 21:55 each night. For more info on cron, check out unixgeeks.org. Add the following at the end if you’d like to suppress the mail from cron: >& /dev/null.

Note that for this script to run, SSH has to be set up with keypairs authentication.

Written by hgrimelid

September 13th, 2008 at 11:29 pm

Posted in Scripts,Server

Tagged with , , ,