X-Git-Url: https://git.treefish.org/~alex/backmeupscotty.git/blobdiff_plain/055e2cc6e3d94e1e7cc1d7158f54c4c95cdafa0f..8d7e0fed296a508b7c2ff2ec93fdba655186fbf7:/backmeupscotty?ds=sidebyside diff --git a/backmeupscotty b/backmeupscotty index 965da29..e9bab43 100644 --- a/backmeupscotty +++ b/backmeupscotty @@ -5,6 +5,11 @@ REMOTE_BASE=/tmp/backmeupscotty ARCHIVE_KEEPNBACKUPS=30 ARCHIVE_KEEPNDAYS=30 +if [ $(pidof -x $(basename $0) | wc -w) -gt 2 ]; then + echo BACKMEUPSCOTTY: Another instance of $(basename $0) is already running! >&2 + exit 1 +fi + while getopts ":q" opt; do case $opt in q) @@ -22,6 +27,16 @@ function scottysync { echo BACKMEUPSCOTTY: Syncing $1 to $REMOTE_HOST:$REMOTE_BASE/$2 @$timestamp + if [ ! -d "$1" ]; then + echo BACKMEUPSCOTTY: Source dir $1 does not exist. Not syncing! >&2 + return 1 + fi + + if [ $(ls -A "$1" | wc -l) -eq 0 ]; then + echo BACKMEUPSCOTTY: Source dir $1 is empty. Not syncing! >&2 + return 1 + fi + dir_current=$REMOTE_BASE/$2/current dir_incomplete=$REMOTE_BASE/$2/incomplete dir_timestamped=$REMOTE_BASE/$2/$timestamp-$(date -d @$timestamp +%Y%m%d%H%M%S) @@ -32,6 +47,15 @@ function scottysync { rsync_exclude=$(eval echo --exclude={$3} | tr -d {}) fi + if (ssh $REMOTE_HOST '[ ! -d '$REMOTE_BASE/$2' ]'); then + echo BACKMEUPSCOTTY: Creating destination directory $REMOTE_HOST:$REMOTE_BASE/$2 + ssh $REMOTE_HOST "mkdir $REMOTE_BASE/$2" + fi + + if (ssh $REMOTE_HOST '[ -d '$REMOTE_BASE/$2/incomplete' ]'); then + echo BACKMEUPSCOTTY: Continuing old incomplete backup >&2 + fi + echo BACKMEUPSCOTTY: Starting rsync rsync -e ssh \ -v -aHAX --numeric-ids --delete --delete-excluded \