From 40db02913049d738813d6b816b7182f3b90f88bb Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 26 Aug 2017 00:10:42 -0400 Subject: [PATCH] Adds parameters to backup-auth for region support and non AWS endpoint support Refs dokku/dokku-mariadb#61 --- README.md | 19 +++++++++++++++---- commands | 2 +- common-functions | 49 ++++++++++++++++++++++++++++++++++++++---------- install | 2 +- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index bc643c8..8ad8295 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres ``` postgres:backup Create a backup of the postgres service to an existing s3 bucket -postgres:backup-auth Sets up authentication for backups on the postgres service +postgres:backup-auth () () () Sets up authentication for backups on the postgres service postgres:backup-deauth Removes backup authentication for the postgres service postgres:backup-schedule Schedules a backup of the postgres service postgres:backup-unschedule Unschedules the backup of the postgres service @@ -216,9 +216,7 @@ or root. ## Backups -Datastore backups are supported via AWS S3. The only supported region is `us-east-1`, and using an S3 bucket in another region will result in an error. - -> If you would like to sponsor work to enable support for other regions, please contact [@josegonzalez](http://github.com/josegonzalez/). +Datastore backups are supported via AWS S3 and S3 compatible services like [minio](https://github.com/minio/minio). Backups can be performed using the backup commands: @@ -239,3 +237,16 @@ dokku postgres:backup-schedule lolipop CRON_SCHEDULE BUCKET_NAME # remove the scheduled backup from cron dokku postgres:backup-unschedule lolipop ``` + +Backup auth can also be set up for different regions, signature versions and endpoints (e.g. for minio): + +``` +# setup s3 backup authentication with different region +dokku postgres:backup-auth lolipop AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION + +# setup s3 backup authentication with different signature version and endpoint +dokku postgres:backup-auth lolipop AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION AWS_SIGNATURE_VERSION ENDPOINT_URL + +# more specific example for minio auth +dokku postgres:backup-auth lolipop MINIO_ACCESS_KEY_ID MINIO_SECRET_ACCESS_KEY us-east-1 s3v4 https://YOURMINIOSERVICE +``` diff --git a/commands b/commands index 1a07da3..1f9f69d 100755 --- a/commands +++ b/commands @@ -105,7 +105,7 @@ case "$1" in declare desc="return $PLUGIN_COMMAND_PREFIX plugin help content" cat< , Create a backup of the $PLUGIN_COMMAND_PREFIX service to an existing s3 bucket - $PLUGIN_COMMAND_PREFIX:backup-auth , Sets up authentication for backups on the $PLUGIN_COMMAND_PREFIX service + $PLUGIN_COMMAND_PREFIX:backup-auth () () (), Sets up authentication for backups on the $PLUGIN_COMMAND_PREFIX service $PLUGIN_COMMAND_PREFIX:backup-deauth , Removes backup authentication for the $PLUGIN_COMMAND_PREFIX service $PLUGIN_COMMAND_PREFIX:backup-schedule , Schedules a backup of the $PLUGIN_COMMAND_PREFIX service $PLUGIN_COMMAND_PREFIX:backup-unschedule , Unschedules the backup of the $PLUGIN_COMMAND_PREFIX service diff --git a/common-functions b/common-functions index ebd2c69..eda9951 100755 --- a/common-functions +++ b/common-functions @@ -31,6 +31,7 @@ get_random_ports() { local quit=0 while [ "$quit" -ne 1 ]; do netstat -an | grep $port > /dev/null + # shellcheck disable=SC2181 if [ $? -gt 0 ]; then quit=1 else @@ -105,9 +106,9 @@ service_alternative_alias() { service_backup() { declare desc="Creates a backup of a service to an existing s3 bucket" declare SERVICE="$1" BUCKET_NAME="$2" - local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" - local AWS_ACCESS_KEY_ID_FILE="$SERVICE_ROOT/backup/AWS_ACCESS_KEY_ID" - local AWS_SECRET_ACCESS_KEY_FILE="$SERVICE_ROOT/backup/AWS_SECRET_ACCESS_KEY" + local BACKUP_CONFIG_ROOT="$PLUGIN_DATA_ROOT/$SERVICE/backup" + local AWS_ACCESS_KEY_ID_FILE="$BACKUP_CONFIG_ROOT/AWS_ACCESS_KEY_ID" + local AWS_SECRET_ACCESS_KEY_FILE="$BACKUP_CONFIG_ROOT/AWS_SECRET_ACCESS_KEY" [[ ! -f "$AWS_ACCESS_KEY_ID_FILE" ]] && dokku_log_fail "Missing AWS_ACCESS_KEY_ID file" [[ ! -f "$AWS_SECRET_ACCESS_KEY_FILE" ]] && dokku_log_fail "Missing AWS_SECRET_ACCESS_KEY file" @@ -116,23 +117,51 @@ service_backup() { trap 'rm -rf "$TMPDIR" > /dev/null' RETURN INT TERM EXIT (service_export "$SERVICE" > "${TMPDIR}/export") - docker run \ - -e AWS_ACCESS_KEY_ID="$(cat "$AWS_ACCESS_KEY_ID_FILE")" \ - -e AWS_SECRET_ACCESS_KEY="$(cat "$AWS_SECRET_ACCESS_KEY_FILE")" \ - -e BUCKET_NAME="$BUCKET_NAME" \ - -e BACKUP_NAME="${PLUGIN_COMMAND_PREFIX}-${SERVICE}" \ - -v "${TMPDIR}:/backup" dokkupaas/s3backup:0.6.0 + + # Build parameter list for s3backup tool + BACKUP_PARAMETERS="-e AWS_ACCESS_KEY_ID=$(cat "$AWS_ACCESS_KEY_ID_FILE") \ + -e AWS_SECRET_ACCESS_KEY=$(cat "$AWS_SECRET_ACCESS_KEY_FILE") \ + -e BUCKET_NAME=$BUCKET_NAME \ + -e BACKUP_NAME=${PLUGIN_COMMAND_PREFIX}-${SERVICE} \ + -v ${TMPDIR}:/backup" + + if [[ -f "$BACKUP_CONFIG_ROOT/AWS_DEFAULT_REGION" ]]; then + BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e AWS_DEFAULT_REGION=$(cat "$BACKUP_CONFIG_ROOT/AWS_DEFAULT_REGION")" + fi + + if [[ -f "$BACKUP_CONFIG_ROOT/AWS_SIGNATURE_VERSION" ]]; then + BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e AWS_SIGNATURE_VERSION=$(cat "$BACKUP_CONFIG_ROOT/AWS_SIGNATURE_VERSION")" + fi + + if [[ -f "$BACKUP_CONFIG_ROOT/ENDPOINT_URL" ]]; then + BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e ENDPOINT_URL=$(cat "$BACKUP_CONFIG_ROOT/ENDPOINT_URL")" + fi + + # shellcheck disable=SC2086 + docker run $BACKUP_PARAMETERS dokkupaas/s3backup:0.7.0 } service_backup_auth() { declare desc="Sets up authentication" - declare SERVICE="$1" AWS_ACCESS_KEY_ID="$2" AWS_SECRET_ACCESS_KEY="$3" + declare SERVICE="$1" AWS_ACCESS_KEY_ID="$2" AWS_SECRET_ACCESS_KEY="$3" AWS_DEFAULT_REGION="$4" AWS_SIGNATURE_VERSION="$5" ENDPOINT_URL="$6" local SERVICE_ROOT="${PLUGIN_DATA_ROOT}/${SERVICE}" local SERVICE_BACKUP_ROOT="${SERVICE_ROOT}/backup/" mkdir -p "$SERVICE_BACKUP_ROOT" echo "$AWS_ACCESS_KEY_ID" > "${SERVICE_BACKUP_ROOT}/AWS_ACCESS_KEY_ID" echo "$AWS_SECRET_ACCESS_KEY" > "${SERVICE_BACKUP_ROOT}/AWS_SECRET_ACCESS_KEY" + + if [[ -n "$AWS_DEFAULT_REGION" ]]; then + echo "$AWS_DEFAULT_REGION" > "${SERVICE_BACKUP_ROOT}/AWS_DEFAULT_REGION" + fi + + if [[ -n "$AWS_SIGNATURE_VERSION" ]]; then + echo "$AWS_SIGNATURE_VERSION" > "${SERVICE_BACKUP_ROOT}/AWS_SIGNATURE_VERSION" + fi + + if [[ -n "$ENDPOINT_URL" ]]; then + echo "$ENDPOINT_URL" > "${SERVICE_BACKUP_ROOT}/ENDPOINT_URL" + fi } service_backup_deauth() { diff --git a/install b/install index 72b46a5..60f5315 100755 --- a/install +++ b/install @@ -13,7 +13,7 @@ plugin-install() { pull-docker-image "${PLUGIN_IMAGE}:${PLUGIN_IMAGE_VERSION}" pull-docker-image "svendowideit/ambassador:latest" pull-docker-image "dokkupaas/wait:0.2" - pull-docker-image "dokkupaas/s3backup:0.6.0" + pull-docker-image "dokkupaas/s3backup:0.7.0" pull-docker-image "busybox:latest" mkdir -p "$PLUGIN_DATA_ROOT" || echo "Failed to create $PLUGIN_SERVICE directory"