[iyunv@localhost ~]# ls abc/
1.tx~ 1.txt a test123.txt
[iyunv@localhost ~]# ls /tmp/abc_dest/
1.tx~ 1.txt a new.txt test123.txt
[iyunv@localhost ~]# rsync -avL --delete /root/abc/ /tmp/abc_dest/
sending incremental file list
./
deleting new.txt
sent 96 bytes received 16 bytes 224.00 bytes/sec
total size is 1151 speedup is 10.28
[iyunv@localhost ~]# ls /tmp/abc_dest/
1.tx~ 1.txt a test123.txt
[iyunv@localhost ~]# rsync -av --exclude "*.txt" /root/abc/ /tmp/abc_dest/
sending incremental file list
./
1.tx~
a/
sent 107 bytes received 38 bytes 290.00 bytes/sec
total size is 0 speedup is 0.00
[iyunv@localhost ~]# ls /tmp/abc_dest/
1.tx~ a
[iyunv@localhost ~]# ls abc/
1.tx~ 1.txt 2.txt a test123.txt
sent 268 bytes received 79 bytes 694.00 bytes/sec
total size is 22 speedup is 0.06
使用大写p参数,可以显示同步传输的速度、和进度。传输大文件时很实用。
-u:update
[iyunv@localhost ~]# cat /root/abc/123
test 20171201
[iyunv@localhost ~]# cat /tmp/abc_dest/123
test 20171205
test 20171205
[iyunv@localhost ~]# rsync -avu /root/abc/ /tmp/abc_dest/
sending incremental file list
./
sent 146 bytes received 16 bytes 324.00 bytes/sec
total size is 36 speedup is 0.22
[iyunv@localhost ~]# cat /tmp/abc_dest/123
test 20171205
test 20171205
[iyunv@localhost ~]# cat /root/abc/123
test 20171201
加上该选项,如果DEST中文件比SRC中的新,则不同步。
通过ssh同步
通过ssh同步的两台机器需要相互之间可以通信,并且两台都要安装rsync工具。
通过ssh的方式,将一台机器的文件同步到另一台机器。
[iyunv@localhost ~]# rsync -av /etc/passwd 192.168.159.130:/tmp/2017.txt root@192.168.159.130's password:
sending incremental file list
passwd
sent 1202 bytes received 31 bytes 352.29 bytes/sec
total size is 1128 speedup is 0.91
[iyunv@localhost ~]# rsync -av 192.168.159.130:/tmp/2017.txt /tmp/201712.txt root@192.168.159.130's password:
receiving incremental file list
2017.txt
sent 30 bytes received 1209 bytes 354.00 bytes/sec
total size is 1128 speedup is 0.91
[iyunv@localhost ~]# ls /tmp
201712.txt