NSLU2-Linux
view · edit · print · history

When you upgraded the firmware to unslung, you will notice that the Drive Backup option doesn't work anymore. Unslung firmware uses symbolic links which the backup program made by LinkSys can't handle.

Now let's see how the backup worked before, and see how to fix it.

First, when using the button Start Backup Now under the Drive Backup, then the script /usr/sbin/drivertodrivercp is run. At the near end, after doing loads of checks to see if nothing else is messing up your disk, the binary drive_backup is run. You will notice that the backup is done instantaneously, according to the logging. Trying drivertodrivercp by hand (command line) shows a Segmentation Fault error when running the drive_backup binary.

When you set a time to do the backup an entry is made in the crontab (/etc/crontab):

0 4 * * * root /usr/sbin/drivertodrivercp &>/dev/null

(Aside: this looks like a syntax error on Linksys' part. This is a Bourne shell - sh - script but the syntax looks like csh script. Line 28 and 35 of original drivertodrivercp gets syntax error - add continue before else)

In order to get the backup working again, you can install the rsync package using ipkg (ipkg install rsync), which put the rsync binary in /opt/bin. A rsync daemon is automatically installed and started after reboot by the /opt/etc/init.d/S##rsync.rc script. For only local copies (from disk 1 to 2) this isn't needed and uses up valuable resources (memory!), so this script can be removed.

Make a directory for backups logs: mkdir /share/hdd/log

Now change the drivertodrivercp script in the last bit (picking up from the touch /tmp/DriveBackupping line):

 
touch /tmp/DriveBackuping

LOGDIR=/share/hdd/log
# Keep seven days of backup logs named after days of the week

LOGBASE=${LOGDIR}/rsync.`date +%A`

#To make logging verbose, turn the "-q" into "-v"
RSYNC="/opt/bin/rsync -a -H -q --delete"

# Backup the conf directory, log to a specific file
DIR=conf
LOG=${LOGBASE}.${DIR}
#
# Syntax matters. Do not put ampersands (&) on the rsync command) 
# It already runs in a crontab
# The separation of logging also separates error messages into a separate file.
# To keep it in the same file, use "2>${LOG}"

${RSYNC} /share/hdd/${DIR}/ /share/flash/${DIR} 1>${LOG} 2>${LOG}.err
# If conf backup succeeds, backup the data dir
if [ $? = 0 ]; then
  DIR=data
  LOG=${LOGBASE}.${DIR}
  ${RSYNC} /share/hdd/${DIR}/ /share/flash/${DIR} 1>${LOG} 2>${LOG}.err
fi


if [ $? = 0 ]; then
        /usr/sbin/set_log backup 0 4
else
        /usr/sbin/set_log backup 0 13
fi

rm -f /tmp/DriveBackuping

/usr/sbin/CheckDiskFull

A few notes on these lines: 1) Note the end slash of the /share/hdd/data/ part, that's important. 2) Note that there is no such slash behind the /share/flash/data part, that's correct. Don't forget the &>/dev/null at the end of the command. If you forget that, the command won't run as a cronjob, although it runs by executing it by hand.

Now the backup should be working fine again using the standard webinterface.

Removing the ampersand (&) from a previous version of these directions on the rsync line will insure the backup process - and subsequent msgs - wait for the the rsync to complete.

The --no-detach option was in the original version of this script and is not required: it is only valid when running as a daemon process and was ignored in non-daemon mode before version 2.6.7-1 gives an error from 2.6.7-1 and later.

The -l option (create symbolic links) was in the original version of this script and is not required: it is implied by the '-a' option

The -H option was missing from the was in the original version of this script; if you use hard links (e.g. backuppc or rsnapshot) then the files get duplicated instead of a hard link used. This slows down the script slightly, but if you're using hardlink you're going to use it (or the destination disk will not be large enough)

Fix the minor logging bug by a Diversion script

When you start using rsync you may lose having useful logging information. This is caused by the Linksys Webinterface, which adds &>/dev/null to every job added to the crontab. This can be fixed easy by adding the LOG information to the drivertodrivercp program, as shown above.

Another approach is a diversion script, which removes &>/dev/null from drivertodrivercp entries which are in the crontabfile. Below is an example of such a diversion script, create the file using one of the Unix style text editors and save as /unslung/rc.crond :-

 
#! /bin/sh
# Diversion script: customize before starting crond
#
# /unslung/rc.crond
#
# Reason: fix the log when using rsync for jobs added from linksys webgui
#
if [ ! -e /etc/crontab.orig ]; then cp -p /etc/crontab /etc/crontab.orig; fi
sed -i -e 's_/usr/sbin/drivertodrivercp   &>/dev/null_/usr/sbin/drivertodrivercp_' /etc/crontab

#
# Continue to start crond

return 1
# EOF - include this line

