Make sure db restore works reliably and overwrites backup collections.
This commit is contained in:
parent
f78bc22b5b
commit
b6a165cb28
|
@ -85,20 +85,22 @@ if [ "$totalFoundObjects" -eq "0" ]; then
|
||||||
echo "This backup doesn't exist!"
|
echo "This backup doesn't exist!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
cd $csd/..
|
||||||
# Get the backup from S3:
|
# Get the backup from S3:
|
||||||
aws s3 cp $S3_BACKUP_PATH/$BACKUP/mongo.tgz mongo.tgz
|
aws s3 cp $S3_BACKUP_PATH/$BACKUP/mongo.tgz mongo.tgz
|
||||||
# Prepare a clean `to_restore` dir:
|
# Prepare a clean `to_restore` dir:
|
||||||
rm -rf $csd/../docker/data/mongo/db/backups/to_restore
|
rm -rf docker/data/mongo/db/backups/to_restore
|
||||||
mkdir -p $csd/../docker/data/mongo/db/backups/to_restore
|
mkdir -p docker/data/mongo/db/backups/to_restore
|
||||||
# Decompress the backup:
|
# 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
|
rm mongo.tgz
|
||||||
# Restore the backup:
|
# Restore the backup:
|
||||||
# The name of the backup is not `mongo` due to the way we're creating it,
|
# The name of the backup is not `mongo` due to the way we're creating it,
|
||||||
# it's $BACKUP.
|
# it's $BACKUP.
|
||||||
docker exec mongo \
|
docker exec mongo \
|
||||||
mongorestore \
|
mongorestore --drop \
|
||||||
mongodb://$SKYNET_DB_USER:$SKYNET_DB_PASS@$SKYNET_DB_HOST:$SKYNET_DB_PORT \
|
mongodb://$SKYNET_DB_USER:$SKYNET_DB_PASS@$SKYNET_DB_HOST:$SKYNET_DB_PORT \
|
||||||
/data/db/backups/to_restore/$BACKUP
|
/data/db/backups/to_restore/$BACKUP
|
||||||
# Clean up:
|
# Clean up:
|
||||||
rm -rf $csd/../docker/data/mongo/db/backups/to_restore
|
rm -rf docker/data/mongo/db/backups/to_restore
|
||||||
|
cd -
|
||||||
|
|
Reference in New Issue