Created
January 9, 2017 23:28
-
-
Save Mic92/3e36f4d3f6a5869023073821cb015b69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# TARGET: Backup-Ziel | |
# IGNORE: Liste zu ignorierender Datenbanken (durch | getrennt) | |
IGNORE="mysql|information_schema|performance_schema|test" | |
PASSWORD="<root-password>" | |
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)" | |
rm -f *.sql.bz2 | |
for DB in $DBS; do | |
lxc-attach -n mysql -- mysqldump --host="localhost" --user="root" --password="$PASSWORD" --skip-extended-insert --skip-comments "$DB" | bzip2 -c > "$DB.sql.bz2" | |
done | |
echo "$0 - Backup erfolgreich durchgefuehrt" | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu -o pipefail | |
# restore: | |
# psql -f $database.dump postgres | |
export PATH="/usr/bin/:$PATH" | |
LIST=$(lxc-attach -n postgres -- psql -h postgres -U postgres -At -c "select datname from pg_database order by datname;") | |
for d in $LIST; do | |
[ "$d" == "template0" ] && continue | |
lxc-attach -n postgres -- pg_dump -h postgres -U postgres "$d" | gzip -c > "$d.dump.gz" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment