Can anyone help me please by looking at my snapshot backup script. It should be taking a daily snapshot of my core libraries and backing them up with
an RSYNC --link-dest. It should keep 5 days worth of backups.
What I find is that if I call the job from CRON it runs OK and I get my backup libraries correctly created but at some point if I leave the process to run it
starts deleting the backup libraries and then just runs through without doing anything i.e. 0 minutes to complete.
Excuse the primitive code but if anyone can tell me what is wrong with it I would be very grateful. Any tips on tidying up the code and adding in "traps"
or console messages for better debugging would also be gratefully received !
:START
#!/bin/bash -xv
# DAILY SNAPSHOT BACKUP
# run from Monday to Friday
SOURCE=/mnt/NASHD/users/
TARGET=/mnt/NASHD/.snap
LOGS=/mnt/NASHD/users/support/tools/LOGS
LOGFILE=rsync.DAILY
STARTMSG="Starting SNAPSHOT DAILY:"
ENDMSG="Completed SNAPSHOT DAILY"
NEWLINE="\n"
# RUNTIME=$(date +%d-%b-%Y)
RUNTIME=$(date)
# Cull previous log. We don't want these to get too big !
rm -v $LOGS/$LOGFILE
# Tell syslog and write to log file, snapshot is starting
logger $STARTMSG $RUNTIME
echo -e $STARTMSG $RUNTIME $NEWLINE > $LOGS/$LOGFILE
echo SOURCE rsync directory is: $SOURCE >> $LOGS/$LOGFILE
logger "SOURCE rsync directory is: $SOURCE"
echo -e TARGET rsync directory is: $TARGET >> $LOGS/$LOGFILE
logger "TARGET rsync directory is: $TARGET"
echo -e LOG directory is: $LOGS/$LOGFILE $NEWLINE >> $LOGS/$LOGFILE
logger "LOG file is: $LOGS/$LOGFILE"
rm -rf $TARGET/daily.5
mv $TARGET/daily.4 $TARGET/daily.5
mv $TARGET/daily.3 $TARGET/daily.4
mv $TARGET/daily.2 $TARGET/daily.3
# cp -v -al $TARGET/daily.1 $TARGET/daily.2
# rsync --log-file=$LOGS/$LOGFILE -aPv --delete-after --safe-links --stats $SOURCE $TARGET/daily.1/
# RSYNC using the link-dest option:
#
# This option behaves like --copy-dest, but unchanged files are
# hard linked from DIR to the destination directory. The files
# must be identical in all preserved attributes (e.g. permissions,
# possibly ownership) in order for the files to be linked
# together. An example:
#
# rsync -av --link-dest=$PWD/prior_dir host:src_dir/ new_dir/
#
mv $TARGET/daily.1 $TARGET/daily.2
rsync --log-file=$LOGS/$LOGFILE -aPv --delete --safe-links --stats --link-dest=$TARGET/daily.2 $SOURCE $TARGET/daily.1/
# Send completion message to syslog and log file
echo -e $NEWLINE $ENDMSG >> $LOGS/$LOGFILE
logger $ENDMSG

ND