rsync

get changes to separate dir

Option –compare-dest also compare destination files relative to DIR.

If DIR is a relative path, it is relative to the destination directory

So to restore changes between remote DST and current folder . but save restored files in _RESTORED_BACKUP folder:

rsync --dry-run -v -ra -P -i --compare-dest=.. ${DSTHOST}:/backup/ _RESTORED_BACKUP

rsync want to transfer - add -i option (–itemize-changes). Usefull also with -n –dry-run.

between two remotes

Rsync cannot work with two remotes. As workaround SSH tunnel to remote host is created and rsync is spawned locally on src host.

How to rsync files between two remotes?

#!/bin/bash -eux
SOURCE_USER=root
SOURCE_HOST=192.168.179.2
SOURCE_PATH="/public/image.iso"
 
TARGET_USER=root
TARGET_HOST=pve5
TARGET_PATH=/mnt/pve/cephfs/template/iso/
 
# Escape characters:
SOURCE_PATH=$(printf %q "$SOURCE_PATH")
TARGET_PATH=$(printf %s "$TARGET_PATH")
 
 
OPTS="--recursive --times --partial --progress --verbose --update --archive --stats"
OPTS="${OPTS} --bwlimit=400"
OPTS="${OPTS} --compress --compress-level=9"
 
# Test connection to accept remote host key
ssh -l $TARGET_USER -A -R localhost:22000:$TARGET_HOST:22 $SOURCE_USER@$SOURCE_HOST "ssh localhost -p 22000 -l root whoami"
 
ssh -l $TARGET_USER -A -R localhost:22000:$TARGET_HOST:22 \
$SOURCE_USER@$SOURCE_HOST "rsync -e 'ssh -p 22000' ${OPTS} \
${SOURCE_PATH} \
$TARGET_USER@localhost:${TARGET_PATH}"