mirror of
https://github.com/rclone/rclone
synced 2024-12-28 21:03:45 +01:00
b2: implement --b2-lifecycle to control lifecycle when creating buckets
This commit is contained in:
parent
d6722607cb
commit
9277ca1e54
@ -214,9 +214,10 @@ type FileInfo struct {
|
|||||||
|
|
||||||
// CreateBucketRequest is used to create a bucket
|
// CreateBucketRequest is used to create a bucket
|
||||||
type CreateBucketRequest struct {
|
type CreateBucketRequest struct {
|
||||||
AccountID string `json:"accountId"`
|
AccountID string `json:"accountId"`
|
||||||
Name string `json:"bucketName"`
|
Name string `json:"bucketName"`
|
||||||
Type string `json:"bucketType"`
|
Type string `json:"bucketType"`
|
||||||
|
LifecycleRules []LifecycleRule `json:"lifecycleRules,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteBucketRequest is used to create a bucket
|
// DeleteBucketRequest is used to create a bucket
|
||||||
|
@ -210,6 +210,31 @@ The minimum value is 1 second. The maximum value is one week.`,
|
|||||||
Advanced: true,
|
Advanced: true,
|
||||||
Hide: fs.OptionHideBoth,
|
Hide: fs.OptionHideBoth,
|
||||||
Help: `Whether to use mmap buffers in internal memory pool. (no longer used)`,
|
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,
|
Name: config.ConfigEncoding,
|
||||||
Help: config.ConfigEncodingHelp,
|
Help: config.ConfigEncodingHelp,
|
||||||
@ -240,6 +265,7 @@ type Options struct {
|
|||||||
DisableCheckSum bool `config:"disable_checksum"`
|
DisableCheckSum bool `config:"disable_checksum"`
|
||||||
DownloadURL string `config:"download_url"`
|
DownloadURL string `config:"download_url"`
|
||||||
DownloadAuthorizationDuration fs.Duration `config:"download_auth_duration"`
|
DownloadAuthorizationDuration fs.Duration `config:"download_auth_duration"`
|
||||||
|
Lifecycle int `config:"lifecycle"`
|
||||||
Enc encoder.MultiEncoder `config:"encoding"`
|
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),
|
Name: f.opt.Enc.FromStandardName(bucket),
|
||||||
Type: "allPrivate",
|
Type: "allPrivate",
|
||||||
}
|
}
|
||||||
|
if f.opt.Lifecycle > 0 {
|
||||||
|
request.LifecycleRules = []api.LifecycleRule{{
|
||||||
|
DaysFromHidingToDeleting: &f.opt.Lifecycle,
|
||||||
|
}}
|
||||||
|
}
|
||||||
var response api.Bucket
|
var response api.Bucket
|
||||||
err := f.pacer.Call(func() (bool, error) {
|
err := f.pacer.Call(func() (bool, error) {
|
||||||
resp, err := f.srv.CallJSON(ctx, &opts, &request, &response)
|
resp, err := f.srv.CallJSON(ctx, &opts, &request, &response)
|
||||||
|
Loading…
Reference in New Issue
Block a user