scripts/dump_mysql.sh

31 lines
1,011 B
Bash
Raw Normal View History

2014-09-14 00:40:55 +02:00
#!/bin/sh
BACKUPDIR=/home/mysql_backup
LOGFILE=${BACKUPDIR}/my_dump_mysql.log
2014-09-14 00:44:42 +02:00
SENDNSCA=/usr/local/sbin/send_nsca\ -H\ <nagios_host>\ -d\ ';;'\ -c\ /usr/local/etc/nagios/send_nsca.cfg
2014-09-14 00:40:55 +02:00
HOSTNAME=`/bin/hostname -f | /usr/bin/cut -d '.' -f 1,2`
backup_success=1
mkdir -p ${BACKUPDIR}
rm -f ${LOGFILE};
for i in `echo 'show databases;' | mysql | grep -v Database`;
do
echo -n " ---> backuping ${i}..." >> ${LOGFILE}
mysqldump --add-drop-table --add-locks --create-options --disable-keys --extended-insert --single-transaction\
--databases --lock-tables --quick --set-charset $i > ${BACKUPDIR}/$i.sql 2>> ${LOGFILE};
if [ $? -eq 0 ];
then
echo " OK" >> ${LOGFILE};
else
backup_success=0
fi
done
if [ $backup_success -eq 1 ]
then
echo "${HOSTNAME};;mysql_backups;;0;OK - backup succeeded at `date`" | ${SENDNSCA} >/dev/null
else
echo "${HOSTNAME};;mysql_backups;;2;CRITICAL - backup failed at `date`, please check ${LOGFILE} for complete report." | ${SENDNSCA} >/dev/null
fi