diff --git a/changelog/unreleased/pull-2350 b/changelog/unreleased/pull-2350 new file mode 100644 index 000000000..0068f542f --- /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_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 e0d94814b..4001e7720 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_DEFAULT_REGION") + } + if err := opts.Apply(loc.Scheme, &cfg); err != nil { return nil, err } diff --git a/doc/030_preparing_a_new_repo.rst b/doc/030_preparing_a_new_repo.rst index a72b10ffa..bbe729bc1 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_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 diff --git a/internal/backend/s3/config.go b/internal/backend/s3/config.go index 932806714..499e05094 100644 --- a/internal/backend/s3/config.go +++ b/internal/backend/s3/config.go @@ -20,8 +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"` + 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. diff --git a/internal/backend/s3/s3.go b/internal/backend/s3/s3.go index b71ef8ab6..770af02f3 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") }