rsync命令是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件。rsync使用所谓的“rsync算法”来使本地和远程两个主机之间的文件达到同步,这个算法只传送两个文件的不同部分,而不是每次都整份传送,因此速度相当快。
rsync有六种不同的工作模式:
注: src表示源文件,dest表示目的文件
[root@adai003 ~]# 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@adai003 ~]# 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工具才可以。
[root@adai003 ~]# 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@adai003 ~]# 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@adai003 ~]# 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@adai003 ~]# 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@adai003 ~]# touch /tmp/grep_dest/new2.txt
[root@adai003 ~]# 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@adai003 ~]# 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
注: 可以同时过滤多种文件。
(adsbygoogle = window.adsbygoogle || []).push({});