X-Git-Url: https://git.treefish.org/~alex/backmeupscotty.git/blobdiff_plain/5c8e1209ef263877c5d6fa0e00386c48c0b241ea..0984727e5376cebd26b5ff6e9469cfc63d0c756d:/backmeupscotty diff --git a/backmeupscotty b/backmeupscotty index be1ce20..80392a3 100644 --- a/backmeupscotty +++ b/backmeupscotty @@ -6,16 +6,28 @@ ARCHIVE_KEEPNBACKUPS=30 ARCHIVE_KEEPNDAYS=30 BACKUP_RUNEVERYNTHDAY=1 -function upperme { - echo $(basename $0) | tr '[:lower:]' '[:upper:]' +_ERROR_ENCOUNTERED=0 +_UPPERME=$(echo $(basename $0) | tr '[:lower:]' '[:upper:]') + +function timestamp { + date +"[%y-%m-%d %H:%M:%S]" +} + +function scottyline { + echo $(timestamp) $_UPPERME: $@ } function scottyinfo { - echo $(upperme): $@ + if ($_ERROR_ENCOUNTERED -eq 0); then + scottyline $@ + else + scottyline $@ >&2 + fi } function scottyerror { - echo $(upperme): $@ >&2 + scottyline $@ >&2 + _ERROR_ENCOUNTERED=1 } function ssh255 { @@ -110,6 +122,8 @@ function scottysync { 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 @@ -126,15 +140,11 @@ function scottysync { } function deleteLock { - if ! rmdir /tmp/$(basename $0).lock; then + if ! rmdir /var/lock/$(basename $0); then scottyerror "Could not delete lockfile /tmp/$(basename $0).lock!" fi } -function prepare { - scottyinfo "Preparing for sync." -} - function cleanup_abort { scottyerror "Caught exit signal! Cleaning up." @@ -213,7 +223,7 @@ function backmeupscotty { exit 0 } -if ! mkdir /tmp/$(basename $0).lock; then +if ! mkdir /var/lock/$(basename $0); then scottyerror "Another instance of $(basename $0) is still running!" exit 1 else