4 REMOTE_BASE=/tmp/backmeupscotty
5 ARCHIVE_KEEPNBACKUPS=30
8 while getopts ":q" opt; do
16 function grepbackups {
17 ssh $REMOTE_HOST "ls $REMOTE_BASE/$1" | grep -E '[0-9]+-[0-9]+'
23 echo BACKMEUPSCOTTY: Syncing $1 to $REMOTE_HOST:$REMOTE_BASE/$2 @$timestamp
25 dir_current=$REMOTE_BASE/$2/current
26 dir_incomplete=$REMOTE_BASE/$2/incomplete
27 dir_timestamped=$REMOTE_BASE/$2/$timestamp-$(date -d @$timestamp +%Y%m%d%H%M%S)
32 rsync_exclude=$(eval echo --exclude={$3} | tr -d {})
35 echo BACKMEUPSCOTTY: Starting rsync
37 -v -aHAX --numeric-ids --delete --delete-excluded \
38 --link-dest=$dir_current \
40 $1/ $REMOTE_HOST:$dir_incomplete/
43 echo BACKMEUPSCOTTY: Timestamping completed backup and linking to current backup
45 "mv $dir_incomplete $dir_timestamped && rm -f $dir_current && ln -s $dir_timestamped $dir_current"
48 while [ $(grepbackups $2 | wc -l) -gt $ARCHIVE_KEEPNBACKUPS ]; do
49 oldestbackup=$(grepbackups $2 | head -1)
50 oldestbackuptstamp=$(echo $oldestbackup | cut -d'-' -f1)
52 if [ $oldestbackuptstamp -lt $(( $(date +%s) - $ARCHIVE_KEEPNDAYS*60*60*24 )) ]; then
53 echo BACKMEUPSCOTTY: Removing old backup $oldestbackup
54 ssh $REMOTE_HOST rm -r "$REMOTE_BASE/$2/$oldestbackup"