various scripts for various tasks.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dump_mysql.sh 1011B

123456789101112131415161718192021222324252627282930
  1. #!/bin/sh
  2. BACKUPDIR=/home/mysql_backup
  3. LOGFILE=${BACKUPDIR}/my_dump_mysql.log
  4. SENDNSCA=/usr/local/sbin/send_nsca\ -H\ <nagios_host>\ -d\ ';;'\ -c\ /usr/local/etc/nagios/send_nsca.cfg
  5. HOSTNAME=`/bin/hostname -f | /usr/bin/cut -d '.' -f 1,2`
  6. backup_success=1
  7. mkdir -p ${BACKUPDIR}
  8. rm -f ${LOGFILE};
  9. for i in `echo 'show databases;' | mysql | grep -v Database`;
  10. do
  11. echo -n " ---> backuping ${i}..." >> ${LOGFILE}
  12. mysqldump --add-drop-table --add-locks --create-options --disable-keys --extended-insert --single-transaction\
  13. --databases --lock-tables --quick --set-charset $i > ${BACKUPDIR}/$i.sql 2>> ${LOGFILE};
  14. if [ $? -eq 0 ];
  15. then
  16. echo " OK" >> ${LOGFILE};
  17. else
  18. backup_success=0
  19. fi
  20. done
  21. if [ $backup_success -eq 1 ]
  22. then
  23. echo "${HOSTNAME};;mysql_backups;;0;OK - backup succeeded at `date`" | ${SENDNSCA} >/dev/null
  24. else
  25. echo "${HOSTNAME};;mysql_backups;;2;CRITICAL - backup failed at `date`, please check ${LOGFILE} for complete report." | ${SENDNSCA} >/dev/null
  26. fi