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

✨ Allow for specifying the S3 Storage Class #205

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ postgres:app-links <app> # list all postgres service l
postgres:backup <service> <bucket-name> [--use-iam] # creates a backup of the postgres service to an existing s3 bucket
postgres:backup-auth <service> <aws-access-key-id> <aws-secret-access-key> <aws-default-region> <aws-signature-version> <endpoint-url> # sets up authentication for backups on the postgres service
postgres:backup-deauth <service> # removes backup authentication for the postgres service
postgres:backup-s3class <service> <s> <-storage-class> # sets the S3 storage class to be used for backups on the postgres service
Copy link
Member

Choose a reason for hiding this comment

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

Can you manually regenerate the readme via make README.md?

Copy link
Author

Choose a reason for hiding this comment

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

That's the way it generates, I can fix the output but idk if there's an issue with the parsing or my subcommand.

postgres:backup-schedule <service> <schedule> <bucket-name> [--use-iam] # schedules a backup of the postgres service
postgres:backup-schedule-cat <service> # cat the contents of the configured backup cronfile for the service
postgres:backup-set-encryption <service> <passphrase> # sets encryption for all future backups of postgres service
Expand Down
24 changes: 22 additions & 2 deletions common-functions
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ service_backup() {
local BACKUP_ENCRYPTION_CONFIG_ROOT="$PLUGIN_DATA_ROOT/$SERVICE/backup-encryption"
local AWS_ACCESS_KEY_ID_FILE="$SERVICE_BACKUP_ROOT/AWS_ACCESS_KEY_ID"
local AWS_SECRET_ACCESS_KEY_FILE="$SERVICE_BACKUP_ROOT/AWS_SECRET_ACCESS_KEY"
local S3_STORAGE_CLASS_FILE="$SERVICE_BACKUP_ROOT/S3_STORAGE_CLASS"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local ID="$(cat "$SERVICE_ROOT/ID")"
local BACKUP_PARAMETERS=""
Expand All @@ -188,6 +189,10 @@ service_backup() {
dokku_log_fail "Provide AWS credentials or use the --use-iam flag"
fi

if [[ -f "$S3_STORAGE_CLASS_FILE" ]]; then
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e S3_STORAGE_CLASS=$(cat "$S3_STORAGE_CLASS_FILE")"
fi

TMPDIR=$(mktemp -d --tmpdir)
trap 'rm -rf "$TMPDIR" > /dev/null' RETURN INT TERM EXIT

Expand Down Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

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

Was this necessary?

Copy link
Author

Choose a reason for hiding this comment

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

Otherwise it will fail upon trying to create the dir if it already existed

echo "$AWS_ACCESS_KEY_ID" >"$SERVICE_BACKUP_ROOT/AWS_ACCESS_KEY_ID"
echo "$AWS_SECRET_ACCESS_KEY" >"$SERVICE_BACKUP_ROOT/AWS_SECRET_ACCESS_KEY"

Expand All @@ -249,7 +254,22 @@ 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"
Copy link
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Author

Choose a reason for hiding this comment

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

Because the auth command is no longer the only one using that directory, leaving it the way it was would also delete the S3_STORAGE_CLASS.


}

service_backup_s3class() {
declare desc="Sets the S3 storage class to be used for the backup"
declare SERVICE="$1" S3_STORAGE_CLASS="$2"
local SERVICE_BACKUP_ROOT="$PLUGIN_DATA_ROOT/$SERVICE/backup/"

mkdir -p "$SERVICE_BACKUP_ROOT"
echo "$S3_STORAGE_CLASS" >"$SERVICE_BACKUP_ROOT/S3_STORAGE_CLASS"
Copy link
Member

Choose a reason for hiding this comment

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

I really need to transfer all of this to the new properties system...


}

service_backup_schedule() {
Expand Down
2 changes: 1 addition & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -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"
25 changes: 25 additions & 0 deletions subcommands/backup-s3class
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/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" S3_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 "$S3_STORAGE_CLASS" ]] && dokku_log_fail "Please specify an aws S3 storage class"
[[ ! "$S3_STORAGE_CLASS" =~ ^(STANDARD|REDUCED_REDUNDANCY|STANDARD_IA|ONEZONE_IA|INTELLIGENT_TIERING|GLACIER|DEEP_ARCHIVE)$ ]] && dokku_log_fail "$S3_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" "$S3_STORAGE_CLASS"
}

service-backup-s3class-cmd "$@"