This repository was archived by the owner on Jun 27, 2019. It is now read-only.
File tree 4 files changed +79
-0
lines changed
4 files changed +79
-0
lines changed Original file line number Diff line number Diff line change 1
1
node_modules /
2
2
npm-debug.log
3
+ scripts /
3
4
Dockerfile
Original file line number Diff line number Diff line change
1
+ *
2
+ ! remote-dump.sh
3
+ ! README.md
4
+ ! .gitignore
Original file line number Diff line number Diff line change
1
+ # How to use the backup script
2
+
3
+ The backup script is intended to be used as a cron job or as a single command from your laptop.
4
+ It uses SSH tunneling to a remote host and dumps the mongo database on your machine.
5
+ Therefore, a public SSH key needs to be copied to the remote machine.
6
+
7
+ # Usage
8
+
9
+ All parameters must be supplied as environment variables:
10
+
11
+ | Name | required |
12
+ | -----------------------| -----------|
13
+ | SSH\_ USERNAME | yes |
14
+ | SSH\_ HOST | yes |
15
+ | MONGODB\_ USERNAME | yes |
16
+ | MONGODB\_ PASSWORD | yes |
17
+ | MONGODB\_ DATABASE | yes |
18
+ | 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.
23
+
24
+ After exporting these environment variables to your bash, run:
25
+
26
+ ``` bash
27
+ ./remote-dump.sh
28
+ ```
29
+
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
+
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ for var in " SSH_USERNAME" " SSH_HOST" " MONGODB_USERNAME" " MONGODB_PASSWORD" " MONGODB_DATABASE"
4
+ do
5
+ if [[ -z " ${! var} " ]]; then
6
+ echo " ${var} is undefined"
7
+ exit -1
8
+ fi
9
+ done
10
+
11
+ OUTPUT_FILE_NAME=${OUTPUT:- human-connection-dump} _$( date -I) .archive
12
+
13
+ echo " SSH_USERNAME ${SSH_USERNAME} "
14
+ echo " SSH_HOST ${SSH_HOST} "
15
+ echo " MONGODB_USERNAME ${MONGODB_USERNAME} "
16
+ echo " MONGODB_PASSWORD ${MONGODB_PASSWORD} "
17
+ echo " MONGODB_DATABASE ${MONGODB_DATABASE} "
18
+ echo " OUTPUT_FILE_NAME ${OUTPUT_FILE_NAME} "
19
+ echo " GPG_PASSWORD ${GPG_PASSWORD:- <none>} "
20
+ echo " -------------------------------------------------"
21
+
22
+ ssh -M -S my-ctrl-socket -fnNT -L 27018:localhost:27017 -l ${SSH_USERNAME} ${SSH_HOST}
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
+
31
+ ssh -S my-ctrl-socket -O check -l ${SSH_USERNAME} ${SSH_HOST}
32
+ ssh -S my-ctrl-socket -O exit -l ${SSH_USERNAME} ${SSH_HOST}
You can’t perform that action at this time.
0 commit comments