server-scripts/backup-mysql

21 lines
658 B
Plaintext
Raw Permalink Normal View History

#!/usr/bin/env bash
2014-10-19 15:27:33 +00:00
# TARGET: Backup-Ziel
# IGNORE: Liste zu ignorierender Datenbanken (durch | getrennt)
IGNORE="mysql|information_schema|performance_schema|test"
2018-09-13 07:43:21 +00:00
PASSWORD="$(cat /etc/nixos/secrets/mysql-password)"
2014-10-19 15:27:33 +00:00
2018-09-13 07:43:21 +00:00
set -eu -o pipefail
export PATH="/usr/bin/:$PATH"
DBS="$(lxc-attach -n mysql -- mysql --host="mysql" --user="root" --password="$PASSWORD" -Bse 'show databases' | grep -Ev $IGNORE)"
2014-10-19 15:27:33 +00:00
rm -f *.sql.bz2
for DB in $DBS; do
2018-09-13 07:43:21 +00:00
lxc-attach -n mysql -- mysqldump --host="localhost" --user="root" --password="$PASSWORD" --skip-extended-insert --skip-comments "$DB" | bzip2 -c > "$DB.sql.bz2"
2014-10-19 15:27:33 +00:00
done
echo "$0 - Backup erfolgreich durchgefuehrt"
exit 0