Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5239458
  • 博文数量: 1144
  • 博客积分: 11974
  • 博客等级: 上将
  • 技术积分: 12312
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-13 20:06
文章存档

2017年(2)

2016年(14)

2015年(10)

2014年(28)

2013年(23)

2012年(29)

2011年(53)

2010年(86)

2009年(83)

2008年(43)

2007年(153)

2006年(575)

2005年(45)

分类: LINUX

2006-04-28 13:45:46

環境說明 

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
'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是同步的呢^_^)


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




阅读(2783) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~