文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>在這裡使用 rsync 這個套件 來作兩台電腦的資料備份

在這裡使用 rsync 這個套件 來作兩台電腦的資料備份

时间:2006-04-28  来源:snowtty

環境說明 

server (需要備份的主機.目前運作中的機器) :
O/S:Redhat 9.0
ip : 192.168.0.2
user : root
欲備份目錄 : /test (實驗用.預設沒有此目錄請自行建立)

client (遠端存放備份的機器.不提供服務只備份資料) :
O/S:Redhat 9.0
ip : 192.168.0.253
user : root
存放資料目錄 : /test (實驗用.預設沒有此目錄請自行建立)

分兩個部分來做

server 部分:

1.首先檢查有沒有rsync 套件 (Redhat 預設都會裝)
#rpm -q rsync
rsync-2.5.5-4

2.開啟rsync的服務並檢查狀態
#chkconfig rsync on
#chkconfig rsync --list
rsync 開啟

client 部分:
為了使用SSH加密傳輸且不需要輸入密碼

1.#cd /root/.ssh (進入到/root/.ssh/ 目錄下)
2.#ssh-keygen -d (產生ssh的公鑰和私鑰)
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): (產生到何處.按Enter 就可以了)
Enter passphrase (empty for no passphrase): (要不要設定passwd.避免問我們按Enter 就可以了)
Enter same passphrase again: (再按一次Enter)
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.

此時目錄下會產生公鑰id_dsa.pub和私鑰id_dsa
現在要把id_dsa.pub丟到192.168.0.2 並且更名為 authorized_keys

3.#scp id_dsa.pub 192.168.0.2:/root/.ssh/authorized_keys
[email protected]'s password:
id_dsa.pub 100% |*****************************| 613 00:00

試試看 ssh 到server 應該就不用輸入密碼了
4.#ssh 192.168.0.2
#exit (記得離開)
5.#cd /usr/local/bin (要寫一個shell script 在 /usr/local/bin下 故先到此目錄下)
#vi sync
rsync -avlR --delete -e ssh 192.168.0.2:/test /
(把192.168.0.2下面的 /test 目錄 備份到本機上的 / , 因為備份會產生test這個資料夾.所以本機上設定為/)
(讓/test => /test 而不是 /test => /test/test)
參數意義如下﹕

-a, --archive
It is a quick way of saying you want recursion and want to preserve almost everything.
-v, --verbose
This option increases the amount of information you are given during the transfer.
-l, --links
When symlinks are encountered, recreate the symlink on the destination.
-R, --relative
Use relative paths. 保留相對路徑...才不會讓子目錄跟 parent 擠在同一層...
--delete
是指如果Server端刪除了一文件,那客戶端也相應把這一文件刪除,保持真正的一致。
-e ssh
建立起加密的連接。
6.#chmod 700 sync 只讓root 可以使用
7.#./sync (執行sync這個script.........此時你就會發現兩台電腦的/test是同步的呢^_^)

參考文件
小弟的心得是參考以下的文件來製作

http://www.adj.idv.tw/server/linux_rsync.php
http://www.fanqiang.com/a6/b7/20010908/1305001258_b.html
http://phorum.study-area.org/viewtopic.php?t=15553&highlight=rsync
http://linux.tnc.edu.tw/techdoc/rsync.htm
相关阅读 更多 +
排行榜 更多 +
浴血混战官方下载

浴血混战官方下载

飞行射击 下载
检票员模拟器免广告下载

检票员模拟器免广告下载

模拟经营 下载
最终前哨最终版手机版下载

最终前哨最终版手机版下载

休闲益智 下载