【脚本】中备中控同步机制
时间:2015-09-11 12:09:22 作者:vaster 标签: Linux 工作总结 分类: Linux 工作总结
通常情况下,我们会为同一项目准备两个中控,一主一备,以下是为主备中控做数据备份的一个方法。此处仅包含用户常用的文件,不包含系统重要文件
1. 备中控部署rsync服务
#cat /etc/rsync_ccs_backup.conf pid file = /var/run/rsyncd.pid port=873 address = 10.10.10.20 uid = root gid = root use chroot = no read only = no hosts allow = 10.10.10.10 hosts deny = * [iplist] path = /home [user1] path = /home/user1 [user2] path = /home/user2 [root] path = /root
PS:主中控IP10.10.10.10,备中控IP10.10.10.20
2. 启动rsync服务(备中控)
/usr/bin/rsync --daemon --config=/etc/rsync_ccs_backup.conf --port=873
3. 主中控部署crontab
00 4 * * * /bin/bash /home/ccsbakup/backup.sh > /root/ccs-backup.log 2>&1
4. 同步脚本内容
# less /home/ccsbakup/backup.sh #!/bin/bash #For transfering important files to sccs, and getting ccs bakup files from sccs #trap trap 'echo exit...;exit 1' 2 15 #sccs -> second ccs wdir="/home/ccsbakup" sccs="10.10.10.20" date=$(date +%Y%m%d) yesterday=$(date -d "1 days ago" +%Y%m%d) account="user1 user2" #transfer important files for root #auvz -> rlptgoDuvz /usr/bin/rsync -rptgoDuvz --progress /home/{wind,*.lst} ${sccs}::iplist #transfer files for accounts for i in $account; do /usr/bin/rsync -rptgoDuvz --progress "/home/${i}/" --exclude=".ssh/*" ${sccs}::${i} done /usr/bin/rsync -rptgoDuvz --progress "/root" --exclude=".ssh/*" ${sccs}::root exit 0