Skip to main content

Rsync

限制頻寬

限制傳檔的網路頻寬

--bwlimit=30000

30000 = 30000 KB/ps = 30 MB/ps

Dry Run
rsync -avh -n <source> <destination>
檔案與資料夾同步

本機內不同個資料夾做複製或同步

rsync -avavh --delete --exclude='path1/to/exclude' --exclude='path2/to/exclude' sourcesource/ destination
rsync -avh /source/*.log /destination
  • source/ 來源目錄+斜線 會複製目錄內的內容
  • source 來源目錄不加斜線 會複製整個目錄
  • --delete 來源檔案被刪除時也會同步到目的端 
進度條

遠端複製大檔案需要續傳與進度條

rsync --partial --progress --rsh=ssh <local_file> user@host:<remote_file>
複製整個系統

複製 Linux 整個系統

mount /dev/sdb1 /mnt
rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /mnt

With a exclusion file

exclude-files.txt:

/boot
/dev
/tmp
/sys
/proc
/backup
/etc/fstab
/etc/mtab
/etc/mdadm.conf
/etc/sysconfig/network*

Cloning a Linux Server

sudo rsync -vPa -e 'ssh -o StrictHostKeyChecking=no' --exclude-from=/root/exclude-files.txt / REMOTE-IP:/
How does rsync work

https://michael.stapelberg.ch/posts/2022-07-02-rsync-how-does-it-work/ 

Other solutions
  • Syncthing - It is a free and open-source file syncing application used to sync files between multiple remote devices over the internet. It works on peer-to-peer architecture and exchanges the data automatically between two devices.