From 63e6ecc7a531629dce0f228cc78632a1cf73726d Mon Sep 17 00:00:00 2001 From: "Ernesto R. C. Pereda" Date: Sat, 29 Aug 2020 12:58:14 -0400 Subject: [PATCH 1/2] Add aws glacier suport --- README.md | 1 + src/backup.sh | 9 +++++++ src/entrypoint.sh | 1 + test/backing-up-to-glacier/docker-compose.yml | 25 +++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 test/backing-up-to-glacier/docker-compose.yml diff --git a/README.md b/README.md index 6b797c1..54f8735 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,7 @@ Variable | Default | Notes `BACKUP_WAIT_SECONDS` | `0` | The backup script will sleep this many seconds between re-starting stopped containers, and proceeding with archiving/uploading the backup. This can be useful if you don't want the load/network spike of a large upload immediately after the load/network spike of container startup. `BACKUP_HOSTNAME` | `$(hostname)` | Name of the host (i.e. Docker container) in which the backup runs. Mostly useful if you want a specific hostname to be associated with backup metrics (see InfluxDB support). `AWS_S3_BUCKET_NAME` | | When provided, the resulting backup file will be uploaded to this S3 bucket after the backup has ran. +`AWS_GLACIER_VAULT_NAME` | | When provided, the resulting backup file will be uploaded to this AWS Glacier vault after the backup has ran. `AWS_ACCESS_KEY_ID` | | Required when using `AWS_S3_BUCKET_NAME`. `AWS_SECRET_ACCESS_KEY` | | Required when using `AWS_S3_BUCKET_NAME`. `AWS_DEFAULT_REGION` | | Optional when using `AWS_S3_BUCKET_NAME`. Allows you to override the AWS CLI default region. Usually not needed. diff --git a/src/backup.sh b/src/backup.sh index e6b4f89..448a067 100755 --- a/src/backup.sh +++ b/src/backup.sh @@ -84,6 +84,15 @@ if [ ! -z "$AWS_S3_BUCKET_NAME" ]; then echo "Upload finished" TIME_UPLOADED="$(date +%s.%N)" fi +if [ ! -z "$AWS_GLACIER_VAULT_NAME" ]; then + info "Uploading backup to GLACIER" + echo "Will upload to vault \"$AWS_GLACIER_VAULT_NAME\"" + TIME_UPLOAD="$(date +%s.%N)" + id + aws $AWS_EXTRA_ARGS glacier upload-archive --account-id - --vault-name "$AWS_GLACIER_VAULT_NAME" --body "$BACKUP_FILENAME" + echo "Upload finished" + TIME_UPLOADED="$(date +%s.%N)" +fi if [ -d "$BACKUP_ARCHIVE" ]; then info "Archiving backup" diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 89363ef..aba24ff 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -8,6 +8,7 @@ cat < env.sh BACKUP_SOURCES="${BACKUP_SOURCES:-/backup}" BACKUP_CRON_EXPRESSION="${BACKUP_CRON_EXPRESSION:-@daily}" AWS_S3_BUCKET_NAME="${AWS_S3_BUCKET_NAME:-}" +AWS_GLACIER_VAULT_NAME="${AWS_GLACIER_VAULT_NAME:-}" AWS_EXTRA_ARGS="${AWS_EXTRA_ARGS:-}" BACKUP_FILENAME=${BACKUP_FILENAME:-"backup-%Y-%m-%dT%H-%M-%S.tar.gz"} BACKUP_ARCHIVE="${BACKUP_ARCHIVE:-/archive}" diff --git a/test/backing-up-to-glacier/docker-compose.yml b/test/backing-up-to-glacier/docker-compose.yml new file mode 100644 index 0000000..c140a32 --- /dev/null +++ b/test/backing-up-to-glacier/docker-compose.yml @@ -0,0 +1,25 @@ +version: "3" + +services: + + dashboard: + image: grafana/grafana + ports: + - "3000:3000" + volumes: + - grafana-data:/var/lib/grafana + + backup: + build: ../.. + environment: + BACKUP_CRON_EXPRESSION: "* * * * *" + BACKUP_FILENAME: glacier-test.tar.gz + AWS_GLACIER_VAULT_NAME: Backups + AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID} + AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY} + AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION} + volumes: + - grafana-data:/backup/grafana-data:ro + +volumes: + grafana-data: From 19e73ab0d071aff1df50de37d7441705f812b8da Mon Sep 17 00:00:00 2001 From: "Ernesto R. C. Pereda" Date: Sat, 24 Oct 2020 10:59:44 -0400 Subject: [PATCH 2/2] Update src/backup.sh --- src/backup.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backup.sh b/src/backup.sh index 448a067..d03cd11 100755 --- a/src/backup.sh +++ b/src/backup.sh @@ -88,7 +88,6 @@ if [ ! -z "$AWS_GLACIER_VAULT_NAME" ]; then info "Uploading backup to GLACIER" echo "Will upload to vault \"$AWS_GLACIER_VAULT_NAME\"" TIME_UPLOAD="$(date +%s.%N)" - id aws $AWS_EXTRA_ARGS glacier upload-archive --account-id - --vault-name "$AWS_GLACIER_VAULT_NAME" --body "$BACKUP_FILENAME" echo "Upload finished" TIME_UPLOADED="$(date +%s.%N)"