Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom s3 endpoint support #28

Merged
merged 9 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ What is mongodb-awesome-backup?
-------------------------------

mongodb-awesome-backup is the collection of scripts which backup MongoDB databases to Amazon S3 or Google Cloud Storage.
You can set a custom S3 endpoint to use S3 based services like DigitalOcean Spaces instead of Amazon S3.


Requirements
Expand Down Expand Up @@ -39,6 +40,7 @@ docker run --rm \
[ -e MONGODB_USERNAME=<DB login username> \ ]
[ -e MONGODB_PASSWORD=<DB login password> \ ]
[ -e MONGODB_AUTHDB=<Authentication DB name> \ ]
[ -e AWSCLI_ENDPOINT_OPT=<S3 endpoint URL (ex. https://fra1.digitaloceanspaces.com)> \ ]
[ -v ~:/mab \ ]
weseek/mongodb-awesome-backup
```
Expand Down Expand Up @@ -66,6 +68,7 @@ docker run --rm \
[ -e MONGODB_USERNAME=<DB login username> \ ]
[ -e MONGODB_PASSWORD=<DB login password> \ ]
[ -e MONGODB_AUTHDB=<Authentication DB name> \ ]
[ -e AWSCLI_ENDPOINT_OPT=<S3 endpoint URL (ex. https://fra1.digitaloceanspaces.com)> \ ]
[ -v ~:/mab \ ]
weseek/mongodb-awesome-backup
```
Expand All @@ -90,6 +93,7 @@ docker run --rm \
[ -e MONGODB_PASSWORD=<DB login password> \ ]
[ -e MONGODB_AUTHDB=<Authentication DB name> \ ]
[ -e MONGORESTORE_OPTS=<Options list of mongorestore> \ ]
[ -e AWSCLI_ENDPOINT_OPT=<S3 endpoint URL (ex. https://fra1.digitaloceanspaces.com)> \ ]
[ -v ~:/mab \ ]
weseek/mongodb-awesome-backup restore
```
Expand Down Expand Up @@ -124,6 +128,7 @@ Environment variables
| MONGODB_AUTHDB | Authentication DB name | - |
| CRONMODE | If set "true", this container is executed in cron mode. In cron mode, the script will be executed with the specified arguments and at the time specified by CRON_EXPRESSION. | "false" |
| CRON_EXPRESSION | Cron expression (ex. "CRON_EXPRESSION=0 4 * * *" if you want to run at 4:00 every day) | - |
| AWSCLI_ENDPOINT_OPT | Set a custom S3 endpoint if you use a S3 based service like DigitalOcean Spaces. (ex. AWSCLI_ENDPOINT_OPT="https://fra1.digitaloceanspaces.com") If not set the Amazon S3 standard endpoint will be used. | - |
| HEALTHCHECKS_URL | URL that gets called after a successful backup (eg. https://healthchecks.io) | - |

### For `restore`
Expand Down Expand Up @@ -151,3 +156,4 @@ Environment variables
| MONGODB_PASSWORD | DB login password | - |
| MONGODB_AUTHDB | Authentication DB name | - |
| MONGORESTORE_OPTS | Options list of mongorestore. (ex --drop) | - |
| AWSCLI_ENDPOINT_OPT | Set a custom S3 endpoint if you use a S3 based service like DigitalOcean Spaces. (ex. AWSCLI_ENDPOINT_OPT="https://fra1.digitaloceanspaces.com") If not set the Amazon S3 standard endpoint will be used. | - |
27 changes: 23 additions & 4 deletions bin/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ DATE_CMD="/bin/date"
# arguments: 1. s3 url (s3://.../...)
s3_exists() {
if [ $# -ne 1 ]; then return 255; fi
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 >/dev/null
if [ -z "$AWSCLI_ENDPOINT_OPT" ]
then
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 >/dev/null
else
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 >/dev/null
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [ -z "$AWSCLI_ENDPOINT_OPT" ]
then
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 >/dev/null
else
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 >/dev/null
fi
${AWSCLI} ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1 >/dev/null

}
gs_exists() {
if [ $# -ne 1 ]; then return 255; fi
Expand All @@ -29,7 +34,12 @@ gs_exists() {
# Output the list of the files on specified S3 URL.
# arguments: 1. s3 url (s3://...)
s3_list_files() {
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1
if [ -z "$AWSCLI_ENDPOINT_OPT" ]
then
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1
else
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [ -z "$AWSCLI_ENDPOINT_OPT" ]
then
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1
else
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1
fi
${AWSCLI} ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_LIST_OPT} $1

}
gs_list_files() {
${GCSCLI} ${GCSCLIOPT} ${GCSCLI_LIST_OPT} $1
Expand All @@ -39,7 +49,12 @@ gs_list_files() {
# arguments: 1. s3 url (s3://.../...)
s3_delete_file() {
if [ $# -ne 1 ]; then return 255; fi
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_DEL_OPT} $1
if [ -z "$AWSCLI_ENDPOINT_OPT" ]
then
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_DEL_OPT} $1
else
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_DEL_OPT} $1
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [ -z "$AWSCLI_ENDPOINT_OPT" ]
then
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_DEL_OPT} $1
else
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_DEL_OPT} $1
fi
${AWSCLI} ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_DEL_OPT} $1

}
gs_delete_file() {
if [ $# -ne 1 ]; then return 255; fi
Expand All @@ -57,7 +72,11 @@ gs_delete_file() {
# 2. target s3 url (s3://...)
s3_copy_file() {
if [ $# -ne 2 ]; then return 255; fi
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_COPY_OPT} $1 $2
if [ -z "$AWSCLI_ENDPOINT_OPT" ]
then
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_COPY_OPT} $1 $2
else
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_COPY_OPT} $1 $2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no "fi" on line 80 and it is a syntax error.

Suggested change
if [ -z "$AWSCLI_ENDPOINT_OPT" ]
then
${AWSCLI} ${AWSCLIOPT} ${AWSCLI_COPY_OPT} $1 $2
else
${AWSCLI} --endpoint-url ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_COPY_OPT} $1 $2
${AWSCLI} ${AWSCLI_ENDPOINT_OPT} ${AWSCLIOPT} ${AWSCLI_COPY_OPT} $1 $2

}
gs_copy_file() {
if [ $# -ne 2 ]; then return 255; fi
Expand Down