====== 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 ===== print why ===== rsync want to transfer - add ''-i'' option (''--itemize-changes''). Usefull also with ''-n'' ''--dry-run''. ===== local replication ===== [[https://superuser.com/questions/307541/copy-entire-file-system-hierarchy-from-one-drive-to-another|Copy entire file system hierarchy from one drive to another]] rsync -avxHAXS --numeric-ids --info=progress2 / /new-disk/ -a : all files, with permissions, etc.. -v : verbose, mention files -x : stay on one file system -H : preserve hard links (not included with -a) -A : preserve ACLs/permissions (not included with -a) -X : preserve extended attributes (not included with -a) -S, --sparse handle sparse files efficiently To improve the copy speed, add -W (--whole-file), to avoid calculating deltas/diffs of the files. ===== 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. [[https://unix.stackexchange.com/questions/183504/how-to-rsync-files-between-two-remotes|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}"