From ed5b2c2c9b094609345c05c6f809b7ccda9e939c Mon Sep 17 00:00:00 2001 From: sohalt Date: Mon, 27 Feb 2023 07:53:25 +0100 Subject: [PATCH 1/2] gs: support other regions than us --- changelog/unreleased/pull-4226 | 6 ++++++ doc/030_preparing_a_new_repo.rst | 2 ++ internal/backend/gs/config.go | 4 +++- internal/backend/gs/config_test.go | 3 +++ internal/backend/gs/gs.go | 7 ++++++- 5 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/pull-4226 diff --git a/changelog/unreleased/pull-4226 b/changelog/unreleased/pull-4226 new file mode 100644 index 000000000..4b5be4655 --- /dev/null +++ b/changelog/unreleased/pull-4226 @@ -0,0 +1,6 @@ +Enhancement: Allow to specify region where a bucket should get created in the gcs backend + +Buckets used by the Google Cloud Storage backend would always get created in the "us" region. +It is now possible to specify the region, where a bucket should get created. + +https://github.com/restic/restic/pull/4226 diff --git a/doc/030_preparing_a_new_repo.rst b/doc/030_preparing_a_new_repo.rst index 44223c146..a871ee507 100644 --- a/doc/030_preparing_a_new_repo.rst +++ b/doc/030_preparing_a_new_repo.rst @@ -613,6 +613,8 @@ The number of concurrent connections to the GCS service can be set with the ``-o gs.connections=10`` switch. By default, at most five parallel connections are established. +The region, where a bucket should be created, can be specified with the ``-o gs.region=us`` switch. By default, the region is set to ``us``. + .. _service account: https://cloud.google.com/iam/docs/service-account-overview .. _create a service account key: https://cloud.google.com/iam/docs/keys-create-delete .. _default authentication material: https://cloud.google.com/docs/authentication#service-accounts diff --git a/internal/backend/gs/config.go b/internal/backend/gs/config.go index 33aec4c99..8bb2bddea 100644 --- a/internal/backend/gs/config.go +++ b/internal/backend/gs/config.go @@ -16,13 +16,15 @@ type Config struct { Bucket string Prefix string - Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"` + Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"` + Region string `option:"region" help:"region to create the bucket in (default: us)"` } // NewConfig returns a new Config with the default values filled in. func NewConfig() Config { return Config{ Connections: 5, + Region: "us", } } diff --git a/internal/backend/gs/config_test.go b/internal/backend/gs/config_test.go index fb03e3a20..fb2774d25 100644 --- a/internal/backend/gs/config_test.go +++ b/internal/backend/gs/config_test.go @@ -10,16 +10,19 @@ var configTests = []struct { Bucket: "bucketname", Prefix: "", Connections: 5, + Region: "us", }}, {"gs:bucketname:/prefix/directory", Config{ Bucket: "bucketname", Prefix: "prefix/directory", Connections: 5, + Region: "us", }}, {"gs:bucketname:/prefix/directory/", Config{ Bucket: "bucketname", Prefix: "prefix/directory", Connections: 5, + Region: "us", }}, } diff --git a/internal/backend/gs/gs.go b/internal/backend/gs/gs.go index 62e5c4954..7b5489111 100644 --- a/internal/backend/gs/gs.go +++ b/internal/backend/gs/gs.go @@ -37,6 +37,7 @@ type Backend struct { projectID string connections uint bucketName string + region string bucket *storage.BucketHandle prefix string listMaxItems int @@ -102,6 +103,7 @@ func open(cfg Config, rt http.RoundTripper) (*Backend, error) { projectID: cfg.ProjectID, connections: cfg.Connections, bucketName: cfg.Bucket, + region: cfg.Region, bucket: gcsClient.Bucket(cfg.Bucket), prefix: cfg.Prefix, Layout: &layout.DefaultLayout{ @@ -142,8 +144,11 @@ func Create(ctx context.Context, cfg Config, rt http.RoundTripper) (restic.Backe } if !exists { + bucketAttrs := &storage.BucketAttrs{ + Location: cfg.Region, + } // Bucket doesn't exist, try to create it. - if err := be.bucket.Create(ctx, be.projectID, nil); err != nil { + if err := be.bucket.Create(ctx, be.projectID, bucketAttrs); err != nil { // Always an error, as the bucket definitely doesn't exist. return nil, errors.Wrap(err, "service.Buckets.Insert") } From 06894484a18fd7185c364db77b87ccc8a4244408 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 26 May 2023 20:05:49 +0200 Subject: [PATCH 2/2] shorten changelog title --- changelog/unreleased/pull-4226 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/changelog/unreleased/pull-4226 b/changelog/unreleased/pull-4226 index 4b5be4655..69c848735 100644 --- a/changelog/unreleased/pull-4226 +++ b/changelog/unreleased/pull-4226 @@ -1,6 +1,7 @@ -Enhancement: Allow to specify region where a bucket should get created in the gcs backend +Enhancement: Allow specifying the region of new buckets in the gcs backend -Buckets used by the Google Cloud Storage backend would always get created in the "us" region. -It is now possible to specify the region, where a bucket should get created. +Buckets used by the Google Cloud Storage backend would always get created in +the "us" region. It is now possible to specify the region, where a bucket +should get created. https://github.com/restic/restic/pull/4226