Rsync

rsync#

Tips#

# 使用 SSH 同步
rsync -avz -e ssh [email protected]:/remote/dir /this/dir/
# 远程使用 sudo
rsync --rsync-path="sudo rsync" -avz dnsmasq/ [email protected]:/etc/dnsmasq/
# 备份整个系统
rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /path/to/backup/folder
# 使用 --info=progress2 显示总体的进度, 而不是每个文件
rsync -aAX --info=progress2 --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /path/to/backup/folder
# 不同步权限用户分组信息
rsync -avz --no-perms --no-owner --no-group mnt/wener abuild/
# 配合 fswatch 使用
# 拷贝
fswatch ./ | xargs -I{} cp {} ~/Dropbox/backup/latest/
# rsync
alias run_rsync='rsync -azP --exclude ".*/" --exclude ".*" --exclude "tmp/" ~/Documents/repos/my_repository [email protected]:~'
run_rsync; fswatch -o . | while read f; do run_rsync; done

并行#

rsync -avzm --stats --safe-links --ignore-existing --dry-run \
--human-readable /data/projects REMOTE-HOST:/data/ > /tmp/transfer.log
# --relative 要求在 /data/projects 执行
cat /tmp/transfer.log | \
parallel --will-cite -j 5 rsync -avzm --relative \
--stats --safe-links --ignore-existing \
--human-readable {} REMOTE-HOST:/data/ > result.log