From 65fc408c43c60a9e9de0c512d0da9f57631b487e Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Tue, 17 Oct 2017 16:17:32 +0200 Subject: [PATCH] gzip mysql dump, cleanup --- db/backup.sh | 16 ++++++---------- db/restore.sh | 10 +++------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/db/backup.sh b/db/backup.sh index f06c870..3ea5327 100755 --- a/db/backup.sh +++ b/db/backup.sh @@ -1,19 +1,15 @@ #!/bin/bash # dump postgres or mysql functions of the database -export POSTGRES="$(dpkg --get-selections | grep postgres 2>&1)" -export MYSQL="$(dpkg --get-selections | grep mysql 2>&1)" +# export POSTGRES="$(dpkg --get-selections | grep postgres 2>&1)" +# export MYSQL="$(dpkg --get-selections | grep mysql 2>&1)" -if [ ! -z "$MYSQL" ]; - then +if [ ! -z "$MYSQL_PASSWORD" ]; then export MYSQL_PWD=$MYSQL_PASSWORD - mysqldump $MYSQL_DATABASE -hdb -u$MYSQL_USER > /srv/backup/mariadb.dump -elif [ ! -z "$POSTGRES" ]; - then - export PGUSER="postgres" + mysqldump $MYSQL_DATABASE -hdb -u$MYSQL_USER | gzip > /srv/backup/mariadb.dump +elif [ ! -z "$POSTGRES_PASSWORD" ]; then export PGPASSWORD=$POSTGRES_PASSWORD - export PGDATABASE="postgres" - pg_dump -Fc -hdb > /srv/backup/postgres.dump + pg_dump -Fc -hdb -Upostgres -dpostgres > /srv/backup/postgres.dump fi echo "Backup done!" diff --git a/db/restore.sh b/db/restore.sh index 3531fe7..480b3f0 100755 --- a/db/restore.sh +++ b/db/restore.sh @@ -4,15 +4,11 @@ # export POSTGRES="$(dpkg --get-selections | grep postgres 2>&1)" # export MYSQL="$(dpkg --get-selections | grep mysql 2>&1)" -if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; - then +if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then export MYSQL_PWD=$MYSQL_ROOT_PASSWORD - mysql -h db $MYSQL_DATABASE -uroot < /srv/backup/mariadb.dump -elif [ ! -z "$POSTGRES_PASSWORD" ]; - then - # export PGUSER="postgres" + gunzip < /srv/backup/mariadb.dump | mysql -h db $MYSQL_DATABASE -uroot +elif [ ! -z "$POSTGRES_PASSWORD" ]; then export PGPASSWORD=$POSTGRES_PASSWORD - # export PGDATABASE="postgres" pg_restore -c -hdb -Upostgres -dpostgres /srv/backup/postgres.dump fi -- 2.39.5