Created
August 11, 2022 15:39
-
-
Save nielsmaerten/acf67b9ab47d5bac5935c7bbc98ed805 to your computer and use it in GitHub Desktop.
A script to help me export the entries from my main Nightscout DB to a serverless instance for archiving.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################## | |
## NIGHTSCOUT BACKUP SCRIPT ## | |
############################## | |
# I'm using an Atlas DB called 'nightscout-cluster' at the time of writing. | |
# This DB is limited to 500MB so every now and then, | |
# I want pump its records over to 'serverlessnightscout' (a serverless Atlas DB), which is unlimited. | |
# If Nightscout ever starts supporting serverless databases, I can just update the | |
# connectionstring in Heroku, and start using the unlimited one. | |
# To run this script, start a fresh mongo docker container like so: | |
docker run -d --name nightscout-backup mongo | |
# Connect to the container's shell: | |
docker exec -it nightscout-backup bash | |
# Then run the following commands: (update with your own values) | |
export BACKUP_DESTINATION=serverlessnightscout.abc123.mongodb.net | |
export BACKUP_SOURCE=nightscout-cluster.abc123.mongodb.net | |
export USERNAME=heroku | |
export PASSWORD=see-password-manager | |
# Dump Nightscout DB from SOURCE Atlas server | |
mongodump --out /backups mongodb+srv://$USERNAME:$PASSWORD@$BACKUP_SOURCE/nightscout?retryWrites=true&w=majority | |
# Restore the Nightscout DB to DESTINATION Atlas server (serverless) | |
mongorestore --dir=/backups mongodb+srv://$USERNAME:$PASSWORD@$BACKUP_DESTINATION/?retryWrites=true&w=majority | |
# Exit docker container | |
exit | |
# Remove the docker container when you're done: | |
docker rm nightscout-backup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you don't want to run this on your own Docker instance, you can have GitHub do it for you: https://github.com/nielsmaerten/nightscout-archiver