X-Git-Url: http://git.treefish.org/~alex/backmeupscotty.git/blobdiff_plain/393f03ad49a1175b5a5b7cf0729f975073d2d1cc..24d125dbe2a3ad4d43792e1e7f8894484d7fda41:/backmeupscotty?ds=sidebyside diff --git a/backmeupscotty b/backmeupscotty index 7aa814a..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 @@ -78,7 +101,7 @@ function scottysync { if [ $? -eq 0 ]; then scottyinfo Timestamping completed backup and linking to current backup ssh $REMOTE_HOST \ - "mv $dir_incomplete $dir_timestamped && rm -f $dir_current && ln -s $dir_timestamped $dir_current" + "mv $dir_incomplete $dir_timestamped && rm -f $dir_current && ln -s $(basename $dir_timestamped) $dir_current" fi while [ $(grepbackups $2 | wc -l) -gt $ARCHIVE_KEEPNBACKUPS ]; do