From df500a372d982e23d8d665a4fdf7e426207827fd Mon Sep 17 00:00:00 2001 From: mdauphin Date: Tue, 23 Jul 2019 11:14:26 +0200 Subject: [PATCH 1/4] Add AWS_REGION env var to specify s3 region --- cmd/restic/global.go | 4 ++++ internal/backend/s3/config.go | 1 + internal/backend/s3/s3.go | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/restic/global.go b/cmd/restic/global.go index e0d94814b..f2e7c7517 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -485,6 +485,10 @@ func parseConfig(loc location.Location, opts options.Options) (interface{}, erro cfg.Secret = os.Getenv("AWS_SECRET_ACCESS_KEY") } + if cfg.Region == "" { + cfg.Region = os.Getenv("AWS_REGION") + } + if err := opts.Apply(loc.Scheme, &cfg); err != nil { return nil, err } diff --git a/internal/backend/s3/config.go b/internal/backend/s3/config.go index 932806714..472d79e4a 100644 --- a/internal/backend/s3/config.go +++ b/internal/backend/s3/config.go @@ -22,6 +22,7 @@ type Config struct { Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"` MaxRetries uint `option:"retries" help:"set the number of retries attempted"` + Region string } // NewConfig returns a new Config with the default values filled in. diff --git a/internal/backend/s3/s3.go b/internal/backend/s3/s3.go index 02eda53be..acdb1bc4f 100644 --- a/internal/backend/s3/s3.go +++ b/internal/backend/s3/s3.go @@ -66,7 +66,7 @@ func open(cfg Config, rt http.RoundTripper) (*Backend, error) { }, }, }) - client, err := minio.NewWithCredentials(cfg.Endpoint, creds, !cfg.UseHTTP, "") + client, err := minio.NewWithCredentials(cfg.Endpoint, creds, !cfg.UseHTTP, cfg.Region) if err != nil { return nil, errors.Wrap(err, "minio.NewWithCredentials") } From 409909a7f5db65561fa97734edc95504e847b5d0 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 22 Nov 2019 15:09:09 +0100 Subject: [PATCH 2/4] Add option description for Region --- internal/backend/s3/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/backend/s3/config.go b/internal/backend/s3/config.go index 472d79e4a..499e05094 100644 --- a/internal/backend/s3/config.go +++ b/internal/backend/s3/config.go @@ -20,9 +20,9 @@ type Config struct { Layout string `option:"layout" help:"use this backend layout (default: auto-detect)"` StorageClass string `option:"storage-class" help:"set S3 storage class (STANDARD, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING or REDUCED_REDUNDANCY)"` - Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"` - MaxRetries uint `option:"retries" help:"set the number of retries attempted"` - Region string + Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"` + MaxRetries uint `option:"retries" help:"set the number of retries attempted"` + Region string `option:"region" help:"set region"` } // NewConfig returns a new Config with the default values filled in. From 4cadc89ad3beaf0d1b21f805e42100c5b8cc1ad0 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 22 Nov 2019 15:16:59 +0100 Subject: [PATCH 3/4] Add documentation and changelog --- changelog/unreleased/pull-2350 | 8 ++++++++ doc/030_preparing_a_new_repo.rst | 9 +++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 changelog/unreleased/pull-2350 diff --git a/changelog/unreleased/pull-2350 b/changelog/unreleased/pull-2350 new file mode 100644 index 000000000..32dd89c4b --- /dev/null +++ b/changelog/unreleased/pull-2350 @@ -0,0 +1,8 @@ +Enhancement: Add option to configure S3 region + +We've added a new option for setting the region when accessing an S3-compatible +service. For some providers, it is required to set this to a valid value. You +can do that either by setting the environment variable `AWS_REGION` or using +the option `s3.region`, e.g. like this: `-o s3.region="us-east-1"`. + +https://github.com/restic/restic/pull/2350 diff --git a/doc/030_preparing_a_new_repo.rst b/doc/030_preparing_a_new_repo.rst index a72b10ffa..1d854e571 100644 --- a/doc/030_preparing_a_new_repo.rst +++ b/doc/030_preparing_a_new_repo.rst @@ -197,10 +197,11 @@ default location: Please note that knowledge of your password is required to access the repository. Losing your password means that your data is irrecoverably lost. -It is not possible at the moment to have restic create a new bucket in a -different location, so you need to create it using a different program. -Afterwards, the S3 server (``s3.amazonaws.com``) will redirect restic to -the correct endpoint. +If needed, you can manually specify the region to use by either setting the +environment variable ``AWS_REGION`` or calling restic with an option parameter +like ``-o s3.region="us-east-1"``. If the region is not specified, the default +region is used. Afterwards, the S3 server (``s3.amazonaws.com``) will redirect +restic to the correct endpoint. Until version 0.8.0, restic used a default prefix of ``restic``, so the files in the bucket were placed in a directory named ``restic``. If you want to From fb95426f64afd1e9145607d39fe55d89b83b0d3c Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 22 Nov 2019 15:24:42 +0100 Subject: [PATCH 4/4] Rename environment variable to AWS_DEFAULT_REGION This seems to be the correct name, at least the AWS cli uses it: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html --- changelog/unreleased/pull-2350 | 4 ++-- cmd/restic/global.go | 2 +- doc/030_preparing_a_new_repo.rst | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/changelog/unreleased/pull-2350 b/changelog/unreleased/pull-2350 index 32dd89c4b..0068f542f 100644 --- a/changelog/unreleased/pull-2350 +++ b/changelog/unreleased/pull-2350 @@ -2,7 +2,7 @@ Enhancement: Add option to configure S3 region We've added a new option for setting the region when accessing an S3-compatible service. For some providers, it is required to set this to a valid value. You -can do that either by setting the environment variable `AWS_REGION` or using -the option `s3.region`, e.g. like this: `-o s3.region="us-east-1"`. +can do that either by setting the environment variable `AWS_DEFAULT_REGION` or +using the option `s3.region`, e.g. like this: `-o s3.region="us-east-1"`. https://github.com/restic/restic/pull/2350 diff --git a/cmd/restic/global.go b/cmd/restic/global.go index f2e7c7517..4001e7720 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -486,7 +486,7 @@ func parseConfig(loc location.Location, opts options.Options) (interface{}, erro } if cfg.Region == "" { - cfg.Region = os.Getenv("AWS_REGION") + cfg.Region = os.Getenv("AWS_DEFAULT_REGION") } if err := opts.Apply(loc.Scheme, &cfg); err != nil { diff --git a/doc/030_preparing_a_new_repo.rst b/doc/030_preparing_a_new_repo.rst index 1d854e571..bbe729bc1 100644 --- a/doc/030_preparing_a_new_repo.rst +++ b/doc/030_preparing_a_new_repo.rst @@ -198,10 +198,10 @@ default location: Losing your password means that your data is irrecoverably lost. If needed, you can manually specify the region to use by either setting the -environment variable ``AWS_REGION`` or calling restic with an option parameter -like ``-o s3.region="us-east-1"``. If the region is not specified, the default -region is used. Afterwards, the S3 server (``s3.amazonaws.com``) will redirect -restic to the correct endpoint. +environment variable ``AWS_DEFAULT_REGION`` or calling restic with an option +parameter like ``-o s3.region="us-east-1"``. If the region is not specified, +the default region is used. Afterwards, the S3 server (at least for AWS, +``s3.amazonaws.com``) will redirect restic to the correct endpoint. Until version 0.8.0, restic used a default prefix of ``restic``, so the files in the bucket were placed in a directory named ``restic``. If you want to