From: Emilie Date: Wed, 9 Aug 2017 10:24:19 +0000 (+0200) Subject: [db] : scripts for mysql and postgres. Now it's transparent for user to import a... X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=c0d0558624d6c9a5c2e127c5a3d658443aef0726;p=docker-django-scripts.git [db] : scripts for mysql and postgres. Now it's transparent for user to import a database, no matter if it is postgres or mysql --- diff --git a/db/backup.sh b/db/backup.sh index 300a3d8..2ffa0ba 100755 --- a/db/backup.sh +++ b/db/backup.sh @@ -1,7 +1,19 @@ #!/bin/bash -export PGPASSWORD=$POSTGRES_PASSWORD +# 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)" -pg_dump -Fc -hdb -Upostgres -dpostgres > /srv/backup/postgres.dump +if [ ! -z "$MYSQL" ]; + then + export MYSQL_PWD=$MYSQL_PASSWORD + mysqldump $MYSQL_DATABASE -hdb -u$MYSQL_USER > /srv/backup/mariadb.dump +elif [ ! -z "$POSTGRES" ]; + then + export PGUSER=$POSTGRES_PASSWORD + export PGPASSWORD=$DB_ROOT_PASSWORD + export PGDATABASE="postgres" + pg_dump -Fc -hdb > /srv/backup/postgres.dump +fi echo "Backup done!" diff --git a/db/restore.sh b/db/restore.sh index c084a16..5f28ff2 100755 --- a/db/restore.sh +++ b/db/restore.sh @@ -1,7 +1,19 @@ #!/bin/bash -export PGPASSWORD=$POSTGRES_PASSWORD +# import dump functions of the database (postgres or mysql) +export POSTGRES="$(dpkg --get-selections | grep postgres 2>&1)" +export MYSQL="$(dpkg --get-selections | grep mysql 2>&1)" -pg_restore -c -Fc -hdb -Upostgres -dpostgres /srv/backup/postgres.dump +if [ ! -z "$MYSQL" ]; + then + export MYSQL_PWD=$MYSQL_PASSWORD + mysql -h db $MYSQL_DATABASE -u$MYSQL_USER < /srv/backup/mariadb.dump +elif [ ! -z "$POSTGRES" ]; + then + export PGUSER=$POSTGRES_PASSWORD + export PGPASSWORD=$DB_ROOT_PASSWORD + export PGDATABASE="postgres" + pg_restore -c -Fc -hdb /srv/backup/postgres.dump +fi echo "Restore done!"