Rsync 是本地及遠端目錄的鏡像備份工具, 在傳輸檔案時, 會比對要備份的目錄及儲存備份的目錄, 只會複製兩者有差異的檔案。以下會介紹用 Rsync 在本機及遠端備份的方法:
首先要安裝 Rsync, 在 RHEL / CentOS 安裝執行以下指令:
# yum install rsync
本機備份:
在本機用 rsync 備份與 cp 差不多:
rsync -avP –delete /home/phpini /backup/
會將 /home/phpini 備份到 /backup/phpini, 但要留意斜線, 如果改成 /home/phpini/, 備份位置會有所不同:
rsync -avP –delete /home/phpini/ /backup/
上面指令會將 /home/phpini/ 目錄下所有檔案, 備份到 /backup/ 下面。
遠端備份:
要做遠端備份, 需要在儲存備份的伺服器上設定及開啟 Rsync 服務, 首先設定 /etc/rsync.conf 檔案, 加入以下內容:
uid = root
gid = wheel
use chroot = true
timeout = 600000
max connections = 400
log file = /var/log/rsyncd.log
gid = wheel
use chroot = true
timeout = 600000
max connections = 400
log file = /var/log/rsyncd.log
[server01]
path = /backup/server01
comment = server01
read only = false
hosts allow = 192.168.1.100
上面設定檔指定只允許 192.168.1.100 連線, 並設定儲存目錄為 /backup/server01, 然後在 192.168.1.100, 然後設定自動開始 rsync, 建立 /etc/xinetd.d/rsync 檔案, 並加入以下內容:
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no # change
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = –daemon
log_on_failure += USERID
}
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no # change
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = –daemon
log_on_failure += USERID
}
然後啟動 xinetd:
# /etc/rc.d/init.d/xinetd start
# chkconfig xinetd on
# chkconfig xinetd on
要備份的伺服器上面可以輸入以下指令進行鏡像備份:
/usr/bin/rsync -avzrpog –delete –force /home/phpini backup_ip::server01 –links
上面指令會將 /home/phpini 備份到 backup_ip 伺服器。