Browse Source

mandatory mysql dump script

master
n 5 years ago
parent
commit
19eff5ecff
1 changed files with 30 additions and 0 deletions
  1. 30
    0
      dump_mysql.sh

+ 30
- 0
dump_mysql.sh View File

@@ -0,0 +1,30 @@
#!/bin/sh

BACKUPDIR=/home/mysql_backup
LOGFILE=${BACKUPDIR}/my_dump_mysql.log
SENDNSCA=/usr/local/sbin/send_nsca\ -H\ 192.168.X.X\ -d\ ';;'\ -c\ /usr/local/etc/nagios/send_nsca.cfg
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

Loading…
Cancel
Save