rsnapshot Backup to External USB Drive Gotcha

I am using rsnapshot to…

Login

Blog History

I am using rsnapshot to make hourly, daily and weekly snapshots of my home workstation data. This is on Fedora 16.

In /etc/rsnapshot.conf there are two commands that specify the root directory you want to create your backups in and whether or not to create it if it doesn't exist already

###########################
# SNAPSHOT ROOT DIRECTORY #
###########################

# All snapshots will be stored under this root directory.
#
snapshot_root   /mnt/3TB_USB/rsnapshot/

# If no_create_root is enabled, rsnapshot will not automatically create the
# snapshot_root directory. This is particularly useful if you are backing
# up to removable media, such as a FireWire or USB drive.
#
no_create_root  1

Problem:
The problem I am having is that if the USB drive isn't mounted rsnapshot exits without doing the backup.

I tried to work around this by adding a script to the cmd_preexec setting thinking that rsnapshot would run cmd_preexec and then check to make sure the snapshot_root existed. But apparently the check for rsnapshot_root happens and rsnapshot exits before cmd_preexec runs. So this approach doesn't work:

# Specify the path to a script (and any optional arguments) to run right
# before rsnapshot syncs files
#
cmd_preexec   /usr/local/bin/mount_backup_usb.sh

Resolution:
So the answer to my problem is to call the mount_backup_usb.sh from the crontab thusly:

# added by jamesm 5/12/2011
0 */4 * * *         /usr/local/bin/mount_backup_usb.sh && /usr/bin/rsnapshot hourly
50 23 * * *         /usr/local/bin/mount_backup_usb.sh && /usr/bin/rsnapshot daily
40 23 * * 6         /usr/local/bin/mount_backup_usb.sh && /usr/bin/rsnapshot weekly
30 23 1 * *         /usr/local/bin/mount_backup_usb.sh && /usr/bin/rsnapshot monthly

This is the script that I use to mount the external USB Drive. Note that I am using the by-uuid device entry to provide un-ambiguous access to the USB HDD volume just in case the device path (/dev/sdb, /dev/sdc) changes (which it can depending what you have plugged into the PC).

#!/bin/sh

VOLUME=/mnt/3TB_USB
BYUUID=/dev/disk/by-uuid/89406e23-02b9-4846-a9db-38c344fe851f

if mount | grep -q $VOLUME ;
then
	echo already mounted
else
	echo not mounted
        # just in case it's already mounted by the user to /media/*
	umount -f $BYUUID > /dev/null 2>&1
	mount $BYUUID $VOLUME

fi	

0 Comments

Submit a Comment

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.