When using this method, you must edit your drivertodrivercp script and remove the &>/dev/null entries. It then reads (picking up from the touch /tmp/DriveBackupping line):

 
touch /tmp/DriveBackuping
/opt/bin/rsync -a -H -q --delete /share/hdd/conf/ /share/flash/conf
if [ $? = 0 ]; then
        /opt/bin/rsync -a -H -q --delete /share/hdd/data/ /share/flash/data
fi

if [ $? = 0 ]; then
        /usr/sbin/set_log backup 0 4
else
        /usr/sbin/set_log backup 0 13
fi

rm -f /tmp/DriveBackuping

/usr/sbin/CheckDiskFull

When using this method, logging will be fully functional again!

It Works

Before the drive copy command works, the periodic automatic drive copy settings (just above the command button) has to be set first, with any time value such as every Saturday at 2am, and then SAVE button pushed. After the copy is finished, this setting can be disabled.

Chacko

Unslung to Disk2?

Change the script to:

 
touch /tmp/DriveBackuping
/opt/bin/rsync -a -H -q --delete /share/flash/conf/ /share/hdd/conf 
if [ $? = 0 ]; then
        /opt/bin/rsync -a -H -q --delete /share/flash/data/ /share/hdd/data  
fi

if [ $? = 0 ]; then
        /usr/sbin/set_log backup 0 4
else
        /usr/sbin/set_log backup 0 13
fi

rm -f /tmp/DriveBackuping

/usr/sbin/CheckDiskFull

RjL

How to further automate this?

A question: Does anybody know how to do with a script (Without using the admin web page) what the above SAVE settings does? With that, one can simply have a command to (a) set the save settings, (b) copy drive1 to drive2 with /usr/sbin/drivertodrivercp, and then (c) reset the SAVE settings back so it wont automatically do copy later.

Another question: Is it possible to plug in the second hard disk drive into port DISK2? when unSlung is already up and running, and then mount this drive? Currently I see the second drive only if unSlung is booted up with the second drive (as well as, of course the unSlung drive in DISK1?).

Also what is the procedure for powering down DISK2?, before it can be unplugged, while unSlung is still running?

Chacko


A Fully-Working Version for V2.3R63-uNSLUng-6.10-beta

Here is the working script I use for DISK 1 to DISK 2, it's been working for about a week now. I followed the directions such as making the log directory (mkdir /share/hdd/log), adding the continue to fix Bourne Shell errors, installed rsync, and removed rsync script: ~D. Yamaki

 
 #!/bin/sh

 if [ -f /tmp/Scanning ]; then
 	/usr/sbin/set_log backup 1 1
 	exit 1
 fi

 if [ -f /tmp/Upgrading ]; then
 	/usr/sbin/set_log backup 1 2
 	exit 1
 fi

 if [ -f /tmp/Preparing ]; then
 	/usr/sbin/set_log backup 1 3
 	exit 1
 fi

 if [ -f /tmp/Moving ]; then
 	/usr/sbin/set_log backup 1 9 
 	exit 1
 fi

 if [ -f /tmp/DriveBackuping ]; then
 	exit 1
 fi

 if [ -e /share/hdd/conf/.dongle ];then
 	continue
 else
 	/usr/sbin/set_log backup 0 1
 	exit 1
 fi


 if [ -e /share/flash/conf/.dongle ];then
 	continue
 else
 	/usr/sbin/set_log backup 0 1
 	exit 1
 fi

 F_HD1=`/bin/cat /share/hdd/conf/.dongle`
 F_HD2=`/bin/cat /share/flash/conf/.dongle`
 if [ "$F_HD1" != "$F_HD2" ]; then
 /usr/sbin/set_log backup 0 12
 exit 1
 fi

 /usr/sbin/CheckBackup
 if [ $? = 1 ]; then
 	/usr/sbin/set_log backup 0 14
 	exit 1
 elif [ $? = 2 ];then
         /usr/sbin/set_log backup 0 15
         exit 1
 elif [ $? = 3 ];then
         /usr/sbin/set_log backup 0 12
         exit 1
 fi

 /usr/sbin/set_log backup 0 3
 touch /tmp/DriveBackuping

 # CUSTOMIZATIONS HERE

 LOGDIR=/share/hdd/log
 # Keep seven days of backup logs named after days of the week

 LOGBASE=${LOGDIR}/rsync.`date +%A`

 #To make logging verbose, turn the "-q" into "-v"
 RSYNC="/opt/bin/rsync -a -H -q --delete"

 # Backup the conf directory, log to a specific file
 DIR=conf
 LOG=${LOGBASE}.${DIR}
 #
 # Syntax matters. Do not put ampersands (&) on the rsync command) 
 # It already runs in a crontab
 # The separation of logging also separates error messages into a separate file.
 # To keep it in the same file, use "2>${LOG}"

 ${RSYNC} /share/hdd/${DIR}/ /share/flash/${DIR} 1>${LOG} 2>${LOG}.err
 # If conf backup succeeds, backup the data dir
 if [ $? = 0 ]; then
   DIR=data
   LOG=${LOGBASE}.${DIR}
   ${RSYNC} /share/hdd/${DIR}/ /share/flash/${DIR} 1>${LOG} 2>${LOG}.err
 fi


 if [ $? = 0 ]; then
         /usr/sbin/set_log backup 0 4
 else
         /usr/sbin/set_log backup 0 13
 fi

 rm -f /tmp/DriveBackuping

 /usr/sbin/CheckDiskFull

 

