rsync文件同步工具介绍
rsync工具可以用来同步文件,比如a目录到b目录,a机器到b机器,(多次同步,可以只同步变动的文件)
例:rsync -av /etc/passwd /tmp/1.txt 同步passwd到1.txt中,-v可视化
rsync -av /etc/passwd root@192.168.133.130:/tmp/1.txt 远程同步
root@可省略,默认是当前登录用户
常用选项
[root@g_linux01 ~]# rsync -av /root/soft/ /tmp/test_dest/sending incremental file list./1.txt2.txt3.txtsent 180 bytes received 72 bytes 504.00 bytes/sectotal 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.txtsent 63 bytes received 15 bytes 156.00 bytes/sectotal 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/sectotal 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/ root@192.168.198.129's password: Permission denied, please try again.root@192.168.198.129's password: sending incremental file listsent 78 bytes received 12 bytes 6.67 bytes/sectotal size is 0 speedup is 0.00