mirror of
https://github.com/restic/restic.git
synced 2025-08-22 13:51:45 +00:00
gs: support other regions than us
This commit is contained in:
@@ -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",
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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",
|
||||
}},
|
||||
}
|
||||
|
||||
|
@@ -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")
|
||||
}
|
||||
|
Reference in New Issue
Block a user