From b6a165cb281e384f758b87119733254d8fbbff15 Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Tue, 19 Oct 2021 16:10:41 +0200 Subject: [PATCH 1/4] Make sure db restore works reliably and overwrites backup collections. --- scripts/db_restore.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/db_restore.sh b/scripts/db_restore.sh index 79e6e0f7..7ae0e6b0 100755 --- a/scripts/db_restore.sh +++ b/scripts/db_restore.sh @@ -85,20 +85,22 @@ if [ "$totalFoundObjects" -eq "0" ]; then echo "This backup doesn't exist!" exit 1 fi +cd $csd/.. # Get the backup from S3: aws s3 cp $S3_BACKUP_PATH/$BACKUP/mongo.tgz mongo.tgz # Prepare a clean `to_restore` dir: -rm -rf $csd/../docker/data/mongo/db/backups/to_restore -mkdir -p $csd/../docker/data/mongo/db/backups/to_restore +rm -rf docker/data/mongo/db/backups/to_restore +mkdir -p docker/data/mongo/db/backups/to_restore # Decompress the backup: -tar -xzf mongo.tgz -C $csd/../docker/data/mongo/db/backups/to_restore +tar -xzf mongo.tgz -C docker/data/mongo/db/backups/to_restore rm mongo.tgz # Restore the backup: # The name of the backup is not `mongo` due to the way we're creating it, # it's $BACKUP. docker exec mongo \ - mongorestore \ + mongorestore --drop \ mongodb://$SKYNET_DB_USER:$SKYNET_DB_PASS@$SKYNET_DB_HOST:$SKYNET_DB_PORT \ /data/db/backups/to_restore/$BACKUP # Clean up: -rm -rf $csd/../docker/data/mongo/db/backups/to_restore +rm -rf docker/data/mongo/db/backups/to_restore +cd - From 96a85e3ec47c8039c22fe5aa0d67bdf1806cba69 Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Tue, 19 Oct 2021 17:10:31 +0200 Subject: [PATCH 2/4] Add an update for awscli. Restore the backtracking paths. --- scripts/db_restore.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/db_restore.sh b/scripts/db_restore.sh index 7ae0e6b0..bcd6b24c 100755 --- a/scripts/db_restore.sh +++ b/scripts/db_restore.sh @@ -1,5 +1,8 @@ #!/bin/bash +# First of all, let's pamper awscli because Python is so special: +pip3 install --upgrade awscli + BACKUP=$1 if [[ $BACKUP == "" ]]; then echo "No backup name given. It should look like '2020-01-29'." @@ -89,18 +92,17 @@ cd $csd/.. # Get the backup from S3: aws s3 cp $S3_BACKUP_PATH/$BACKUP/mongo.tgz mongo.tgz # Prepare a clean `to_restore` dir: -rm -rf docker/data/mongo/db/backups/to_restore -mkdir -p docker/data/mongo/db/backups/to_restore +rm -rf $csd/../docker/data/mongo/db/backups/to_restore +mkdir -p $csd/../docker/data/mongo/db/backups/to_restore # Decompress the backup: -tar -xzf mongo.tgz -C docker/data/mongo/db/backups/to_restore +tar -xzf mongo.tgz -C $csd/../docker/data/mongo/db/backups/to_restore rm mongo.tgz # Restore the backup: # The name of the backup is not `mongo` due to the way we're creating it, # it's $BACKUP. docker exec mongo \ - mongorestore --drop \ + mongorestore -- drop\ mongodb://$SKYNET_DB_USER:$SKYNET_DB_PASS@$SKYNET_DB_HOST:$SKYNET_DB_PORT \ /data/db/backups/to_restore/$BACKUP # Clean up: -rm -rf docker/data/mongo/db/backups/to_restore -cd - +rm -rf $csd/../docker/data/mongo/db/backups/to_restore From 8bb5e24e24a364edbcb0e32cf0657063bc0b0ae4 Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Tue, 19 Oct 2021 17:12:00 +0200 Subject: [PATCH 3/4] Fix fingers-faster-than-brain bug. --- scripts/db_restore.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/db_restore.sh b/scripts/db_restore.sh index bcd6b24c..6e64671e 100755 --- a/scripts/db_restore.sh +++ b/scripts/db_restore.sh @@ -101,7 +101,7 @@ rm mongo.tgz # The name of the backup is not `mongo` due to the way we're creating it, # it's $BACKUP. docker exec mongo \ - mongorestore -- drop\ + mongorestore --drop \ mongodb://$SKYNET_DB_USER:$SKYNET_DB_PASS@$SKYNET_DB_HOST:$SKYNET_DB_PORT \ /data/db/backups/to_restore/$BACKUP # Clean up: From e541669a652b298f62f9b47a9c14978d7291f873 Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Tue, 19 Oct 2021 17:13:05 +0200 Subject: [PATCH 4/4] Remove merge leftovers. --- scripts/db_restore.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/db_restore.sh b/scripts/db_restore.sh index 6e64671e..f19def85 100755 --- a/scripts/db_restore.sh +++ b/scripts/db_restore.sh @@ -88,7 +88,6 @@ if [ "$totalFoundObjects" -eq "0" ]; then echo "This backup doesn't exist!" exit 1 fi -cd $csd/.. # Get the backup from S3: aws s3 cp $S3_BACKUP_PATH/$BACKUP/mongo.tgz mongo.tgz # Prepare a clean `to_restore` dir: