rsync命令是一個遠程數據同步工具,可經過LAN/WAN快速同步多臺主機間的文件。rsync使用所謂的「rsync算法」來使本地和遠程兩個主機之間的文件達到同步,這個算法只傳送兩個文件的不一樣部分,而不是每次都整份傳送,所以速度至關快。算法
rsync有六種不一樣的工做模式:shell
注: src表示源文件,dest表示目的文件數組
[root@1 ~]# rsync -av /etc/passwd /tmp/11.txt sending incremental file list passwd sent 1222 bytes received 31 bytes 2506.00 bytes/sec total size is 1148 speedup is 0.92
[root@1 ~]# rsync -av /etc/passwd root@192.168.8.129:/tmp/11.txt root@192.168.8.129's password: sending incremental file list passwd sent 1222 bytes received 31 bytes 358.00 bytes/sec total size is 1148 speedup is 0.92
注: 進行遠程同步的時候,遠程機和本地機必須都安裝有rsync工具才能夠。ssh
[root@1 ~]# rsync -av -e "ssh -p 22" /etc/passwd root@192.168.8.129:/tmp/11.txt root@192.168.8.129's password: sending incremental file list sent 31 bytes received 12 bytes 7.82 bytes/sec total size is 1148 speedup is 26.70
[root@1 ~]# rsync -av root@192.168.8.129:/etc/passwd /tmp/22.txt root@192.168.8.129's password: receiving incremental file list passwd sent 42 bytes received 83 bytes 27.78 bytes/sec total size is 1149 speedup is 9.19
[root@1 ~]# rsync -avP /root/grep/ /tmp/grep_dest/ sending incremental file list created directory /tmp/grep_dest ./ 717.sh 65 100% 0.00kB/s 0:00:00 (xfer#1, to-check=20/22) aaa.sed.shell 47 100% 3.53kB/s 0:00:00 (xfer#2, to-check=19/22) …………
[root@1 ~]# rsync -avL /root/grep/ /tmp/grep_dest/ sending incremental file list adailink sent 1530 bytes received 32 bytes 3124.00 bytes/sec total size is 14275 speedup is 9.14
[root@1 ~]# touch /tmp/grep_dest/new2.txt [root@1 ~]# rsync -av --delete /root/grep/ /tmp/grep_dest/ sending incremental file list ./ deleting new2.txt ##刪除文件new2.txt adailink -> /root/awk/test.txt sent 405 bytes received 19 bytes 848.00 bytes/sec total size is 13178 speedup is 31.08
[root@1 ~]# rsync -av --exclude "*.txt" --exclude "*.shell" /root/grep/ /tmp/grep_dest/ sending incremental file list ./ 717.sh adailink -> /root/awk/test.txt boot.log.bak
注: 能夠同時過濾多種文件。工具