From 8cecaf980589eacb180d33523d846a834f96059a Mon Sep 17 00:00:00 2001
From: Martin Lowe <martin.lowe@eclipse-foundation.org>
Date: Wed, 18 Dec 2019 11:04:48 -0500
Subject: [PATCH] Added documentation around backups of data from MongoDB

Signed-off-by: Martin Lowe <martin.lowe@eclipse-foundation.org>
---
 README.md | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/README.md b/README.md
index 69c771b..b4a8ffc 100644
--- a/README.md
+++ b/README.md
@@ -121,6 +121,46 @@ db.listing_versions.createIndex({ platforms: 1 }, {name: "platforms"});
 db.installs.createIndex({listing_id: 1 }, {name: "lid"});
 ```
 
+### Creating a backup
+
+In order to create a backup of an existing data set, read access to the MongoDB instance is required, and is best done with shell access.  
+
+To use the following commands, replace `<user>` with the name of the user with write access to the MPC data set. Each of these commands will initiate a password challenge request, and cannot be together in a script easily. Adding the `--password=<>` is not recommended as it is a vulnerability as the logs will remain on the server with plain text passwords. Additionally, the `<date>` placeholder should be replaced with whatever date stamp has been set in the snapshot .gz files.  
+
+In container:  
+
+```
+mkdir snapshot
+mongodump --username=<user> --archive=snapshot/listings.<date>.gz --db=mpc --collection=listings --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256 --gzip
+mongodump --username=<user> --archive=snapshot/markets.<date>.gz --db=mpc --collection=markets --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256 --gzip
+mongodump --username=<user> --archive=snapshot/categories.<date>.gz --db=mpc --collection=categories --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256 --gzip
+mongodump --username=<user> --archive=snapshot/catalogs.<date>.gz --db=mpc --collection=catalogs --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256 --gzip
+mongodump --username=<user> --archive=snapshot/listing_versions.<date>.gz --db=mpc --collection=listing_versions --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256 --gzip
+```
+
+If using Docker to host:
+`docker cp dev_mongo_1:/snapshot ./snapshot`
+
+### Restoring from backup
+
+In order to restore data from backup snapshot, write access to the MongoDB instance is required, and is best done with shell access. As `mongorestore` doesn't update or overwrite records, the existing data set should be wiped before proceeding with restoring from backup snapshots. 
+
+To use the following commands, replace `<user>` with the name of the user with write access to the MPC data set. Each of these commands will initiate a password challenge request, and cannot be together in a script easily. Adding the `--password=<>` is not recommended as it is a vulnerability as the logs will remain on the server with plain text passwords. Additionally, the `<date>` placeholder should be replaced with whatever date stamp has been set in the snapshot .gz files.
+
+From host machine to Docker:
+`docker cp ./snapshot dev_mongo_1:/`
+
+In container:  
+
+```
+mongorestore --username=<user> --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256 --nsInclude=mpc.* --gzip --archive=snapshot/listings.<date>.gz
+mongorestore --username=<user> --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256 --nsInclude=mpc.* --gzip --archive=snapshot/markets.<date>.gz
+mongorestore --username=<user> --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256 --nsInclude=mpc.* --gzip --archive=snapshot/catalogs.<date>.gz
+mongorestore --username=<user> --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256 --nsInclude=mpc.* --gzip --archive=snapshot/categories.<date>.gz
+mongorestore --username=<user> --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256 --nsInclude=mpc.* --gzip --archive=snapshot/listing_versions.<date>.gz
+```
+
+
 ## Copyright 
 
 Copyright (c) 2019 Eclipse Foundation and others.
-- 
GitLab