- scottyinfo Timestamping completed backup and linking to current backup
- ssh $REMOTE_HOST \
- "mv $dir_incomplete $dir_timestamped && rm -f $dir_current && ln -s $dir_timestamped $dir_current"
+ scottyinfo "Timestamping completed backup and linking to current backup."
+ ssh255 $REMOTE_HOST \
+ "mv $dir_incomplete $dir_timestamped && rm -f $dir_current && \
+ ln -s $(basename $dir_timestamped) $dir_current"
+ else
+ scottyerror "Rsync failed."
+ fi
+
+ while [ $(grepbackups | wc -l) -gt $ARCHIVE_KEEPNBACKUPS ]; do
+ oldestbackup=$(grepbackups | head -1)
+ oldestbackuptstamp=$(echo $oldestbackup | cut -d'-' -f1)
+
+ if [ $oldestbackuptstamp -lt $(( $(date +%s) - $ARCHIVE_KEEPNDAYS*60*60*24 )) ]; then
+ scottyinfo "Removing old backup $oldestbackup."
+ ssh255 $REMOTE_HOST rm -r "$REMOTE_DIR/$oldestbackup"
+ else
+ break
+ fi
+ done
+}
+
+function deleteLock {
+ if ! rmdir /var/lock/$(basename $0); then
+ scottyerror "Could not delete lockfile /tmp/$(basename $0).lock!"
+ fi
+}
+
+function cleanup_abort {
+ scottyerror "Caught exit signal! Cleaning up."
+
+ cleanup ABORT
+
+ if [ $(jobs -p) ]; then
+ scottyerror "TERMinating remaining child processes."
+ kill $(jobs -p)