From: Martin Desrumaux Date: Tue, 5 Jan 2021 15:32:52 +0000 (+0100) Subject: feat(backup/restore): migrate backup to date-based format X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=bff2162c243ad8c0e853865d6ff260896499bb93;p=docker-django-scripts.git feat(backup/restore): migrate backup to date-based format --- diff --git a/dev/local/restore_db.sh b/dev/local/restore_db.sh index f01584e..4dcf40c 100755 --- a/dev/local/restore_db.sh +++ b/dev/local/restore_db.sh @@ -2,10 +2,17 @@ /srv/bin/misc/wait-for-it/wait-for-it.sh -h db -p $DB_PORT; +# Stop execution if some command fails set -e echo "Restoring..." +# Migrate backup to date-based format +if [ -f /srv/backup/postgres.dump ]; then + mv /srv/backup/postgres.dump /srv/backup/postgres_old.dump + ln -s /srv/backup/postgres_old.dump /srv/backup/postgres_latest.dump +fi + # import database functions of type if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then gunzip < /srv/backup/mariadb.dump.gz | mysql -h db $MYSQL_DATABASE -uroot -p$MYSQL_ROOT_PASSWORD diff --git a/prod/local/backup_db.sh b/prod/local/backup_db.sh index 4a2a516..f1778d3 100755 --- a/prod/local/backup_db.sh +++ b/prod/local/backup_db.sh @@ -4,6 +4,15 @@ # export POSTGRES="$(dpkg --get-selections | grep postgres 2>&1)" # export MYSQL="$(dpkg --get-selections | grep mysql 2>&1)" +# Stop execution if some command fails +set -e + +# Migrate backup to date-based format +if [ -f /srv/backup/postgres.dump ]; then + mv /srv/backup/postgres.dump /srv/backup/postgres_old.dump + ln -s /srv/backup/postgres_old.dump /srv/backup/postgres_latest.dump +fi + if [ ! -z "$MYSQL_PASSWORD" ]; then export MYSQL_PWD=$MYSQL_PASSWORD mysqldump $MYSQL_DATABASE -hdb -u$MYSQL_USER | gzip > /srv/backup/mariadb.dump.gz