]> git.treefish.org Git - backmeupscotty.git/commitdiff
Added nthdayincomplete test.
authorAlexander Schmidt <alex@treefish.org>
Thu, 3 Jul 2014 03:12:52 +0000 (05:12 +0200)
committerAlexander Schmidt <alex@treefish.org>
Thu, 3 Jul 2014 03:12:52 +0000 (05:12 +0200)
backmeupscotty
backmeupscotty-example

index 6affc578cc58f4d648e4130710901c2a721b204a..7a76c15468e6fe0c0b49197e028c279e5c572c36 100644 (file)
@@ -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
 
index 452e3c0535ab37f54c8dcd3f1bdaf41eee4ef4db..c49e2adb76d6c00eeb0a90531b9d10994de2be3d 100755 (executable)
@@ -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