rsync工具能夠用來同步文件,好比a目錄到b目錄,a機器到b機器,(屢次同步,能夠只同步變更的文件)linux
例:rsync -av /etc/passwd /tmp/1.txt 同步passwd到1.txt中,-v可視化ssh
rsync -av /etc/passwd root@192.168.133.130:/tmp/1.txt 遠程同步工具
root@可省略,默認是當前登陸用戶spa
[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 刪除原目錄中沒有的文件code
[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類型文件rem
[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
[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 list sent 78 bytes received 12 bytes 6.67 bytes/sec total size is 0 speedup is 0.00