A Fully-Working Version for Unslung 6.8

Building on the preceding work, here's the script I've been using to do a drive-1-to-drive-2 copy with Unslung 6.8. Due to the way the Linksys R63 firmware handles the conf partitions, neither the above scripts, nor even the Linksys utility on the native firmware actually copy the conf partition data to the second drive! This script fixes that. Note that as written, this script uses the /opt/bin/nice utility to reduce the priority of the rsync doing the copy, in hopes that this will keep the unit somewhat responsive should the copy occur while something else is going on. If you don't have /opt/bin/nice installed, either install it (search using the Package Search Engine; used to be in coreutils), or edit the script to remove the string "/opt/bin/nice" whereever it appears. ~mwester

 
#!/bin/sh

if [ -f /tmp/Scanning ]; then
        /usr/sbin/set_log backup 1 1
        exit 1
fi

if [ -f /tmp/Upgrading ]; then
        /usr/sbin/set_log backup 1 2
        exit 1
fi

if [ -f /tmp/Preparing ]; then
        /usr/sbin/set_log backup 1 3
        exit 1
fi

if [ -f /tmp/Moving ]; then
        /usr/sbin/set_log backup 1 9
        exit 1
fi

if [ -f /tmp/DriveBackuping ]; then
        exit 1
fi

if [ -e /share/hdd/conf/.dongle ];then
else
        /usr/sbin/set_log backup 0 1
        exit 1
fi


if [ -e /share/flash/conf/.dongle ];then
else
        /usr/sbin/set_log backup 0 1
        exit 1
fi

F_HD1=`/bin/cat /share/hdd/conf/.dongle`
F_HD2=`/bin/cat /share/flash/conf/.dongle`
if [ "$F_HD1" != "$F_HD2" ]; then
/usr/sbin/set_log backup 0 12
exit 1
fi

/usr/sbin/CheckBackup
if [ $? = 1 ]; then
        /usr/sbin/set_log backup 0 14
        exit 1
elif [ $? = 2 ];then
        /usr/sbin/set_log backup 0 15
        exit 1
elif [ $? = 3 ];then
        /usr/sbin/set_log backup 0 12
        exit 1
fi

/usr/sbin/set_log backup 0 3
touch /tmp/DriveBackuping

# Rotate the logs
if [ -f /var/log/d2d.2.log ]; then rm /var/log/d2d.2.log; fi
if [ -f /var/log/d2d.1.log ]; then mv /var/log/d2d.1.log /var/log/d2d.2.log; fi
if [ -f /var/log/d2d.0.log ]; then mv /var/log/d2d.0.log /var/log/d2d.1.log; fi

date                                                   >/var/log/d2d.0.log
echo "------------------------------ Backup of conf:" >>/var/log/d2d.0.log
echo "Creating mount directory."                      >>/var/log/d2d.0.log
mkdir -p /mnt/tmpmnt_conf                             >>/var/log/d2d.0.log 2>&1
echo "Mounting /dev/sda1."                            >>/var/log/d2d.0.log
mount /dev/sda2 /mnt/tmpmnt_conf                      >>/var/log/d2d.0.log 2>&1
echo "Performing rsync."                              >>/var/log/d2d.0.log
/opt/bin/nice /opt/bin/rsync -a -l --delete --stats /share/hdd/conf/ /mnt/tmpmnt_conf >>/var/log/d2d.0.log 2>&1
ECODE=$?
echo "Un-mounting /dev/sda1."                         >>/var/log/d2d.0.log
umount /mnt/tmpmnt_conf                               >>/var/log/d2d.0.log 2>&1
if [ $ECODE = 0 ]; then
  echo "------------------------------ Backup of data:" >>/var/log/d2d.0.log
  echo "Performing rsync."                              >>/var/log/d2d.0.log
  /opt/bin/nice /opt/bin/rsync -a -l --delete --stats /share/hdd/data/ /share/flash/data >>/var/log/d2d.0.log 2>&1
  ECODE=$?
fi

if [ $ECODE = 0 ]; then
        /usr/sbin/set_log backup 0 4
else
        /usr/sbin/set_log backup 0 13
fi
date                                                  >>/var/log/d2d.0.log

rm -f /tmp/DriveBackuping
/usr/sbin/CheckDiskFull

Page last modified on March 25, 2008, at 02:06 AM