NSLU2 – Backup files

Now that I’ve managed to copy all my important files onto the USB disk plugged into DISK1 of my NSLU2, I wanted to make sure I kept a backup of everything, and decided a good strategy would be to mirror files to the hard disk plugged into DISK2 (via my USB hub) of the NSLU2.

After looking at the linksys web tool and realising the backup stuff doesn’t work properly, I went looking for a smart way to do this, and settled on RSYNC, which can be installed via IPKG.

I use RSYNC to copy changes to a directory from one disk to another, and then have this scheduled to run once a week.  I created a number of scripts to backup certain directories, and then schedule these to run on different nights of the week.

The script looks like the following:

#!/bin/sh
before="$(date +%s)"
fromdir="/home/user/"
todir="/share/flash/data/backup/user/"
logfile="/var/log/backup_users.log"
Set_Led beep2
date >$logfile
echo "----------------------------" >>$logfile
/opt/bin/rsync -avrlHpEog $fromdir $todir >>$logfile
echo "----------------------------" >>$logfile
after="$(date +%s)"
elapsed_seconds="$(expr $after - $before)"
date >>$logfile
echo Elapsed time: $elapsed_seconds secs >>$logfile
Set_Led beep1

 

And then I change the fromdir/todir and logfile depending on what I’m backing up.  I’ve also put some time recording into the log file, and some beep commands so you know when its starting and finishing should you be using the NSLU2 at the time.
The only thing left is to schedule this through CRON.  I created a symbollic link into /etc/cron.daily then added the entries.  The run-parts command for cron doesn’t work on the default version with the NSLU2, hence why you have to add each entry.

My 3 cron entries I have for backups are as follows:

01 0 * * 0  /etc/cron.daily/backupUserDirs.sh
01 0 * * 1  /etc/cron.daily/backupRestorePC.sh
01 0 * * 2  /etc/cron.daily/backupMultimedia.sh

My only criticism – because the NSLU2 is pretty slow, RSYNC can take a while – but then I don’t care as it scheduled to run when I’m not doing anything on my NSLU2.  The other tip – copy the files yourself before running a sync – if you make RSYNC do all the work, it could take a while!

Leave a Reply

Your email address will not be published. Required fields are marked *