X-Git-Url: https://git.treefish.org/~alex/backmeupscotty.git/blobdiff_plain/ac0107435611d1c64236ba33f586fc5d142ee076..2da8ed681614289264c6069c03921b418b77b0ef:/backmeupscotty diff --git a/backmeupscotty b/backmeupscotty index e1fe9a5..65e4d53 100644 --- a/backmeupscotty +++ b/backmeupscotty @@ -6,6 +6,7 @@ ARCHIVE_KEEPNBACKUPS=30 ARCHIVE_KEEPNDAYS=30 BACKUP_RUNEVERYNTHDAY=1 BWLIMIT=500KiB +BACKUP_FORCE=0 _ERROR_ENCOUNTERED=0 @@ -183,12 +184,23 @@ Usage: $(basename $0) [OPTION]... Recognized options: -q Only output errors -n Run only on nth day + -f Force backup + -l List existing backups -h Print out this help EOF } +function exclusiveLock { + if ! mkdir /var/lock/$(basename $0); then + scottyerror "Another instance of $(basename $0) is still running!" + exit 1 + else + trap deleteLock EXIT + fi +} + function backmeupscotty { - while getopts "qn:h" opt; do + while getopts "qn:flh" opt; do case $opt in q) exec > /dev/null @@ -196,6 +208,12 @@ function backmeupscotty { n) BACKUP_RUNEVERYNTHDAY=$OPTARG ;; + f) + BACKUP_FORCE=1 + ;; + l) + LIST_BACKUPS=1 + ;; h) printhelp exit 0 @@ -205,7 +223,18 @@ function backmeupscotty { ssh255 $REMOTE_HOST exit - if latestTooOld; then + if [ $LIST_BACKUPS ]; then + for backup in $(grepbackups); do + echo $backup + done + exit 0 + fi + + exclusiveLock + + if [ $BACKUP_FORCE -eq 1 ]; then + scottyinfo "Backup was enforced." + elif latestTooOld; then scottyerror "The latest backup is too old." elif isNthDay; then scottyinfo "This is the nth day." @@ -225,10 +254,3 @@ function backmeupscotty { exit 0 } - -if ! mkdir /var/lock/$(basename $0); then - scottyerror "Another instance of $(basename $0) is still running!" - exit 1 -else - trap deleteLock EXIT -fi