From 96c634b6e776079ae692a87d0849a569c80237a8 Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Thu, 21 Oct 2021 10:40:33 +0200 Subject: [PATCH] Backup MongoDB before CockroachDB because we can backfill user registrations in MongoDB but not in CockroachDB. --- scripts/db_backup.sh | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/db_backup.sh b/scripts/db_backup.sh index 14f7abb1..32e042ce 100755 --- a/scripts/db_backup.sh +++ b/scripts/db_backup.sh @@ -27,26 +27,6 @@ fi # Take the current datetime: DT=$(date +%Y-%m-%d) -### COCKROACH DB ### -echo "Creating a backup of CockroachDB:" -# Check if a backup already exists: -totalFoundObjects=$(aws s3 ls $S3_BACKUP_PATH/$DT --recursive --summarize | grep "cockroach" | wc -l) -if [ "$totalFoundObjects" -ge "1" ]; then - echo "Backup already exists for today. Skipping." -else - # Create a cockroachdb backup: - docker exec cockroach \ - cockroach sql \ - --host cockroach:26257 \ - --certs-dir=/certs \ - --execute="BACKUP TO '$S3_BACKUP_PATH/$DT/cockroach/?AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID&AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY';" - if [[ $? > 0 ]]; then - echo "Creating a CockroachDB backup failed. Skipping." - else - echo "Successfully backed up CockroachDB." - fi -fi - ### MONGO DB ### echo "Creating a backup of MongoDB:" # Check if a backup already exists: @@ -73,3 +53,23 @@ else fi docker exec mongo rm -rf /data/db/backups/$DT fi + +### COCKROACH DB ### +echo "Creating a backup of CockroachDB:" +# Check if a backup already exists: +totalFoundObjects=$(aws s3 ls $S3_BACKUP_PATH/$DT --recursive --summarize | grep "cockroach" | wc -l) +if [ "$totalFoundObjects" -ge "1" ]; then + echo "Backup already exists for today. Skipping." +else + # Create a cockroachdb backup: + docker exec cockroach \ + cockroach sql \ + --host cockroach:26257 \ + --certs-dir=/certs \ + --execute="BACKUP TO '$S3_BACKUP_PATH/$DT/cockroach/?AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID&AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY';" + if [[ $? > 0 ]]; then + echo "Creating a CockroachDB backup failed. Skipping." + else + echo "Successfully backed up CockroachDB." + fi +fi