Rsync

限制頻寬

限制傳檔的網路頻寬

--bwlimit=30000

30000 = 30000 KB/ps = 30 MB/ps

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

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

rsync -avh --delete --exclude='path1/to/exclude' --exclude='path2/to/exclude' source/ destination
rsync -avh /source/*.log /destination
進度條

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

rsync --partial --progress --rsh=ssh <local_file> user@host:<remote_file>
遠端同步

本機至遠端

rsync -avzh /root/rpmpkgs root@192.168.0.141:/root/

遠端至本機

rsync -avzh root@192.168.0.141:/root/rpmpkgs /tmp/myrpms

透過 SSH

# Copy a File from a Remote Server to a Local Server
rsync -avzhe ssh root@192.168.0.141:/root/anaconda-ks.cfg /tmp

# Copy a File from a Local Server to a Remote Server
rsync -avzhe ssh backup.tar.gz root@192.168.0.141:/backups/
Include & Exclude

指定附檔名

rsync -avh /source/*.log /destination

rsync -avh --include='*.log' --exclude='*' /source/ /destination

例外檔案清單

rsync -avh --exclude-from=/root/exclude-files.txt /source/ /destination

複製整個系統

複製 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



Revision #20
Created 17 July 2020 18:58:06 by Admin
Updated 3 August 2023 14:43:19 by Admin