一,Linux下Rsync設置
主服務端:192.168.1.1 (linux)
1.安裝Rsync服務端
Rpm –ivh rsync-2.6.8-3.1.rpm
2.修改rsync文件
Vi /etc/xined.d/rsync
service rsync
{
disable = no //需要修改的地方
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
3.添加配置文件rsyncd.conf
[root@server ~]# more /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = no
max connections = 8
syslog facility = local5
pid file = /var/run/rsyncd.pid
hosts deny = 0.0.0.0/0.0.0.0
[ETC] //模塊名稱
hosts allow = 192.168.1.68 192.168.1.67 //設置訪問權限
uid = root
gid = root
path = /backup/etc //模塊實際路徑
4.啟動Rsync服務
/etc/init.d/xinetd start
備份服務端:192.168.1.68(Linux)
1.編寫備份腳本
backup_etc 腳本如下:
#!/bin/bash
PATH="/bin:/usr/bin:/sbin"
ADMIN_USER="it_backup"
NOW=`date +%Y%m%d%t%T`
BACKUP_DATE="`date +%Y%m%d` - `date +%a`"
CURRENT_TIME=`date +%F-%H%M%S`
#TARGET_DOW=`date +%w`
TMP_LOG_FILE="/var/log/.backup_daily-${CURRENT_TIME}.log"
LOG_FILE="/var/log/backup_daily.log"
OPT=""
echo "" > $TMP_LOG_FILE
echo "===================================================================" >> $TMP_LOG_FILE
echo "Bash Script: " ${0} >> $TMP_LOG_FILE
echo "Host.......: " ${HOSTNAME} >> $TMP_LOG_FILE
SOURCE_DIR="rsync://192.168.1.1/ETC/" //源路徑
TARGET_DIR="${1}/etc/" //目的路徑
echo "Source Dir.: " ${SOURCE_DIR} >> $TMP_LOG_FILE
echo "Target Dir.: " ${TARGET_DIR} >> $TMP_LOG_FILE
echo "" >> $TMP_LOG_FILE
until rsync -avr --delete $OPT $SOURCE_DIR $TARGET_DIR >> $TMP_LOG_FILE
do
echo "Another Try: `date +%Y%m%d%t%T`" >> $TMP_LOG_FILE
sleep 1m
done
echo "" >> $TMP_LOG_FILE
echo "Start......: ${NOW}" >> $TMP_LOG_FILE
echo "End........: `date +%Y%m%d%t%T`" >> $TMP_LOG_FILE
echo "===================================================================" >> $TMP_LOG_FILE
mail -s "$0 - ${HOSTNAME} - ${BACKUP_DATE}" $ADMIN_USER < $TMP_LOG_FILE
#--- accumulate the log file
cat $LOG_FILE >> $TMP_LOG_FILE
cp -f $TMP_LOG_FILE $LOG_FILE && rm -f $TMP_LOG_FILE
2.添加任務計劃
#source: etc (192.168.1.1 /etc)
00 23 * * * /usr/local/script/backup_etc /backup02/ > /dev/null
二,Windows下Rsync設置
主服務端:192.168.1.15(windows xp)
1.安裝cwRsyncServer
2.配置rsyncd.conf
uid = 0
gid = 0
use chroot = false
strict modes = false
hosts allow = 192.168.1.68 //設置訪問權限
log file = rsyncd.log
# Module definitions
# Remember cygwin naming conventions : c:/work becomes /cygwin/c/work
#
[BAK]
path = /cygdrive/d/BakACM/BAK
read only = true
transfer logging = yes
備份服務器:192.168.1.68(linux)
同上,編寫執行計劃腳本,並修改相應源路徑和目的路徑即可。