2014-09-14 00:40:55 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2023-08-10 21:47:21 +02:00
|
|
|
BACKUPDIR=/home/backups/mysql
|
2014-09-14 00:40:55 +02:00
|
|
|
LOGFILE=${BACKUPDIR}/my_dump_mysql.log
|
2023-08-10 21:47:21 +02:00
|
|
|
SENDZABBIX="zabbix_sender --config /usr/local/etc/zabbix6/zabbix_agentd.conf --key mysql.backups"
|
|
|
|
HOSTNAME=$(hostname -f | cut -d '.' -f 1,2)
|
2014-09-14 00:40:55 +02:00
|
|
|
backup_success=1
|
|
|
|
|
|
|
|
mkdir -p ${BACKUPDIR}
|
|
|
|
rm -f ${LOGFILE};
|
|
|
|
|
2023-08-10 21:47:21 +02:00
|
|
|
for i in $(mysql --skip-column-names --silent --raw --execute 'show databases;' | grep --invert-match Database);
|
2014-09-14 00:40:55 +02:00
|
|
|
do
|
2023-08-10 21:47:21 +02:00
|
|
|
printf " ---> backing up %s..." "$i" >> ${LOGFILE}
|
2014-09-14 00:40:55 +02:00
|
|
|
mysqldump --add-drop-table --add-locks --create-options --disable-keys --extended-insert --single-transaction\
|
2023-08-10 21:47:21 +02:00
|
|
|
--databases --lock-tables --quick --set-charset "$i" | lbzip2 > "$BACKUPDIR/$i.sql.bz2" 2>> ${LOGFILE};
|
|
|
|
if [ $? ];
|
2014-09-14 00:40:55 +02:00
|
|
|
then
|
|
|
|
echo " OK" >> ${LOGFILE};
|
|
|
|
else
|
|
|
|
backup_success=0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $backup_success -eq 1 ]
|
|
|
|
then
|
2023-08-10 21:47:21 +02:00
|
|
|
${SENDZABBIX} --value 0 >/dev/null
|
2014-09-14 00:40:55 +02:00
|
|
|
else
|
2023-08-10 21:47:21 +02:00
|
|
|
${SENDZABBIX} --value 1 >/dev/null
|
2014-09-14 00:40:55 +02:00
|
|
|
fi
|