X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=bin%2Fsrsync-incremental;h=644b2fef253f9a881026b3afa1fbc4f3b968b2b5;hb=8935e6db7519655d39889a85a6c72edf4a9ee333;hp=909c028802032b5679321c7dcc53e0a83518c1a2;hpb=eb6bc786f279dce74d397ae59639fc14b7a98d5c;p=config%2Fdotfiles.git diff --git a/bin/srsync-incremental b/bin/srsync-incremental index 909c028..644b2fe 100755 --- a/bin/srsync-incremental +++ b/bin/srsync-incremental @@ -34,11 +34,11 @@ fi cd "$1" || exit 1 shift -dest=`echo backup-*` -if test "x$dest" != 'xbackup-*'; then - # -F and grep is used to list only directories, zsh's *(/) would be great. - dest="`pwd`/`ls -1dF backup-* | grep / | tail -n1`" -fi +# Get absolute path to last backup directory. +for x in backup-*; do + test -d "$x" || continue + dest="../$x" # relative to destination directory +done target=backup-`date '+%Y-%m-%d-%H-%M-%S'` @@ -53,4 +53,12 @@ rsync \ --archive --hard-links --numeric-ids --one-file-system \ --link-dest="$dest" \ "$@" current \ -&& mv current "$target" +|| { + # Try to remove "current" without changing the exit code. In case the + # connection failed without transferring any files, we want the next + # backup to be able to run. + code=$? + rmdir current 2>/dev/null || true + exit $code +} +mv current "$target"