From: Alexander Schmidt Date: Thu, 3 Jul 2014 03:12:52 +0000 (+0200) Subject: Added nthdayincomplete test. X-Git-Url: https://git.treefish.org/~alex/backmeupscotty.git/commitdiff_plain/24d125dbe2a3ad4d43792e1e7f8894484d7fda41 Added nthdayincomplete test. --- diff --git a/backmeupscotty b/backmeupscotty index 6affc57..7a76c15 100644 --- a/backmeupscotty +++ b/backmeupscotty @@ -4,6 +4,7 @@ REMOTE_HOST=localhost REMOTE_BASE=/tmp/backmeupscotty ARCHIVE_KEEPNBACKUPS=30 ARCHIVE_KEEPNDAYS=30 +BACKUP_RUNEVERYNTHDAY=1 function upperme { echo $(basename $0) | tr '[:lower:]' '[:upper:]' @@ -22,11 +23,14 @@ if [ $(pidof -x $(basename $0) | wc -w) -gt 2 ]; then exit 1 fi -while getopts ":q" opt; do +while getopts "qn:" opt; do case $opt in q) exec > /dev/null ;; + n) + BACKUP_RUNEVERYNTHDAY=$OPTARG + ;; esac done @@ -34,6 +38,25 @@ function grepbackups { ssh $REMOTE_HOST "ls $REMOTE_BASE/$1" | grep -E '[0-9]+-[0-9]+' } +function isIncomplete { + if ( ssh $REMOTE_HOST '[ -d '$REMOTE_BASE/$1/incomplete' ]' ); then + return 0 + else + return 1 + fi +} + +function isIncompleteOrNthDay { + if isIncomplete $1 || \ + [ $(( ( $(date +%s) / (60*60*24) ) % $BACKUP_RUNEVERYNTHDAY )) -eq 0 ]; + then + return 0 + else + return 1 + fi + +} + function scottysync { timestamp=$(date +%s) @@ -64,7 +87,7 @@ function scottysync { ssh $REMOTE_HOST "mkdir $REMOTE_BASE/$2" fi - if (ssh $REMOTE_HOST '[ -d '$REMOTE_BASE/$2/incomplete' ]'); then + if isIncomplete $2; then scottyerror Continuing old incomplete backup fi diff --git a/backmeupscotty-example b/backmeupscotty-example index 452e3c0..c49e2ad 100755 --- a/backmeupscotty-example +++ b/backmeupscotty-example @@ -7,5 +7,10 @@ REMOTE_BASE=/home/alex/backtest ARCHIVE_KEEPNBACKUPS=30 ARCHIVE_KEEPNDAYS=1 +if ! isIncompleteOrNthDay dest; then + scottyinfo "This is not the nth day and no incomplete backup exists." + exit 0 +fi + scottysync /home/alex/backtest/source dest "/gack,/gugu/*" scottysync /home/alex/backtest/source2 dest2