2024-03-23 16:06:28 +11:00
#!/bin/sh
status=$(/sbin/e-smith/config getprop mariadb status)
fixtables=$(/sbin/e-smith/config getprop mariadb autofixtables || echo "disabled")
if [ "$fixtables" = "enabled" ]; then
/sbin/e-smith/config delprop mariadb failsbackup
fi
failsbackup=$(/sbin/e-smith/config getprop mariadb failsbackup || echo "disabled")
onfailure () {
db=$1
message=""
if [ "$failsbackup" = "enabled" ]; then
exit 1;
message="There was an error trying to dump database $db, please fix this db. We stop there without backups."
echo $message
echo $message | /usr/bin/mail -s "error on backup of $db MariaDB database" admin
fi
message="$message \nThere was an error trying to dump database $db, please check for table errors in this db. Forcing a backup of the corrupted DB."
2025-04-20 00:53:33 -04:00
mariadb-dump --force --ignore-table=mysql.event --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mysql/"$db"-failed.dump || message="$message \nFailed to force backup of corrupted db $db as $db-failed.dump" >&2
2024-03-23 16:06:28 +11:00
if [ "$fixtables" = "enabled" ]; then
repair="failure"
message="$message \nTrying to auto-repair the db and do a backup after..."
2025-04-20 00:53:33 -04:00
mariadb-check -s --auto-repair -c "$db" && \
mariadb-dump --ignore-table=mysql.event --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mysql/"$db".dump && repair="success"
2024-03-23 16:06:28 +11:00
message="$message \n => $repair"
fi
echo $message
echo $message | /usr/bin/mail -s "error on backup of $db MariaDB database" admin
}
if [ "$status" = "disabled" ]
then
echo "mysqld is disabled - no tables dumped" >&2
exit 0
fi
for db in $(mysql -BNre "show databases;"|egrep -vi "^information_schema$|^performance_schema$")
do
2025-04-20 00:53:33 -04:00
mariadb-dump --ignore-table=mysql.event --single-transaction --add-drop-table -QB "$db" -r /home/e-smith/db/mysql/"$db".dump || onfailure $db
2024-03-23 16:06:28 +11:00
done
2025-04-20 00:53:33 -04:00
# double usage as already in mysql.dump
2024-04-06 15:30:15 -04:00
# dump user privileges
2025-04-20 00:53:33 -04:00
#mariadb-dump --system=users --insert-ignore > /home/e-smith/db/mysql/mysql.privileges.dump
2024-04-06 15:30:15 -04:00
# dump plugins
2025-04-20 00:53:33 -04:00
#mariadb-dump --system=plugins --insert-ignore > /home/e-smith/db/mysql/mysql.plugins.dump
2024-04-06 15:30:15 -04:00
# dump udfs
2025-04-20 00:53:33 -04:00
#mariadb-dump --system=udfs --insert-ignore > /home/e-smith/db/mysql/mysql.udfs.dump
2024-04-06 15:30:15 -04:00
# dump servers
2025-04-20 00:53:33 -04:00
#mariadb-dump --system=servers --insert-ignore > /home/e-smith/db/mysql/mysql.servers.dump
2024-04-06 15:30:15 -04:00
# dump stats
2025-04-20 00:53:33 -04:00
#mariadb-dump --system=stats --insert-ignore > /home/e-smith/db/mysql/mysql.stats.dump
2024-04-06 15:30:15 -04:00
# dump timezones
2025-04-20 00:53:33 -04:00
#mariadb-dump --system=timezones --insert-ignore > /home/e-smith/db/mysql/mysql.timezones.dump