################################################## ############################
# make sure we're running as root
#
if (( `$ID -u` != 0 )); then
$ECHO Error: must be root. Exiting... ;
exit;
fi
################################################## ############################
# check the arguments and the options
#
if [ ! -b $MOUNT_DEVICE ] ; then
$ECHO Error: $MOUNT_DEVICE ins\'t a valid device. Exiting ;
exit ;
fi
if [ ! -d $MOUNT_POINT_RW ] ; then
if [ -e $MOUNT_POINT_RW ] ; then
$ECHO Error: $MOUNT_POINT_RW isn\'t a directory. Exiting ;
exit ;
fi
$ECHO Notice: $MOUNT_POINT_RW don\'t exist. Creating... ;
mkdir -p -m 755 $MOUNT_POINT_RW ;
fi
################################################## ############################
# attempt to remount the RW mount point as RW; else abort
#
$MOUNT -o remount,rw $MOUNT_DEVICE $MOUNT_POINT_RW ;
if (( $? )); then
$ECHO Error: could not remount $MOUNT_POINT_RW readwrite ;
exit ;
fi
################################################## ############################
# continue check the arguments and the options
#
if [ ! -d $SOURCE_DIR ] ; then
$ECHO $SOURCE_DIR isn\'t a valid directory. Exiting... ;
exit ;
fi
################################################## ############################
# setting optionals settings
#
if [ -z $BACKUP_NAME ] ; then
BACKUP_NAME=BACKUP;
fi
if [ ! -z $($ECHO $BACKUP_NAME | $GREP "\/" ) ] ; then
$ECHO Error: bacup_name: $BACKUP_NAME can\'t be a subdirectory ;
exit;
fi
if [ ! -d $MOUNT_POINT_RW/$DESTINATION_DIR/ ] ; then
if [ -e $MOUNT_POINT_RW/$DESTINATION_DIR/ ] ; then
ECHO Error: $MOUNT_POINT_RW/$DESTINATION_DIR/ isn\'t a directory. Exiting ;
exit ;
fi
$ECHO Notice: $MOUNT_POINT_RW/$DESTINATION_DIR/ don\'t exist. Creating... ;
mkdir -p -m 755 $MOUNT_POINT_RW/$DESTINATION_DIR/ ;
fi
################################################## ############################
# setting optionals settings
#
if [ -z "$BACKUP_NUMBER" ] ; then
BACKUP_NUMBER=5;
fi
################################################## ############################
# rotating snapshots
# delete the oldest snapshot in background, if it exists:
#
if [ -d $MOUNT_POINT_RW/$DESTINATION_DIR/$BACKUP_NAME.$BACKUP_NUMBER ] ; then
$MV $MOUNT_POINT_RW/$DESTINATION_DIR/$BACKUP_NAME.$BACKUP_NUMBER \
$MOUNT_POINT_RW/$DESTINATION_DIR/$BACKUP_NAME.$BACKUP_NUMBER.delete
$RM -rf $MOUNT_POINT_RW/$DESTINATION_DIR/$BACKUP_NAME.$BACKUP_NUMBER.delete &
fi
################################################## ############################
# shift the middle snapshots(s) back by one, if they exist
#
for i in `$SEQ $BACKUP_NUMBER 2`; do
iminus=$(($i-1)) ;
if [ -d $MOUNT_POINT_RW/$DESTINATION_DIR/$BACKUP_NAME.$iminus ] ; then
$MV $MOUNT_POINT_RW/$DESTINATION_DIR/$BACKUP_NAME.$iminus \
$MOUNT_POINT_RW/$DESTINATION_DIR/$BACKUP_NAME.$i ;
fi
done
################################################## ############################
# make a hard-link-only (except for dirs) copy of the latest snapshot,
# if that exists
#
if [ -d $MOUNT_POINT_RW/$DESTINATION_DIR/$BACKUP_NAME.0 ] ; then
$CP -al $MOUNT_POINT_RW/$DESTINATION_DIR/$BACKUP_NAME.0 \
$MOUNT_POINT_RW/$DESTINATION_DIR/$BACKUP_NAME.1 ;
fi
################################################## ############################
# $EXCLUDE_FILE is an optional
#
if [ ! -z $EXCLUDE_FILE ] ; then
if [ -f $EXCLUDE_FILE ] ; then
EXCLUDE_LINE="--exclude-from=\"$EXCLUDE_FILE\"" ;
else
$ECHO Error: $EXCLUDE_FILE isn\'t a valid file. Exiting. ;
exit;
fi
fi
################################################## ############################
# 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 \
-va --delete --delete-excluded \
$EXCLUDE_LINE \
$SOURCE_DIR/ $MOUNT_POINT_RW/$DESTINATION_DIR/$BACKUP_NAME.0 ;
################################################## ############################
# update the mtime of $BACKUP_NAME.0 to reflect the snapshot time
#
$TOUCH $MOUNT_POINT_RW/$DESTINATION_DIR/$BACKUP_NAME.0 ;
################################################## ############################
# wait for rm in background finish
#
wait ;
################################################## ############################
# remount the RW snapshot mountpoint as readonly
#
$MOUNT -o remount,ro $MOUNT_DEVICE $MOUNT_POINT_RW ;
if (( $? )); then
$ECHO Error: could not remount $MOUNT_POINT_RW readonly ;
exit ;
fi
#
# EOF
################################################## ############################
Hofe hat weiter geholfen
