rsync可以說是網管人員的命根子,如果再加上幾行簡單的shell_script指令,就幾乎可以操控所有套件之備份與還原了!再次從舊部落格移植文章過來!

 

 

 

 

 

 

我要 A (10.0.0.1) 要對 B (192.168.0.1) 做異地備援 ...所以我針對 A 讓它使用SSH連到 B 時...
不需要輸入密碼...User 是 Root...SSH Version2的版本..首先要先在A(10.0.0.1)產生public/private
dsa key pair..

步驟一:
[root@mondeo home]# cd /root/.ssh/
[root@mondeo .ssh]# ssh-keygen -d
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase): <-- 此處不打passphrase..下次才不會詢問password
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
11:22:33:44:55:66:77:88:99:00:11:22:33:44:55:66 root@mondeo.adj.idv.tw
[root@mondeo .ssh]#

這時會在系統下看到兩個檔案...id_dsa與id_dsa.pub 現在要把id_dsa.pub丟到192.168.0.1
並且更名為 authorized_keys2

步驟二:
[root@mondeo .ssh]# scp id_dsa.pub 192.168.0.1:/root/.ssh/authorized_keys2
root@192.168.0.1's password:
id_dsa.pub 100% |************************************************
***************************| 612 00:00
現在您可以執行ssh 192.168.0.1 看看能否登入而不需要輸入密碼...

步驟三:
首先要先對B(192.168.0.1)把Rsync的Server on起來...
[root@linux /]#chkconfig --list rsync
rsync off
[root@linux /]#chkconfig rsync on

步驟四:

現在我先在A(10.0.0.1)上建一個 Backup directory...然後對B(192.168.0.1)的mysql跟html
的目錄做異地備援...偶寫一個簡單的script如下:
[root@mondeo /]# mkdir backup
[root@mondeo backup]#vi sync

rsync -avlR --delete -e ssh 192.168.0.1:/var/lib/mysql /backup/
rsync -avlR --delete -e ssh 192.168.0.1:/var/www/html /backup

[root@mondeo backup]#
chmod 700 sync

p.s.

參數意義如下﹕

-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
建立起加密的連接。

 

 
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 bunkera 的頭像
    bunkera

    狂戀Linux

    bunkera 發表在 痞客邦 留言(0) 人氣()