From b9698550f0d56cac70f1dd2998cc55eb71c4487a Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Tue, 31 Aug 2010 14:40:39 +0200 Subject: [PATCH] implement multi-backup --- remote-backup | 101 ++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/remote-backup b/remote-backup index 74a3758..5390260 100755 --- a/remote-backup +++ b/remote-backup @@ -60,82 +60,87 @@ then fi ###END: generic tool checker -source /etc/remote-backup.conf +for config in /etc/remote-backup/*/config +do + source /etc/remote-backup/defaults.conf + source "$config" -echo "Debut de backup de ${REMOTE_LOCATION} vers ${SNAPSHOT_RW}/${DEST}/ a $(date)" + echo "Debut de backup de ${REMOTE_LOCATION} vers ${SNAPSHOT_RW}/${DEST}/ a $(date)" # ------------- the script itself -------------------------------------- # make sure we're running as root -if [ ! $UID -eq 0 ] -then - $ECHO "Sorry, must be root. Exiting..." - exit -fi - -if [[ "$REMOUNT" == "true" ]] -then - # attempt to remount the RW mount point as RW; else abort - $MOUNT -o remount,rw $MOUNT_DEVICE $SNAPSHOT_RW ; - if (( $? )) + if [ ! $UID -eq 0 ] then - $ECHO "snapshot: could not remount $SNAPSHOT_RW readwrite" + $ECHO "Sorry, must be root. Exiting..." exit fi -fi + + if [[ "$REMOUNT" == "true" ]] + then +# attempt to remount the RW mount point as RW; else abort + $MOUNT -o remount,rw $MOUNT_DEVICE $SNAPSHOT_RW ; + if (( $? )) + then + $ECHO "snapshot: could not remount $SNAPSHOT_RW readwrite" + exit + fi + fi # rotating snapshots of /home (fixme: this should be more general) # step 1: delete the oldest snapshot, if it exists: -if [ -d $SNAPSHOT_RW/$DEST/daily.${MAX_ROTATE} ] -then - $RM -rf $SNAPSHOT_RW/$DEST/daily.${MAX_ROTATE} -fi + if [ -d $SNAPSHOT_RW/$DEST/daily.${MAX_ROTATE} ] + then + $RM -rf $SNAPSHOT_RW/$DEST/daily.${MAX_ROTATE} + fi # step 2: shift the middle snapshots(s) back by one, if they exist -for backup_number in $(seq $((${MAX_ROTATE}-1)) -1 1) -do - if [ -d $SNAPSHOT_RW/$DEST/daily.${backup_number} ] - then - $MV $SNAPSHOT_RW/$DEST/daily.${backup_number} \ - $SNAPSHOT_RW/$DEST/daily.$((${backup_number}+1)) - fi -done + for backup_number in $(seq $((${MAX_ROTATE}-1)) -1 1) + do + if [ -d $SNAPSHOT_RW/$DEST/daily.${backup_number} ] + then + $MV $SNAPSHOT_RW/$DEST/daily.${backup_number} \ + $SNAPSHOT_RW/$DEST/daily.$((${backup_number}+1)) + fi + done # step 3: make a hard-link-only (except for dirs) copy of the latest snapshot, # if that exists -if [ -d $SNAPSHOT_RW/$DEST/daily.0 ] -then - $CP -al $SNAPSHOT_RW/$DEST/daily.0 $SNAPSHOT_RW/$DEST/daily.1 -fi + if [ -d $SNAPSHOT_RW/$DEST/daily.0 ] + then + $CP -al $SNAPSHOT_RW/$DEST/daily.0 $SNAPSHOT_RW/$DEST/daily.1 + fi # step 4: rsync from the system into the latest snapshot (notice that # rsync behaves like cp --remove-destination by default, so the destination # is unlinked first. If it were not so, this would copy over the other # snapshot(s) too! -$RSYNC \ - -a \ - --delete \ - --delete-excluded \ - --exclude-from="$EXCLUDES" \ - --bwlimit=$BWLIMIT \ - ${REMOTE_LOCATION} \ - $SNAPSHOT_RW/$DEST/daily.0 + $RSYNC \ + -a \ + --delete \ + --delete-excluded \ + --exclude-from="$EXCLUDES" \ + --bwlimit=$BWLIMIT \ + ${REMOTE_LOCATION} \ + $SNAPSHOT_RW/$DEST/daily.0 # step 5: update the mtime of daily.0 to reflect the snapshot time -$TOUCH $SNAPSHOT_RW/$DEST/daily.0 + $TOUCH $SNAPSHOT_RW/$DEST/daily.0 # and thats it for home. # now remount the RW snapshot mountpoint as readonly -if [[ "$REMOUNT" == "true" ]] -then - $MOUNT -o remount,ro $MOUNT_DEVICE $SNAPSHOT_RW - if (( $? )) + if [[ "$REMOUNT" == "true" ]] then - $ECHO "snapshot: could not remount $SNAPSHOT_RW readonly" - exit + $MOUNT -o remount,ro $MOUNT_DEVICE $SNAPSHOT_RW + if (( $? )) + then + $ECHO "snapshot: could not remount $SNAPSHOT_RW readonly" + exit + fi fi -fi -echo "Fin de backup de ${REMOTE_LOCATION} vers ${SNAPSHOT_RW}/${DEST}/ a $(date)" + echo "Fin de backup de ${REMOTE_LOCATION} vers ${SNAPSHOT_RW}/${DEST}/ a $(date)" + echo '-----------------------------------------------------------------------' +done