平常操作在monitor1上做,但monitor2上的数据也要随时更新,但间隔大点是没关系的脚本要求是即要本地备份,也要远程备份,同时做到monitor2的数据更新部分数据扔storage。以下是Nagios mysql备份的详细脚本代码
Nagios mysql备份脚本如下:
#!/bin/bash
date=`date +%Y%m%d_%H%M`
BACK_PATH=/opt/data/var/nagios_bak
FILE1=nagios_etc_$date.tar.gz
FILE2=mysql_bakcup_$date.sql
tar -czf $BACK_PATH/$FILE1 /opt/nagios/etc 1>/dev/null 2>/dev/null
cp $BACK_PATH/$FILE1 /data/var/.
mysqldump -uroot -ppasswd db >/data/var/$FILE2
scp $BACK_PATH/$FILE1 monitor2:/opt/data/var/nagios_bak/. 1>/dev/null 2>/dev/null
ssh monitor2 "rm -rf /usr/local/nagios/etc/" 1>/dev/null 2>/dev/null
scp -rp /usr/local/nagios/etc monitor2:/usr/local/nagios/. 1>/dev/null 2>/dev/null
ssh monitor2 "chown -R admin.admin /usr/local/nagios/etc/;/etc/init.d/nagios restart" 1>/dev/null 2>/dev/null
Nagios mysql备份完之后把脚本写入crontab
加一句
1 */2 * * * /home/admin/bin/backup_nagios.sh
整个Nagios mysql备份就完成了
【编辑推荐】