[root@linux-node2 scripts]# vi backup.sh
#!/bin/shIP="`ifconfig eth0|awk -F '[ :]+' 'NR==2 {print $4}'`"Path=/backup/$IP[ ! -d $Path ] && mkdir $Path -pcd $Path#backuptar zcPf $Path/www_$(date +%F).tar.gz /var/html/www/ &&\tar zcPf $Path/conf_$(date +%F).tar.gz /var/spool/cron/root /etc/rc.d/rc.local /etc/sysconfig/iptables /server/scripts &&\tar zcPf $Path/logs_$(date +%F).tar.gz /app/logs/ &&\find /backup/ -type f -name "*$(date +%F).tar.gz"|xargs md5sum >>/$Path/flag_$(date +%F)#to bakup serverrsync -az /backup/ rsync_backup@10.89.7.9::backup --password-file=/etc/rsync.password#delfind $Path -type f -name "*.tar.gz" -mtime +7|xargs rm -f
#################################################
[root@backup backup]# ll
total 4drwxr-xr-x 2 rsync rsync 4096 Aug 29 13:43 10.89.7.10[root@backup backup]# cd 10.89.7.10/[root@backup 10.89.7.10]# lltotal 16-rw-r--r-- 1 rsync rsync 934 Aug 29 13:43 conf_2018-08-29.tar.gz-rw-r--r-- 1 rsync rsync 227 Aug 29 13:43 flag_2018-08-29-rw-r--r-- 1 rsync rsync 115 Aug 29 13:43 logs_2018-08-29.tar.gz-rw-r--r-- 1 rsync rsync 118 Aug 29 13:43 www_2018-08-29.tar.gz[root@backup 10.89.7.10]# cat flag_2018-08-29 da2845ff1010e2ac01cf216929034558 /backup/10.89.7.10/www_2018-08-29.tar.gz22610f1441a524aa056e824f3dbf624d /backup/10.89.7.10/conf_2018-08-29.tar.gz7742644088b57b69b396d0025f835097 /backup/10.89.7.10/logs_2018-08-29.tar.gz[root@backup 10.89.7.10]##通过md5sum检查,如果没有问题都是“OK”
[root@backup 10.89.7.10]# md5sum -c flag_2018-08-29
/backup/10.89.7.10/www_2018-08-29.tar.gz: OK/backup/10.89.7.10/conf_2018-08-29.tar.gz: OK/backup/10.89.7.10/logs_2018-08-29.tar.gz: OK#模拟问题
[root@backup 10.89.7.10]# echo 111 >logs_2018-08-29.tar.gz
[root@backup 10.89.7.10]# md5sum -c flag_2018-08-29 |grep FAILEDmd5sum: WARNING: 1 of 3 computed checksums did NOT match/backup/10.89.7.10/logs_2018-08-29.tar.gz: FAILED#检查脚本:
[root@backup scripts]# cat chkbak.sh
#! /bin/sh/bin/find /backup -type f -name "flag_$(date +%F)"|xargs md5sum -c |grep FAILED >/opt/mail_body_$(date +%F).txtmail -s "$(date +%U%T) back" 123456379@qq.com
#启动邮件服务
[root@backup scripts]# yum install sendmail -y
[root@backup scripts]# /etc/init.d/sendmail start
Starting sendmail: [ OK ]Starting sm-client: [ OK ][root@linux-node2 scripts]##执行脚本,查看邮件
[root@backup scripts]# sh chkbak.sh
md5sum: WARNING: 1 of 3 computed checksums did NOT match