diff --git a/remote-backup b/remote-backup index 0405599..3754430 100755 --- a/remote-backup +++ b/remote-backup @@ -105,8 +105,8 @@ do $RM -rf "$SNAPSHOT_RW/$NAME/daily.${MAX_ROTATE}" fi -# step 2: shift the middle snapshots(s) back by one, if they exist - for backup_number in $(seq $((${MAX_ROTATE}-1)) -1 1) +# step 2: shift the snapshots(s) back by one, if they exist + for backup_number in $(seq $((${MAX_ROTATE}-1)) -1 0) do if [ -d "$SNAPSHOT_RW/$NAME/daily.${backup_number}" ] then @@ -115,23 +115,22 @@ do fi done -# step 3: make a hard-link-only (except for dirs) copy of the latest snapshot, -# if that exists - if [ -d "$SNAPSHOT_RW/$NAME/daily.0" ] +# step 3: rsync from the system, linking to latest snapshot if files are +# identical. + RSYNC_OPTS="-a \ + --delete \ + --delete-excluded \ + --exclude-from='$EXCLUDES' \ + --bwlimit='$BWLIMIT'" + + if [ -d "$SNAPSHOT_RW/$NAME/daily.1/" ] then - $CP -al "$SNAPSHOT_RW/$NAME/daily.0" "$SNAPSHOT_RW/$NAME/daily.1" + RSYNC_OPTS="$RSYNC_OPTS \ + --link-dest='$SNAPSHOT_RW/$NAME/daily.1/'" fi -# step 4: rsync from the system into the latest snapshot (notice that -# rsync behaves like cp --remove-destination by default, so the destination -# is unlinked first. If it were not so, this would copy over the other -# snapshot(s) too! $RSYNC \ - -a \ - --delete \ - --delete-excluded \ - --exclude-from="$EXCLUDES" \ - --bwlimit="$BWLIMIT" \ + $RSYNC_OPTS \ "${REMOTE_LOCATION}" \ "$SNAPSHOT_RW/$NAME/daily.0"