]> git.treefish.org Git - backmeupscotty.git/commitdiff
Using scotty functions for info and alert messages
authorAlexander Schmidt <alex@treefish.org>
Wed, 11 Jun 2014 14:16:22 +0000 (16:16 +0200)
committerAlexander Schmidt <alex@treefish.org>
Wed, 11 Jun 2014 14:16:22 +0000 (16:16 +0200)
backmeupscotty

index e9bab430abb4c03726c44a4338255499d266a000..7aa814abdf69de8733c192d6a954c3fd214612db 100644 (file)
@@ -5,8 +5,20 @@ REMOTE_BASE=/tmp/backmeupscotty
 ARCHIVE_KEEPNBACKUPS=30
 ARCHIVE_KEEPNDAYS=30
 
+function upperme {
+    echo $(basename $0) | tr '[:lower:]' '[:upper:]'
+}
+
+function scottyinfo {
+    echo $(upperme): $@ 
+}
+
+function scottyerror {
+    echo $(upperme): $@ >&2 
+}
+
 if [ $(pidof -x $(basename $0) | wc -w) -gt 2 ]; then 
-    echo BACKMEUPSCOTTY: Another instance of $(basename $0) is already running! >&2
+    scottyerror Another instance of $(basename $0) is already running!
     exit 1
 fi
 
@@ -25,15 +37,15 @@ function grepbackups {
 function scottysync {
     timestamp=$(date +%s)
 
-    echo BACKMEUPSCOTTY: Syncing $1 to $REMOTE_HOST:$REMOTE_BASE/$2 @$timestamp
+    scottyinfo Syncing $1 to $REMOTE_HOST:$REMOTE_BASE/$2 @$timestamp
 
     if [ ! -d "$1" ]; then
-       echo BACKMEUPSCOTTY: Source dir $1 does not exist. Not syncing! >&2
+       scottyerror Source dir $1 does not exist. Not syncing!
        return 1
     fi
 
     if [ $(ls -A "$1" | wc -l) -eq 0 ]; then
-       echo BACKMEUPSCOTTY: Source dir $1 is empty. Not syncing! >&2
+       scottyerror Source dir $1 is empty. Not syncing!
        return 1
     fi
 
@@ -48,15 +60,15 @@ function scottysync {
     fi
 
     if (ssh $REMOTE_HOST '[ ! -d '$REMOTE_BASE/$2' ]'); then
-       echo BACKMEUPSCOTTY: Creating destination directory $REMOTE_HOST:$REMOTE_BASE/$2
+       scottyinfo Creating destination directory $REMOTE_HOST:$REMOTE_BASE/$2
        ssh $REMOTE_HOST "mkdir $REMOTE_BASE/$2"
     fi
 
     if (ssh $REMOTE_HOST '[ -d '$REMOTE_BASE/$2/incomplete' ]'); then
-       echo BACKMEUPSCOTTY: Continuing old incomplete backup >&2
+       scottyerror Continuing old incomplete backup
     fi
 
-    echo BACKMEUPSCOTTY: Starting rsync
+    scottyinfo Starting rsync
     rsync -e ssh \
        -v -aHAX --numeric-ids --delete --delete-excluded \
        --link-dest=$dir_current \
@@ -64,7 +76,7 @@ function scottysync {
        $1/ $REMOTE_HOST:$dir_incomplete/
     
     if [ $? -eq 0 ]; then
-       echo BACKMEUPSCOTTY: Timestamping completed backup and linking to current backup
+       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"
     fi
@@ -74,7 +86,7 @@ function scottysync {
        oldestbackuptstamp=$(echo $oldestbackup | cut -d'-' -f1)
 
        if [ $oldestbackuptstamp -lt $(( $(date +%s) - $ARCHIVE_KEEPNDAYS*60*60*24 )) ]; then
-           echo BACKMEUPSCOTTY: Removing old backup $oldestbackup
+           scottyinfo Removing old backup $oldestbackup
            ssh $REMOTE_HOST rm -r "$REMOTE_BASE/$2/$oldestbackup"
        else
            break