當前位置:
首頁 > 知識 > Linux之rsync遠程同步

Linux之rsync遠程同步

rsync is a utility for efficiently transferring and synchronizing files across computer systems, by checking the timestamp and size of files.It is commonly found on Unix-like systems and functions as both a file synchronization and file transfer program. The rsync algorithm is a type of delta encoding, and is used for minimizing network usage. Zlib may be used for additional compression,and SSH or stunnel can be used for data security.

Rsync is typically used for synchronizing files and directories between two different systems. For example, if the command rsync local-file user@remote-host:remote-file is run, rsync will use SSH to connect as user to remote-host.Once connected, it will invoke the remote host"s rsync and then the two programs will determine what parts of the file need to be transferred over the connection.

Rsync can also operate in a daemon mode, serving files in the native rsync protocol (using the "rsync://" syntax).

rsync是類unix系統下的數據鏡像備份工具——remote sync。一款快速增量備份工具 Remote Sync,遠程同步 支持本地複製,或者與其他SSH、rsync主機同步。

rsync,remote synchronize顧名思意就知道它是一款實現遠程同步功能的軟體,它在同步文件的同時,可以保持原來文件的許可權、時間、軟硬鏈接等附加信息。 rsync是用 「rsync 演算法」提供了一個客戶機和遠程文件伺服器的文件同步的快速方法,而且可以通過ssh方式來傳輸文件,這樣其保密性也非常好,另外它還是免費的軟體。

rsync特性如下:

可以鏡像保存整個目錄樹和文件系統。

可以很容易做到保持原來文件的許可權、時間、軟硬鏈接等等。

無須特殊許可權即可安裝。

快速:第一次同步時 rsync 會複製全部內容,但在下一次只傳輸修改過的文件。rsync 在傳輸數據的過程中可以實行壓縮及解壓縮操作,因此可以使用更少的帶寬。

安全:可以使用scp、ssh等方式來傳輸文件,當然也可以通過直接的socket連接。

支持匿名傳輸,以方便進行網站鏡象。

rsync有六種不同的工作模式:

1)拷貝本地文件。當SRC和DES路徑信息都不包含有單個冒號":"分隔符時就啟動這種工作模式。如:rsync -a /data /backup

2)使用一個遠程shell程序(如rsh、ssh)來實現將本地機器的內容拷貝到遠程機器。當DST路徑地址包含單個冒號":"分隔符時啟動該模式。如:rsync -avz *.c foo:src

3)使用一個遠程shell程序(如rsh、ssh)來實現將遠程機器的內容拷貝到本地機器。當SRC地址路徑包含單個冒號":"分隔符時啟動該模式。如:rsync -avz foo:src/bar /data

4)從遠程rsync伺服器中拷貝文件到本地機。當SRC路徑信息包含"::"分隔符時啟動該模式。如:rsync -av root@192.168.78.192::www /databack

5)從本地機器拷貝文件到遠程rsync伺服器中。當DST路徑信息包含"::"分隔符時啟動該模式。如:rsync -av /databack root@192.168.78.192::www

6)列遠程機的文件列表。這類似於rsync傳輸,不過只要在命令中省略掉本地機信息即可。如:rsync -v rsync://192.168.78.192/www

rsync 命令來同步系統文件之前要先登錄remote 主機認證,認證過程中用到的協議有2種:ssh 協議和rsync協議

1. ssh 認證協議

rsync server 端不用啟動rsync的daemon進程,只要獲取remote host的用戶名和密碼就可以直接 rsync 同步文件

rsync server 端因為不用啟動daemon進程,所以也不用配置文件 /etc/rsyncd.conf

ssh 認證協議跟scp 的原理是一樣的,如果在同步過程中不需要收入密碼就 用 ssh-keygen -t rsa 打通通道

這種方式默認是省略了 -e ssh 的,與下面等價:

rsync -avz /SRC -e ssh root@172.17.256.211:/DEST #-a 文件宿主變化,時間戳不變 -z:壓縮數據傳輸

當遇到要修改埠的時候,我們可以:

rsync -avz /SRC -e "ssh -p36000" root@172.17.256.211:/DEST #修改了ssh 協議的埠,默認是22

2. rsync 認證協議

rsync 認證協議,需要在rsync server端啟動daemon進程,並設置對應的配置文件: /etc/rsyncd.conf

rysnc 認證協議

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 達人科技 的精彩文章:

並行模式庫PPL應用實戰(一):使用task類創建並行任務
EF Core學習Code First
多線程和非同步編程示例和實踐-踩過的坑
Java類的載入的一個小問題
ElasticSearch裡面一些小坑筆記

TAG:達人科技 |

您可能感興趣

Linux rsync同步文件腳本
Linux之crontab 使用
從Linux到Windows的PowerShell遠程處理
Linux之父Linus Torvalds,他回來啦
Linux系統安裝Oracle,配置etc/security/limits.conf文件
乾貨詳解 Linux phantomJs install course
Windows和Ubuntu系統如何遠程連接Linux伺服器
Linux/Windows等Chrome獲Material Design更新
Torvalds談Linux行為準則
科技圖鑑 Microsoft Loves Linux
Skype的Snap安裝包發布,Microsoft Loves Linux
Linux系統BillGates botnet component查殺
linux性能調試之iostat
Linux之父Linus Torvalds惡評Intel漏洞修復補丁:完全是個垃圾
Google決定用gLinux取代Goobuntu Linux操作系統
Linux cgroups 命令簡介
SUSE Linux Enterprise High Performance Computing公測啟動
Linux下如何實現與Internet時間同步
終極之戰:Linux&Windows
Linux使用ssh遠程登錄Ubuntu