From 03a56833967b3494fd8cc5eadaf4d61527ca8b8f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Voyazopoulos?= Date: Mon, 11 Feb 2019 15:50:56 +0100 Subject: [PATCH] Dumps are now timestamped, and restore drops the database before --- dev/local/restore_db.sh | 4 +++- prod/local/backup_db.sh | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dev/local/restore_db.sh b/dev/local/restore_db.sh index 4c1aaf1..89fbd13 100755 --- a/dev/local/restore_db.sh +++ b/dev/local/restore_db.sh @@ -11,7 +11,9 @@ if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then gunzip < /srv/backup/mariadb.dump.gz | mysql -h db $MYSQL_DATABASE -uroot -p$MYSQL_ROOT_PASSWORD elif [ ! -z "$POSTGRES_PASSWORD" ]; then export PGPASSWORD=$POSTGRES_PASSWORD - pg_restore -c -hdb -Upostgres -dpostgres /srv/backup/postgres.dump + dropdb -hdb -Upostgres postgres + createdb -hdb -Upostgres -T template0 postgres + pg_restore -C -c -hdb -Upostgres -dpostgres /srv/backup/postgres_latest.dump fi echo "Restore done!" diff --git a/prod/local/backup_db.sh b/prod/local/backup_db.sh index 4fa4811..4a2a516 100755 --- a/prod/local/backup_db.sh +++ b/prod/local/backup_db.sh @@ -9,7 +9,10 @@ if [ ! -z "$MYSQL_PASSWORD" ]; then mysqldump $MYSQL_DATABASE -hdb -u$MYSQL_USER | gzip > /srv/backup/mariadb.dump.gz elif [ ! -z "$POSTGRES_PASSWORD" ]; then export PGPASSWORD=$POSTGRES_PASSWORD - pg_dump -Fc -hdb -Upostgres -dpostgres > /srv/backup/postgres.dump + now=$(date +"%m_%d_%Y_%H_%M_%S") + pg_dump -Fc -hdb -Upostgres -dpostgres > /srv/backup/postgres_$now.dump + rm -f /srv/backup/postgres_latest.dump + ln -s /srv/backup/postgres_$now.dump /srv/backup/postgres_latest.dump fi echo "Backup done!" -- 2.39.5