脚本

循环rsync备份目录,检查有无以当天命名的文件,有即备份成功,写入日志,没有即失败写入日志,每天把日志发送给管理员

date=`date -d -1day +%F`
dir=`ls /log-backup|egrep -v '172.17.2.10'`
for i in $dir
do
  if [ ! -f /log-backup/$i/${i}_$date.tar.gz ]
   then
    echo "${i}_$date数据备份失败" >> /home/mail-logs/${date}.log 
   else
    echo "${i}_$date数据备份成功" >> /home/mail-logs/${date}.log
  fi
done
cat /home/mail-logs/${date}.log | mail -s '每日wordpress服务器备份结果' huangyingmao@strongfood.com.cn
find /home/mail-logs -name *.log -mtime +10|xargs rm -rf

 

date=`date -d -1day +%F`
dir=`ls /log-backup/172.17.2.10/`
for i in $dir
do
  if [ ! -f /log-backup/172.17.2.10/$i/172.17.2.10_$date.tar.gz ]
   then
    echo "172.17.2.10_${date}_$i数据备份失败" >> /home/mail-logs/web/${date}.log 
   else
    echo "172.17.2.10_${date}_$i数据备份成功" >> /home/mail-logs/web/${date}.log
  fi
done
cat /home/mail-logs/web/${date}.log | mail -s '每日官网服务器备份结果' huangyingmao@strongfood.com.cn \
&&cat /home/mail-logs/web/${date}.log | mail -s '每日官网服务器备份结果' zhye@strongfood.com.cn

 

rsync启动脚本

#!/bin/bash
#chkconfig 3 100 100
#description:rsync-self
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
pid=/var/run/rsyncd.pid
function check(){
if [ "$1" = "start" -o "$1" = "stop" -o "$1" = "restart" ]
 then
   continue
 else
   echo "usage:start|stop|restart"
fi
}
function fuwu(){ case $1 in
  start)
     if [ -f $pid ]
      then
        echo "服务是启动状态!"
        action "rsync" /bin/true
      else
        /usr/bin/rsync --daemon  
        action "开启rsync" /bin/true       
      fi
;;
  stop)
      if [ -f $pid ]
        then
         /usr/bin/pkill rsync
         action "关闭rsync" /bin/true
        else
         echo "服务没启动!"
        fi
;;
  restart)
      if [ -f $pid ]
       then
         /usr/bin/pkill rsync&&/usr/bin/rsync --daemon
         action "关闭rsync" /bin/true
         action "开启rsync" /bin/true
       else
         /usr/bin/rsync --daemon
         action "开启rsync" /bin/true
       fi
;;
   *)
     check $1
esac
}
function main() {
    fuwu $1
}
main $1

posted on 2019-07-17 13:59  一直用这名字  阅读(234)  评论(0编辑  收藏  举报

导航