X-Git-Url: http://git.treefish.org/~alex/backmeupscotty.git/blobdiff_plain/ac0107435611d1c64236ba33f586fc5d142ee076..HEAD:/backmeupscotty?ds=sidebyside diff --git a/backmeupscotty b/backmeupscotty index e1fe9a5..729a781 100644 --- a/backmeupscotty +++ b/backmeupscotty @@ -1,11 +1,14 @@ #!/bin/bash +REMOTE_USER=root REMOTE_HOST=localhost REMOTE_DIR=/tmp/backmeupscotty/test ARCHIVE_KEEPNBACKUPS=30 ARCHIVE_KEEPNDAYS=30 BACKUP_RUNEVERYNTHDAY=1 BWLIMIT=500KiB +BACKUP_FORCE=0 +FAKE_SUPER=0 _ERROR_ENCOUNTERED=0 @@ -34,7 +37,7 @@ function scottyerror { } function ssh255 { - ssh $@ + ssh -l $REMOTE_USER $@ sshret=$? if [ $sshret -eq 255 ]; then @@ -104,6 +107,12 @@ function scottysync { rsync_exclude=$(eval echo --exclude={$SYNC_EXC} | tr -d {}) fi + if [ $FAKE_SUPER -eq 1 ]; then + rsync_fake_super="-M--fake-super" + else + rsync_fake_super="" + fi + if (ssh255 $REMOTE_HOST '[ ! -d '$REMOTE_DIR' ]'); then scottyinfo "Creating destination directory $REMOTE_HOST:$REMOTE_DIR." ssh255 $REMOTE_HOST "mkdir $REMOTE_DIR" @@ -114,10 +123,10 @@ function scottysync { fi scottyinfo "Starting rsync." - rsync -e ssh --bwlimit=$BWLIMIT \ + rsync -e "ssh -l $REMOTE_USER" --bwlimit=$BWLIMIT \ -v -aHAX --numeric-ids --delete --delete-excluded \ --link-dest=$dir_current \ - $rsync_exclude \ + $rsync_exclude $rsync_fake_super \ $SYNC_SRC/ $REMOTE_HOST:$dir_incomplete/ if [ $? -eq 0 ]; then @@ -183,12 +192,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 +216,12 @@ function backmeupscotty { n) BACKUP_RUNEVERYNTHDAY=$OPTARG ;; + f) + BACKUP_FORCE=1 + ;; + l) + LIST_BACKUPS=1 + ;; h) printhelp exit 0 @@ -205,7 +231,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 +262,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