rsync方式同步数据

转CU上的chenl

一、功能:
在使用dd镜像服务器上的两块SCSI硬盘之后,使用rsync方式同步数据;使用crond调度,采用差异备份方式,每日同步一次,保留一个月的增量数据。


二、说明:
1、rsyncd.conf配置文件说明
id = root
gid = root
# id,gid设置为root,可以对一些nobody没有权限读的文件/目录进行备份。
use chroot = no
max connections = 4
syslog facility = local5
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
lock file = /var/run/rsyncd.lock
#配置需要同步的FileSet
[etc]
path = /etc
comment = etc
auth users = backup
secrets file = /etc/rsyncd.secrets

[tomcat]
path = /usr/local/tomcat
comment = tomcat
auth users = backup
secrets file = /etc/rsyncd.secrets

[backup]
path = /backup
comment = backup
auth users = backup
secrets file = /etc/rsyncd.secrets

[cl]
path = /home/cl
comment = cl
auth users = backup
secrets file = /etc/rsyncd.secrets
2、rsyncd.secrets密码配置文件
backup:web_backup
#用户名为backup,密码为web_backup
#要设置此文件只有属主有权限访问

3、rsync.sh同步脚本
#!/bin/sh
#########################################################################
#
# File: rsync.sh
# Description: backup data with rsyncd.
# Language: GNU Bourne-Again SHell
# Version: 2.0
# Date: 2006-5-15
# Corp.: Chenlei
# Author: chnl@163.com
# Version 2.0: This Edition use rsync.conf file to get the directory.
# First Edition Info:
# cl, 2004.11.11
# This script gets files from server to local directory to backup.
# It's a month rotating incremental backup.
#
#########################################################################

############################
#
# Exit values:
# ------------
# 0 successful
# Others failur
#
# ----------------------------------------------------------------------
# Args:
# 1. Config File
#

[ -f /etc/profile ] && . /etc/profile
LogDir=/var/log
Prog=/usr/bin/rsync

#解析配置文件中的FileSet及DirName
while read Record
do
FileSet=$(echo $Record|grep -v ^#|grep -v ^$| awk -F"|" '{print $1}')
DirName=$(echo $Record|grep -v ^#|grep -v ^$|awk -F"|" '{print $2}')

Date=`date +%d`
FileDir=/backup/$DirName
[ -d $BakDir ] || mkdir -p $FileDir
BakDir=/backup/$DirName/rotating_bak/$Date
LogFile=$LogDir/rsync.$FileSet.log
[ -d $BakDir ] && rm -fr $BakDir
# 设定rsync备份时所使用的参数选项,采用压缩及backup参数
OPTS="--force --ignore-errors --delete --backup --backup-dir=$BakDir -az"
SERVER="backup@127.0.0.1"
export RSYNC_PASSWORD=web_backup
#产生时间戳日志到日志文件
echo "############" >>$LogFile 2>&1
echo "Begin Time: `date`" >>$LogFile 2>&1
$Prog $OPTS $SERVER:shy.gifFileSet $FileDir >>$LogFile 2>&1
echo "End Time: `date`" >>$LogFile 2>&1
echo "############" >>$LogFile 2>&1
done < $1

4、rsync.sh同步脚本
#FileSet及Directory设置
etc|/etc
tomcat|/usr/local/tomcat
cl|/home/cl
附录:
文档:
rsyncd.conf
rsyncd.secrets
rsync.conf
rsync.sh

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/181629/viewspace-835911/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/181629/viewspace-835911/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值