rsync文件同步工具介绍 、常用选项 、通过ssh同步

rsync文件同步工具介绍

rsync工具可以用来同步文件,比如a目录到b目录,a机器到b机器,(多次同步,可以只同步变动的文件)

例:rsync -av /etc/passwd /tmp/1.txt 同步passwd到1.txt中,-v可视化

rsync -av /etc/passwd  [email protected]:/tmp/1.txt 远程同步

root@可省略,默认是当前登录用户

常用选项

[root@g_linux01 ~]# rsync -av /root/soft/ /tmp/test_dest/
sending incremental file list
./
1.txt
2.txt
3.txt

sent 180 bytes  received 72 bytes  504.00 bytes/sec
total size is 0  speedup is 0.00
[root@g_linux01 ~]# ls /tmp/test_dest/
1.txt  2.txt  3.txt

--delete 删除原目录中没有的文件

[root@g_linux01 ~]# touch /tmp/test_dest/4.txt
[root@g_linux01 ~]# rsync -av --delete /root/soft/ /tmp/test_dest/
sending incremental file list
./
deleting 4.txt

sent 63 bytes  received 15 bytes  156.00 bytes/sec
total size is 0  speedup is 0.00

 --exclude 过滤掉log类型文件

[root@g_linux01 soft]# ls 
1.log  1.txt  2.txt  3.txt
[root@g_linux01 soft]# rsync -av --exclude "*.log" /root/soft/ /tmp/test_dest/
sending incremental file list
./

sent 67 bytes  received 15 bytes  164.00 bytes/sec
total size is 0  speedup is 0.00
[root@g_linux01 soft]# ls /tmp/test_dest/
1.txt  2.txt  3.txt

 通过ssh同步 ,-e "ssh -p 22" 指定22端口

[root@g_linux01 soft]# rsync -avP -e "ssh -p 22" /root/soft/ 192.168.198.129:/tmp/1_dest/ 
[email protected]'s password: 
Permission denied, please try again.
[email protected]'s password: 
sending incremental file list

sent 78 bytes  received 12 bytes  6.67 bytes/sec
total size is 0  speedup is 0.00

猜你喜欢

转载自my.oschina.net/u/3771583/blog/1786113