【rsync】使用rsync命令提高檔案傳輸效率
眾多資料庫伺服器的管理過程中,在不同伺服器間的檔案傳輸是免不了的。您可以使用scp命令或FTP方法完成檔案的傳送和接收,這篇文章我將給大家介紹另外一種方法,這就是rsync命令。
rsync是檔案傳輸程式,它的功能和演算法描述可以參考維基百科中的介紹。
參考連結:
我來透過實驗給大家展示一下rsync命令的常用方法。
這裡我們演示使用的作業系統是Linux,rsync已經預裝好。如果是AIX作業系統,需要單獨在IBM網站下載安裝包安裝。
演示場景:將secDB1伺服器SRC目錄下的內容同步傳輸到secDB2伺服器DEST目錄下,整個過程在secDB1伺服器上來完成。
1.在第一臺主機的根目錄下建立一個名為“SRC”的目錄,作為我們傳輸演示的源目錄。
[root@secDB1 /]# mkdir /SRC
2.在SRC目錄中建立兩個檔案f1和f2
[root@secDB1 /]# cd /SRC
[root@secDB1 SRC]# touch f1
[root@secDB1 SRC]# touch f2
[root@secDB1 SRC]# ls -ltr
total 0
-rw-r--r-- 1 root root 0 Feb 21 10:37 f1
-rw-r--r-- 1 root root 0 Feb 21 10:37 f2
3.在第二臺主機的根目錄下建立一個名為“DEST”的目錄,作為我們傳輸演示的目標目錄
[root@secDB2 /]# cd /
[root@secDB2 /]# mkdir /DEST
4.將secDB1伺服器SRC目錄下的內容同步傳輸到secDB2伺服器DEST目錄下
[root@secDB1 SRC]# rsync -av /SRC/ -e ssh root@172.17.193.211:/DEST
root@172.17.193.211's password:
building file list ... done
./
f1
f2
sent 162 bytes received 70 bytes 42.18 bytes/sec
total size is 0 speedup is 0.00
5.驗證第二臺主機的DEST目錄下是否有傳送過來的檔案
[root@secDB2 /]# cd /DEST
[root@secDB2 DEST]# ls -ltr
total 0
-rw-r--r-- 1 root root 0 Feb 21 02:37 f1
-rw-r--r-- 1 root root 0 Feb 21 02:37 f2
檔案傳送成功,目的達到。
6.修改DEST目錄下的f1檔案內容,使之與源目錄SRC中的f1目錄不相同
[root@secDB2 DEST]# echo "mod" > f1
[root@secDB2 DEST]# cat f1
mod
[root@secDB2 DEST]# ls -ltr
total 4
-rw-r--r-- 1 root root 0 Feb 21 02:37 f2
-rw-r--r-- 1 root root 4 Feb 21 02:59 f1
7.再次將SRC目錄下的內容向DEST目錄同步
[root@secDB1 SRC]# rsync -av /SRC/ -e ssh root@172.17.193.211:/DEST
root@172.17.193.211's password:
building file list ... done
f1
sent 114 bytes received 48 bytes 46.29 bytes/sec
total size is 0 speedup is 0.00
注意,此時僅僅將有變化的內容f1同步到了DEST目錄,這也是rsync命令的優勢所在。
8.在經過再次同步之後,此時DEST目錄下的檔案再一次與SRC目錄下的內容保持一致。
[root@secDB2 DEST]# ls -ltr
total 0
-rw-r--r-- 1 root root 0 Feb 21 02:37 f1
-rw-r--r-- 1 root root 0 Feb 21 02:37 f2
9.注意“/”符號帶來的差別
如果將“/SRC/”後面的“/”去掉,此時將會將SRC目錄和目錄的下的所有內容統統的傳送到DEST目錄下。
[root@secDB1 SRC]# rsync -av /SRC -e ssh root@172.17.193.211:/DEST
root@172.17.193.211's password:
building file list ... done
SRC/
SRC/f1
SRC/f2
sent 166 bytes received 70 bytes 67.43 bytes/sec
total size is 0 speedup is 0.00
10.使用rsync命令的聯機幫助文件可以獲得更多的提示資訊
[root@secDB1 SRC]# rsync -h
……此處內容省略……
11.小結
rsync在給我們傳輸檔案提供另外一種途徑的同時,也提高了我們的工作效率。在存在少量差異需要完成檔案同步的場合下是不二選擇。善用之。
Good luck.
secooler
10.02.21
-- The End --
rsync是檔案傳輸程式,它的功能和演算法描述可以參考維基百科中的介紹。
參考連結:
我來透過實驗給大家展示一下rsync命令的常用方法。
這裡我們演示使用的作業系統是Linux,rsync已經預裝好。如果是AIX作業系統,需要單獨在IBM網站下載安裝包安裝。
演示場景:將secDB1伺服器SRC目錄下的內容同步傳輸到secDB2伺服器DEST目錄下,整個過程在secDB1伺服器上來完成。
1.在第一臺主機的根目錄下建立一個名為“SRC”的目錄,作為我們傳輸演示的源目錄。
[root@secDB1 /]# mkdir /SRC
2.在SRC目錄中建立兩個檔案f1和f2
[root@secDB1 /]# cd /SRC
[root@secDB1 SRC]# touch f1
[root@secDB1 SRC]# touch f2
[root@secDB1 SRC]# ls -ltr
total 0
-rw-r--r-- 1 root root 0 Feb 21 10:37 f1
-rw-r--r-- 1 root root 0 Feb 21 10:37 f2
3.在第二臺主機的根目錄下建立一個名為“DEST”的目錄,作為我們傳輸演示的目標目錄
[root@secDB2 /]# cd /
[root@secDB2 /]# mkdir /DEST
4.將secDB1伺服器SRC目錄下的內容同步傳輸到secDB2伺服器DEST目錄下
[root@secDB1 SRC]# rsync -av /SRC/ -e ssh root@172.17.193.211:/DEST
root@172.17.193.211's password:
building file list ... done
./
f1
f2
sent 162 bytes received 70 bytes 42.18 bytes/sec
total size is 0 speedup is 0.00
5.驗證第二臺主機的DEST目錄下是否有傳送過來的檔案
[root@secDB2 /]# cd /DEST
[root@secDB2 DEST]# ls -ltr
total 0
-rw-r--r-- 1 root root 0 Feb 21 02:37 f1
-rw-r--r-- 1 root root 0 Feb 21 02:37 f2
檔案傳送成功,目的達到。
6.修改DEST目錄下的f1檔案內容,使之與源目錄SRC中的f1目錄不相同
[root@secDB2 DEST]# echo "mod" > f1
[root@secDB2 DEST]# cat f1
mod
[root@secDB2 DEST]# ls -ltr
total 4
-rw-r--r-- 1 root root 0 Feb 21 02:37 f2
-rw-r--r-- 1 root root 4 Feb 21 02:59 f1
7.再次將SRC目錄下的內容向DEST目錄同步
[root@secDB1 SRC]# rsync -av /SRC/ -e ssh root@172.17.193.211:/DEST
root@172.17.193.211's password:
building file list ... done
f1
sent 114 bytes received 48 bytes 46.29 bytes/sec
total size is 0 speedup is 0.00
注意,此時僅僅將有變化的內容f1同步到了DEST目錄,這也是rsync命令的優勢所在。
8.在經過再次同步之後,此時DEST目錄下的檔案再一次與SRC目錄下的內容保持一致。
[root@secDB2 DEST]# ls -ltr
total 0
-rw-r--r-- 1 root root 0 Feb 21 02:37 f1
-rw-r--r-- 1 root root 0 Feb 21 02:37 f2
9.注意“/”符號帶來的差別
如果將“/SRC/”後面的“/”去掉,此時將會將SRC目錄和目錄的下的所有內容統統的傳送到DEST目錄下。
[root@secDB1 SRC]# rsync -av /SRC -e ssh root@172.17.193.211:/DEST
root@172.17.193.211's password:
building file list ... done
SRC/
SRC/f1
SRC/f2
sent 166 bytes received 70 bytes 67.43 bytes/sec
total size is 0 speedup is 0.00
10.使用rsync命令的聯機幫助文件可以獲得更多的提示資訊
[root@secDB1 SRC]# rsync -h
……此處內容省略……
11.小結
rsync在給我們傳輸檔案提供另外一種途徑的同時,也提高了我們的工作效率。在存在少量差異需要完成檔案同步的場合下是不二選擇。善用之。
Good luck.
secooler
10.02.21
-- The End --
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-627423/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- rsync udr——遠端大檔案傳輸加速
- rsync命令快速刪大檔案
- 如何使用 rsync 透過 SSH 恢復部分傳輸的檔案
- 基於rsync實現海量檔案高速傳輸的解決方案
- Linux命令---rsyncLinux
- 檔案伺服器rsync伺服器
- rsync 命令及其示例
- Linux 檔案同步工具之 rsyncLinux
- rsync 使用示例
- linux 利用rsync實現檔案增量同步Linux
- rsync同步和備份檔案到本地
- rsync
- 使用 rsync 複製大檔案的一些誤解
- 使用rsync批次部署🥑
- CentOS7 下使用 rsync+sersync 配置檔案自動同步CentOS
- 慎用rsync
- 【Linux】Rsync的剖析與使用Linux
- scp實現斷點續傳---rsync斷點
- 為企業解決跨國檔案傳輸,提高工作效率!
- Rsync安全配置
- rsync 用法教程
- scp使用者遷移rsync
- 使用rsync同步網路備份
- 檔案共享服務之實時備份(inotify+rsync)
- wtfpd檔案傳輸使用
- Linux rsync配置用於伺服器之間傳輸大量的資料Linux伺服器
- rsync 同步目錄
- rsync 故障排查整理
- rsync實時同步
- 資料同步rsync
- Rsync資料同步
- rsync遠端同步
- rsync檔案同步工具常見模式有哪些?linux運維學模式Linux運維
- rsync客戶端一鍵安裝rsync指令碼(原始碼)客戶端指令碼原始碼
- 【多檔案自平衡雲傳輸】使用展示 —— 檔案傳輸系統
- 完全解析Rsync命令的17個備份選項
- 把Oracle的命令輸出傳送到檔案的命令Oracle
- Rsync服務詳解
- Rsync 資料備份