Skip to content

Instantly share code, notes, and snippets.

@cdukebwell
Last active May 26, 2022 14:16
Show Gist options
  • Save cdukebwell/6511c19385bd0bf045f0f5276d1f2f5b to your computer and use it in GitHub Desktop.
Save cdukebwell/6511c19385bd0bf045f0f5276d1f2f5b to your computer and use it in GitHub Desktop.
Simple mongo dump/restore
#!/bin/bash
lookbackDate=`date -d "6 hours ago" +"%Y-%m-%dT%H:%M:%S%z"`
echo $lookbackDate
while IFS= read -r c
do
echo "Queuing...${c}"
mongodump \
--config=/home/ubuntu/aws-prod-cs \
--username=root \
-d fhir_prod \
-c $c \
--gzip --archive \
| mongorestore \
--config=/home/ubuntu/atlas-prod-cs \
--username=pa-prod-service \
--stopOnError \
--numInsertionWorkersPerCollection=10 \
--nsFrom="fhir_prod.*" \
--nsTo="fhir.*" \
--
--gzip --archive > "/tmp/mongosync-prod-${lookbackdate}.log"
done < "/home/ubuntu/collections.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment