Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit e314238

Browse files
committed
Add option for gpg encryption
1 parent dfad34e commit e314238

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

scripts/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,27 @@ All parameters must be supplied as environment variables:
1616
| MONGODB\PASSWORD | yes |
1717
| MONGODB\_DATABASE | yes |
1818
| OUTPUT | |
19+
| GPG\_PASSWORD | |
20+
21+
If you set `GPG_PASSWORD`, the resulting archive will be encrypted (symmetrically, with the given passphrase).
22+
This is recommended if you dump the database on your personal laptop because of data security.
1923

2024
After exporting these environment variables to your bash, run:
21-
```
25+
26+
```bash
2227
./remote-dump.sh
2328
```
2429

30+
31+
# Import into your local mongo db (optional)
32+
33+
Run (but change the file name accordingly):
34+
```bash
35+
mongorestore --gzip --archive=human-connection-dump_2018-11-21.archive
36+
```
37+
38+
If you previously encrypted your dump, run:
39+
```bash
40+
gpg --decrypt human-connection-dump_2018-11-21.archive.gpg | mongorestore --gzip --archive
41+
```
42+

scripts/remote-dump.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@ echo "MONGODB_USERNAME ${MONGODB_USERNAME}"
1616
echo "MONGODB_PASSWORD ${MONGODB_PASSWORD}"
1717
echo "MONGODB_DATABASE ${MONGODB_DATABASE}"
1818
echo "OUTPUT_FILE_NAME ${OUTPUT_FILE_NAME}"
19+
echo "GPG_PASSWORD ${GPG_PASSWORD:-<none>}"
1920
echo "-------------------------------------------------"
2021

2122
ssh -M -S my-ctrl-socket -fnNT -L 27018:localhost:27017 -l ${SSH_USERNAME} ${SSH_HOST}
22-
mongodump --host localhost -d ${MONGODB_DATABASE} --port 27018 --username ${MONGODB_USERNAME} --password ${MONGODB_PASSWORD} --authenticationDatabase admin --gzip --archive=${OUTPUT_FILE_NAME}
23+
24+
if [[ -z "${!GPG_PASSWORD}" ]]; then
25+
mongodump --host localhost -d ${MONGODB_DATABASE} --port 27018 --username ${MONGODB_USERNAME} --password ${MONGODB_PASSWORD} --authenticationDatabase admin --gzip --archive | gpg -c --batch --passphrase ${GPG_PASSWORD} --output ${OUTPUT_FILE_NAME}.gpg
26+
else
27+
mongodump --host localhost -d ${MONGODB_DATABASE} --port 27018 --username ${MONGODB_USERNAME} --password ${MONGODB_PASSWORD} --authenticationDatabase admin --gzip --archive=${OUTPUT_FILE_NAME}
28+
fi
29+
30+
2331
ssh -S my-ctrl-socket -O check -l ${SSH_USERNAME} ${SSH_HOST}
2432
ssh -S my-ctrl-socket -O exit -l ${SSH_USERNAME} ${SSH_HOST}

0 commit comments

Comments
 (0)