From 479ce83f5c2714349c9db830f8f7abd8b973ce51 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Sun, 26 Apr 2020 22:48:35 +0530 Subject: [PATCH] fix: required region s3 compatible backup/restore --- README.md | 4 ++++ build/common/commands/push_backup.py | 6 ++++++ build/common/commands/restore_backup.py | 1 + 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index eeb18692..9b87e994 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,7 @@ The backup will be available in the `sites-vol` volume. Environment Variables - `BUCKET_NAME`, Required to set bucket created on S3 compatible storage. +- `REGION`, Required to set region for S3 compatible storage. - `ACCESS_KEY_ID`, Required to set access key. - `SECRET_ACCESS_KEY`, Required to set secret access key. - `ENDPOINT_URL`, Required to set URL of S3 compatible storage. @@ -268,6 +269,7 @@ Environment Variables ```sh docker run \ -e "BUCKET_NAME=backups" \ + -e "REGION=region" \ -e "ACCESS_KEY_ID=access_id_from_provider" \ -e "SECRET_ACCESS_KEY=secret_access_from_provider" \ -e "ENDPOINT_URL=https://region.storage-provider.com" \ @@ -320,12 +322,14 @@ Environment Variables - `ACCESS_KEY_ID`, Required to set access key. - `SECRET_ACCESS_KEY`, Required to set secret access key. - `ENDPOINT_URL`, Required to set URL of S3 compatible storage. +- `REGION`, Required to set region for s3 compatible storage. - `BUCKET_DIR`, Required to set directory in bucket where sites from this deployment will be backed up. ```sh docker run \ -e "MYSQL_ROOT_PASSWORD=admin" \ -e "BUCKET_NAME=backups" \ + -e "REGION=region" \ -e "ACCESS_KEY_ID=access_id_from_provider" \ -e "SECRET_ACCESS_KEY=secret_access_from_provider" \ -e "ENDPOINT_URL=https://region.storage-provider.com" \ diff --git a/build/common/commands/push_backup.py b/build/common/commands/push_backup.py index e795b3ef..26b5c464 100644 --- a/build/common/commands/push_backup.py +++ b/build/common/commands/push_backup.py @@ -47,6 +47,7 @@ def get_s3_config(): conn = boto3.client( 's3', + region_name=os.environ.get('REGION'), aws_access_key_id=os.environ.get('ACCESS_KEY_ID'), aws_secret_access_key=os.environ.get('SECRET_ACCESS_KEY'), endpoint_url=os.environ.get('ENDPOINT_URL') @@ -75,6 +76,10 @@ def check_environment_variables(): print('Variable BUCKET_DIR not set') exit(1) + if not 'REGION' in os.environ: + print('Variable REGION not set') + exit(1) + def upload_file_to_s3(filename, folder, conn, bucket): destpath = os.path.join(folder, os.path.basename(filename)) @@ -96,6 +101,7 @@ def delete_old_backups(limit, bucket, site_name): s3 = boto3.resource( 's3', + region_name=os.environ.get('REGION'), aws_access_key_id=os.environ.get('ACCESS_KEY_ID'), aws_secret_access_key=os.environ.get('SECRET_ACCESS_KEY'), endpoint_url=os.environ.get('ENDPOINT_URL') diff --git a/build/common/commands/restore_backup.py b/build/common/commands/restore_backup.py index f248bbf7..38c1494b 100644 --- a/build/common/commands/restore_backup.py +++ b/build/common/commands/restore_backup.py @@ -121,6 +121,7 @@ def pull_backup_from_s3(): # https://stackoverflow.com/a/54672690 s3 = boto3.resource( 's3', + region_name=os.environ.get('REGION'), aws_access_key_id=os.environ.get('ACCESS_KEY_ID'), aws_secret_access_key=os.environ.get('SECRET_ACCESS_KEY'), endpoint_url=os.environ.get('ENDPOINT_URL')