X-Git-Url: https://git.treefish.org/~alex/backmeupscotty.git/blobdiff_plain/aad0734411ecf750bf2233dba6cffb333da50d68..190f715747bca44914cb8904e3b07c2d499f44f4:/backmeupscotty?ds=inline diff --git a/backmeupscotty b/backmeupscotty index 44e9c54..152cf86 100644 --- a/backmeupscotty +++ b/backmeupscotty @@ -6,16 +6,18 @@ ARCHIVE_KEEPNBACKUPS=30 ARCHIVE_KEEPNDAYS=30 BACKUP_RUNEVERYNTHDAY=1 -function upperme { - echo $(basename $0) | tr '[:lower:]' '[:upper:]' +_UPPERME=$(echo $(basename $0) | tr '[:lower:]' '[:upper:]') + +function timestamp { + date +"[%y-%m-%d %H:%M:%S]" } function scottyinfo { - echo $(upperme): $@ + echo $(timestamp) $_UPPERME: $@ } function scottyerror { - echo $(upperme): $@ >&2 + echo $(timestamp) $_UPPERME: $@ >&2 } function ssh255 { @@ -125,8 +127,10 @@ function scottysync { done } -function prepare { - scottyinfo "Preparing for sync." +function deleteLock { + if ! rmdir /var/lock/$(basename $0); then + scottyerror "Could not delete lockfile /tmp/$(basename $0).lock!" + fi } function cleanup_abort { @@ -139,6 +143,8 @@ function cleanup_abort { kill $(jobs -p) fi + deleteLock + exit } @@ -150,6 +156,11 @@ function prepare { scottyinfo "No prepare function was defined." } +function cleanup_normal { + cleanup + deleteLock +} + function printhelp { cat </var/run/$(basename $0).pid -if ! flock -n 200; then +if ! mkdir /var/lock/$(basename $0); then scottyerror "Another instance of $(basename $0) is still running!" exit 1 +else + trap deleteLock EXIT fi -echo $$ 1>&200