implement multi-backup
This commit is contained in:
parent
67cc3b7b96
commit
b9698550f0
101
remote-backup
101
remote-backup
@ -60,82 +60,87 @@ then
|
|||||||
fi
|
fi
|
||||||
###END: generic tool checker
|
###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 --------------------------------------
|
# ------------- the script itself --------------------------------------
|
||||||
|
|
||||||
# make sure we're running as root
|
# make sure we're running as root
|
||||||
if [ ! $UID -eq 0 ]
|
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 (( $? ))
|
|
||||||
then
|
then
|
||||||
$ECHO "snapshot: could not remount $SNAPSHOT_RW readwrite"
|
$ECHO "Sorry, must be root. Exiting..."
|
||||||
exit
|
exit
|
||||||
fi
|
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)
|
# rotating snapshots of /home (fixme: this should be more general)
|
||||||
|
|
||||||
# step 1: delete the oldest snapshot, if it exists:
|
# step 1: delete the oldest snapshot, if it exists:
|
||||||
if [ -d $SNAPSHOT_RW/$DEST/daily.${MAX_ROTATE} ]
|
if [ -d $SNAPSHOT_RW/$DEST/daily.${MAX_ROTATE} ]
|
||||||
then
|
then
|
||||||
$RM -rf $SNAPSHOT_RW/$DEST/daily.${MAX_ROTATE}
|
$RM -rf $SNAPSHOT_RW/$DEST/daily.${MAX_ROTATE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# step 2: shift the middle snapshots(s) back by one, if they exist
|
# step 2: shift the middle snapshots(s) back by one, if they exist
|
||||||
for backup_number in $(seq $((${MAX_ROTATE}-1)) -1 1)
|
for backup_number in $(seq $((${MAX_ROTATE}-1)) -1 1)
|
||||||
do
|
do
|
||||||
if [ -d $SNAPSHOT_RW/$DEST/daily.${backup_number} ]
|
if [ -d $SNAPSHOT_RW/$DEST/daily.${backup_number} ]
|
||||||
then
|
then
|
||||||
$MV $SNAPSHOT_RW/$DEST/daily.${backup_number} \
|
$MV $SNAPSHOT_RW/$DEST/daily.${backup_number} \
|
||||||
$SNAPSHOT_RW/$DEST/daily.$((${backup_number}+1))
|
$SNAPSHOT_RW/$DEST/daily.$((${backup_number}+1))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# step 3: make a hard-link-only (except for dirs) copy of the latest snapshot,
|
# step 3: make a hard-link-only (except for dirs) copy of the latest snapshot,
|
||||||
# if that exists
|
# if that exists
|
||||||
if [ -d $SNAPSHOT_RW/$DEST/daily.0 ]
|
if [ -d $SNAPSHOT_RW/$DEST/daily.0 ]
|
||||||
then
|
then
|
||||||
$CP -al $SNAPSHOT_RW/$DEST/daily.0 $SNAPSHOT_RW/$DEST/daily.1
|
$CP -al $SNAPSHOT_RW/$DEST/daily.0 $SNAPSHOT_RW/$DEST/daily.1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# step 4: rsync from the system into the latest snapshot (notice that
|
# step 4: rsync from the system into the latest snapshot (notice that
|
||||||
# rsync behaves like cp --remove-destination by default, so the destination
|
# 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
|
# is unlinked first. If it were not so, this would copy over the other
|
||||||
# snapshot(s) too!
|
# snapshot(s) too!
|
||||||
$RSYNC \
|
$RSYNC \
|
||||||
-a \
|
-a \
|
||||||
--delete \
|
--delete \
|
||||||
--delete-excluded \
|
--delete-excluded \
|
||||||
--exclude-from="$EXCLUDES" \
|
--exclude-from="$EXCLUDES" \
|
||||||
--bwlimit=$BWLIMIT \
|
--bwlimit=$BWLIMIT \
|
||||||
${REMOTE_LOCATION} \
|
${REMOTE_LOCATION} \
|
||||||
$SNAPSHOT_RW/$DEST/daily.0
|
$SNAPSHOT_RW/$DEST/daily.0
|
||||||
|
|
||||||
# step 5: update the mtime of daily.0 to reflect the snapshot time
|
# 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.
|
# and thats it for home.
|
||||||
|
|
||||||
# now remount the RW snapshot mountpoint as readonly
|
# now remount the RW snapshot mountpoint as readonly
|
||||||
if [[ "$REMOUNT" == "true" ]]
|
if [[ "$REMOUNT" == "true" ]]
|
||||||
then
|
|
||||||
$MOUNT -o remount,ro $MOUNT_DEVICE $SNAPSHOT_RW
|
|
||||||
if (( $? ))
|
|
||||||
then
|
then
|
||||||
$ECHO "snapshot: could not remount $SNAPSHOT_RW readonly"
|
$MOUNT -o remount,ro $MOUNT_DEVICE $SNAPSHOT_RW
|
||||||
exit
|
if (( $? ))
|
||||||
|
then
|
||||||
|
$ECHO "snapshot: could not remount $SNAPSHOT_RW readonly"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user