10.28 rsync工具介紹ssh
10.29/10.30 rsync經常使用選項工具
10.31 rsync經過ssh同步code
yum install -y rsync
rsync -av /etc/passwd /tmp/1.txt rsync -av /etc/passwd root@192.168.83.22:/tmp/1.txt
rsync [OPTION] … SRC DEST 本地同步 rsync [OPTION] … SRC [user@]host:DEST 本地同步遠程(不寫用戶則是當前用戶,對方沒有則報錯) rsync [OPTION] … [user@]host:SRC DEST 遠程同步本地 rsync [OPTION] … SRC [user@]host::DEST ? rsync [OPTION] … [user@]host::SRC DEST
rsync經常使用選項rem
示例:同步
//準備實驗用的aaa目錄 root@axiang01 ~]# ls -l aaa 總用量 4 -rw-r--r--. 1 root root 12 7月 19 10:13 11.txt drwxr-xr-x. 2 root root 6 7月 19 10:12 aa lrwxrwxrwx. 1 root root 10 7月 19 10:19 softlink1 -> /tmp/1.txt //日思一腦殘rsync av是標配 [root@axiang01 ~]# rsync -av /root/aaa/ /tmp/aaa_dest/ 建議目錄後加「/」 sending incremental file list created directory /tmp/aaa_dest ./ 11.txt softlink1 -> /tmp/1.txt aa/ sent 161 bytes received 41 bytes 404.00 bytes/sec total size is 22 speedup is 0.11 [root@axiang01 ~]# ls -l /tmp/aaa_dest 總用量 4 -rw-r--r--. 1 root root 12 7月 19 10:13 11.txt drwxr-xr-x. 2 root root 6 7月 19 10:12 aa lrwxrwxrwx. 1 root root 10 7月 19 10:19 softlink1 -> /tmp/1.txt [root@axiang01 ~]# //幹掉軟,靠avL [root@axiang01 ~]# rsync -avL /root/aaa/ /tmp/aaa_dest/ //增長L選項能夠同步軟連接的源文件,不過仍是以軟鏈接命名(爲了要和同步源目錄下的文件命名保持一致) sending incremental file list softlink1 sent 1166 bytes received 32 bytes 2396.00 bytes/sec total size is 1053 speedup is 0.88 [root@axiang01 ~]# ls -l /tmp/aaa_dest/ 總用量 8 -rw-r--r--. 1 root root 12 7月 19 10:13 11.txt drwxr-xr-x. 2 root root 6 7月 19 10:12 aa -rw-r--r--. 1 root root 1041 7月 18 22:32 softlink1 此處與/tmp/1.txt同步 //同步啥是啥,別整沒用的 --delete [root@axiang01 ~]# touch /tmp/aaa_dest/new.txt 人無我有~ [root@axiang01 ~]# rsync -avL /root/aaa/ /tmp/aaa_dest/ --delete 還有麼? sending incremental file list ./ deleting new.txt //不一樣步沒用的 --exclude [root@axiang01 ~]# rm -rf /tmp/aaa_dest/* 重來 [root@axiang01 ~]# rsync -avL /root/aaa/ /tmp/aaa_dest/ --exclude "*.txt" --exclude "a*" 不一樣步啥啥啥 sending incremental file list ./ softlink1 sent 1135 bytes received 34 bytes 2338.00 bytes/sec total size is 1041 speedup is 0.89 [root@axiang01 ~]# ls /tmp/aaa_dest/ softlink1 //exclude挺好使 //看同步大文件要多久 -P選項 [root@axiang01 ~]# !rm rm -rf /tmp/aaa_dest/* [root@axiang01 ~]# rsync -avP /root/aaa/ /tmp/aaa_dest/ 精確顯示傳輸速度和% sending incremental file list ./ 11.txt 12 100% 0.00kB/s 0:00:00 (xfer#1, to-check=2/4) softlink1 -> /tmp/1.txt aa/ //哎呦喂,你新你有理 -auv 不一樣步mtime落後的源文件 [root@axiang01 ~]# vi /tmp/aaa_dest/11.txt [root@axiang01 ~]# rsync -auv /root/aaa/ /tmp/aaa_dest/ sending incremental file list ./ sent 100 bytes received 16 bytes 232.00 bytes/sec total size is 22 speedup is 0.19 [root@axiang01 ~]# cat /tmp/aaa_dest/11.txt 6ofjeow afegs efewf:66 555 444 沒變 //壓縮傳輸 -z選項 [root@axiang01 ~]# rsync -az /root/aaa/ /tmp/aaa_dest/ //文件不大看不出效果
示例:登錄
//推文件 沒弄過密鑰須要輸入登陸密碼 [root@axiang01 ~]# rsync -av /etc/passwd 192.168.83.22:/tmp/axiang.txt sending incremental file list passwd sent 1115 bytes received 31 bytes 99.65 bytes/sec total size is 1041 speedup is 0.91 //拉文件 [root@axiang01 ~]# rsync -avP 192.168.83.22:/tmp/axiang.txt /tmp/aaa.txt receiving incremental file list axiang.txt 1041 100% 1016.60kB/s 0:00:00 (xfer#1, to-check=0/1) sent 30 bytes received 1124 bytes 769.33 bytes/sec total size is 1041 speedup is 0.90