expect与rsync 异步并行备份数据脚本 #!/bin/bash #author:qunying.liu #2014.08.02 #脚本用途:通过rsync从远程机器备份数据到本机机器对应目录 #脚本目录:/usr/local/scripts/,expect脚本目录:/usr/local/scripts/dsfilersync, #备注:一个机器对应一个exp脚本,该脚本中包含该机器所有rsync同步目录。 #初始化目录 cd /usr/local/scripts/ grep "rsync -avz" ./dsfilersync/*.exp|awk ‘{print $NF}‘ >backupdir.info for DIR in `cat ./backupdir.info`; do [ ! -d $DIR ] && mkdir -p $DIR && echo "Create Dir $DIR done !" ls -ld $DIR done #统计需要备份的机器IP到dataserver.ip文件中 grep "rsync -avz" ./dsfilersync/*.exp|awk -F@ ‘{print $2}‘|awk -F: ‘{print $1}‘|sort |uniq >./dsfilersync/dataserver.ip tmp_fifofile="/tmp/fifo.$$" ;mkfifo "$tmp_fifofile" ;exec 6<>"$tmp_fifofile" ;rm $tmp_fifofile #通过管道文件,让expect脚本异步执行。 for ip in `cat ./dsfilersync/dataserver.ip`;do { echo "$ip,Begin at `date +%Y-%m-%d-%H-%M-%S`...." #每天中午12点清空日志 if [ 12 -eq $(date +%H) ];then echo "">/data/scripts/logs/time$ip.log echo "">/data/scripts/logs/datarsync$ip.log fi flag="`/bin/ps -ef|grep $ip.exp|grep -v grep`" if [ -z "$flag" ];then echo "$ip:Begin at `date +%Y-%m-%d-%H-%M-%S`" >> ./logs/time$ip.log cd /data/scripts/ ( ./dsfilersync/$ip.exp 1> ./logs/datarsync$ip.log 2>&1 && echo "$ip:Finsh at `date +%Y-%m-%d-%H-%M-%S`" >> /data/applogs/time$ip.log ) || /usr/local/scripts/MonitorAgent -f monitor -t "data rsync file from $ip failed " -i " rsync file failed from $ip , please check /data/applogs/datarsync$ip.log " else echo "$ip: Already running...." fi } & done wait exec 6>&- echo "Finsh at `date +%Y-%m-%d-%H-%M`"
本文出自 “运维者说:从菜鸟到老鸟” 博客,请务必保留此出处http://liuqunying.blog.51cto.com/3984207/1538476
expect与rsync 异步并行备份数据脚本,布布扣,bubuko.com
原文:http://liuqunying.blog.51cto.com/3984207/1538476