X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=bin%2Fsrsync-incremental;h=644b2fef253f9a881026b3afa1fbc4f3b968b2b5;hb=8935e6db7519655d39889a85a6c72edf4a9ee333;hp=9ebf41949518ba541d2ee6cdedce24b38b2a44d0;hpb=392f7c624686e93ed5236648a612717d8c469c73;p=config%2Fdotfiles.git diff --git a/bin/srsync-incremental b/bin/srsync-incremental index 9ebf419..644b2fe 100755 --- a/bin/srsync-incremental +++ b/bin/srsync-incremental @@ -21,6 +21,8 @@ # along with this program. If not, see . +set -e + if test "$#" -lt 2; then echo "Usage: $0 " >&2 echo @@ -28,14 +30,15 @@ if test "$#" -lt 2; then exit 2 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'` @@ -50,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"