scripts/dump_mysql.sh
2023-08-10 21:47:21 +02:00

30 lines
874 B
Bash
Executable file

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