This repository was archived by the owner on Jun 27, 2019. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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+
20+ After exporting these environment variables to your bash, run:
21+ ```
22+ ./remote-dump.sh
23+ ```
24+
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 " -------------------------------------------------"
20+
21+ 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+ ssh -S my-ctrl-socket -O check -l ${SSH_USERNAME} ${SSH_HOST}
24+ ssh -S my-ctrl-socket -O exit -l ${SSH_USERNAME} ${SSH_HOST}
You can’t perform that action at this time.
0 commit comments