diff --git a/backend/b2/api/types.go b/backend/b2/api/types.go index 46c59db75..b2aa1a7fb 100644 --- a/backend/b2/api/types.go +++ b/backend/b2/api/types.go @@ -214,9 +214,10 @@ type FileInfo struct { // CreateBucketRequest is used to create a bucket type CreateBucketRequest struct { - AccountID string `json:"accountId"` - Name string `json:"bucketName"` - Type string `json:"bucketType"` + AccountID string `json:"accountId"` + Name string `json:"bucketName"` + Type string `json:"bucketType"` + LifecycleRules []LifecycleRule `json:"lifecycleRules,omitempty"` } // DeleteBucketRequest is used to create a bucket diff --git a/backend/b2/b2.go b/backend/b2/b2.go index 7694c5dc7..f1b0acc31 100644 --- a/backend/b2/b2.go +++ b/backend/b2/b2.go @@ -210,6 +210,31 @@ The minimum value is 1 second. The maximum value is one week.`, Advanced: true, Hide: fs.OptionHideBoth, Help: `Whether to use mmap buffers in internal memory pool. (no longer used)`, + }, { + Name: "lifecycle", + Help: `Set the number of days deleted files should be kept when creating a bucket. + +On bucket creation, this parameter is used to create a lifecycle rule +for the entire bucket. + +If lifecycle is 0 (the default) it does not create a lifecycle rule so +the default B2 behaviour applies. This is to create versions of files +on delete and overwrite and to keep them indefinitely. + +If lifecycle is >0 then it creates a single rule setting the number of +days before a file that is deleted or overwritten is deleted +permanently. This is known as daysFromHidingToDeleting in the b2 docs. + +The minimum value for this parameter is 1 day. + +You can also enable hard_delete in the config also which will mean +deletions won't cause versions but overwrites will still cause +versions to be made. + +See: [rclone backend lifecycle](#lifecycle) for setting lifecycles after bucket creation. +`, + Default: 0, + Advanced: true, }, { Name: config.ConfigEncoding, Help: config.ConfigEncodingHelp, @@ -240,6 +265,7 @@ type Options struct { DisableCheckSum bool `config:"disable_checksum"` DownloadURL string `config:"download_url"` DownloadAuthorizationDuration fs.Duration `config:"download_auth_duration"` + Lifecycle int `config:"lifecycle"` Enc encoder.MultiEncoder `config:"encoding"` } @@ -1070,6 +1096,11 @@ func (f *Fs) makeBucket(ctx context.Context, bucket string) error { Name: f.opt.Enc.FromStandardName(bucket), Type: "allPrivate", } + if f.opt.Lifecycle > 0 { + request.LifecycleRules = []api.LifecycleRule{{ + DaysFromHidingToDeleting: &f.opt.Lifecycle, + }} + } var response api.Bucket err := f.pacer.Call(func() (bool, error) { resp, err := f.srv.CallJSON(ctx, &opts, &request, &response)