diff --git a/README.md b/README.md index e5c5302b..d76d30df 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ postgres:app-links # list all postgres service l postgres:backup [--use-iam] # creates 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-deauth # removes backup authentication for the postgres service +postgres:backup-s3class # sets the S3 storage class to be used for backups on the postgres service postgres:backup-schedule [--use-iam] # schedules a backup of the postgres service postgres:backup-schedule-cat # cat the contents of the configured backup cronfile for the service postgres:backup-set-encryption # sets encryption for all future backups of postgres service diff --git a/common-functions b/common-functions index c0b316c7..f2a9d169 100755 --- a/common-functions +++ b/common-functions @@ -3,6 +3,7 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/config/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" docker_ports_options() { declare desc="Exports a list of exposed ports" @@ -188,6 +189,10 @@ service_backup() { dokku_log_fail "Provide AWS credentials or use the --use-iam flag" fi + if fn-plugin-property-exists "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "S3_STORAGE_CLASS"; then + BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e S3_STORAGE_CLASS=$(fn-plugin-property-get "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "S3_STORAGE_CLASS")" + fi + TMPDIR=$(mktemp -d --tmpdir) trap 'rm -rf "$TMPDIR" > /dev/null' RETURN INT TERM EXIT @@ -226,7 +231,7 @@ service_backup_auth() { 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_BACKUP_ROOT="$PLUGIN_DATA_ROOT/$SERVICE/backup" - mkdir "$SERVICE_BACKUP_ROOT" + 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" @@ -249,7 +254,18 @@ service_backup_deauth() { local SERVICE_ROOT="${PLUGIN_DATA_ROOT}/${SERVICE}" local SERVICE_BACKUP_ROOT="${SERVICE_ROOT}/backup/" - rm -rf "$SERVICE_BACKUP_ROOT" + rm -f "$SERVICE_BACKUP_ROOT/AWS_ACCESS_KEY_ID" + rm -f "$SERVICE_BACKUP_ROOT/AWS_SECRET_ACCESS_KEY" + rm -f "$SERVICE_BACKUP_ROOT/AWS_DEFAULT_REGION" + rm -f "$SERVICE_BACKUP_ROOT/AWS_SIGNATURE_VERSION" + rm -f "$SERVICE_BACKUP_ROOT/ENDPOINT_URL" + +} + +service_backup_s3class() { + declare desc="Sets the S3 storage class to be used for the backup" + declare SERVICE="$1" S3_STORAGE_CLASS="$2" + fn-plugin-property-write "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "S3_STORAGE_CLASS" "$S3_STORAGE_CLASS" } service_backup_schedule() { diff --git a/config b/config index 1a2312fd..9f8ce0cd 100644 --- a/config +++ b/config @@ -28,5 +28,5 @@ fi export PLUGIN_BUSYBOX_IMAGE="busybox:1.31.1-uclibc" export PLUGIN_AMBASSADOR_IMAGE="dokku/ambassador:0.3.3" -export PLUGIN_S3BACKUP_IMAGE="dokku/s3backup:0.10.3" +export PLUGIN_S3BACKUP_IMAGE="dokku/s3backup:0.11.1" export PLUGIN_WAIT_IMAGE="dokku/wait:0.4.3" diff --git a/install b/install index 6521cc36..d8238d24 100755 --- a/install +++ b/install @@ -1,5 +1,7 @@ #!/usr/bin/env bash source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" + set -eo pipefail [[ $DOKKU_TRACE ]] && set -x @@ -25,6 +27,7 @@ plugin-install() { mkdir -p "$PLUGIN_DATA_ROOT" || echo "Failed to create $PLUGIN_SERVICE data directory" chown dokku:dokku "$PLUGIN_DATA_ROOT" + fn-plugin-property-setup "$PLUGIN_COMMAND_PREFIX" mkdir -p "$PLUGIN_CONFIG_ROOT" || echo "Failed to create $PLUGIN_SERVICE config directory" chown dokku:dokku "$PLUGIN_CONFIG_ROOT" diff --git a/subcommands/backup-s3class b/subcommands/backup-s3class new file mode 100755 index 00000000..780f7a11 --- /dev/null +++ b/subcommands/backup-s3class @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_BASE_PATH/common/functions" +source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" + +service-backup-s3class-cmd() { + #E set the s3 storage class to Standard Infrequent Access + #E dokku $PLUGIN_COMMAND_PREFIX:backup-s3class lolipop STANDARD_IA + #A service, service to run command against + #A storage-class, an aws S3 storage class + declare desc="sets the S3 storage class to be used for backups on the $PLUGIN_SERVICE service" + local cmd="$PLUGIN_COMMAND_PREFIX:backup-s3class" argv=("$@") + [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" STORAGE_CLASS="$2" + is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service" + [[ -z "$STORAGE_CLASS" ]] && dokku_log_fail "Please specify an aws S3 storage class" + [[ ! "$STORAGE_CLASS" =~ ^(STANDARD|REDUCED_REDUNDANCY|STANDARD_IA|ONEZONE_IA|INTELLIGENT_TIERING|GLACIER|DEEP_ARCHIVE)$ ]] && dokku_log_fail "$STORAGE_CLASS is not a valid S3 storage class. Read https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html for more information." + service_backup_s3class "$SERVICE" "$STORAGE_CLASS" + echo "Set the storage class to $STORAGE_CLASS" +} + +service-backup-s3class-cmd "$@"