Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

b2: cleanup unfinished large files

Garry McNulty887834da915b
diff --git a/backend/b2/b2.go b/backend/b2/b2.go
index 77c2c5277..048f6b804 100644
--- a/backend/b2/b2.go
+++ b/backend/b2/b2.go
@@ -980,6 +980,12 @@ func (f *Fs) purge(oldOnly bool) error {
errReturn = err
}
}
+ var isUnfinishedUploadStale = func(timestamp api.Timestamp) bool {
+ if time.Since(time.Time(timestamp)).Hours() > 24 {
+ return true
+ }
+ return false
+ }
// Delete Config.Transfers in parallel
toBeDeleted := make(chan *api.File, fs.Config.Transfers)
@@ -1003,6 +1009,9 @@ func (f *Fs) purge(oldOnly bool) error {
if object.Action == "hide" {
fs.Debugf(remote, "Deleting current version (id %q) as it is a hide marker", object.ID)
toBeDeleted <- object
+ } else if object.Action == "start" && isUnfinishedUploadStale(object.UploadTimestamp) {
+ fs.Debugf(remote, "Deleting current version (id %q) as it is a start marker (upload started at %s)", object.ID, time.Time(object.UploadTimestamp).Local())
+ toBeDeleted <- object
} else {
fs.Debugf(remote, "Not deleting current version (id %q) %q", object.ID, object.Action)
}
diff --git a/docs/content/b2.md b/docs/content/b2.md
index a7fecae25..25be69bab 100644
--- a/docs/content/b2.md
+++ b/docs/content/b2.md
@@ -181,8 +181,8 @@ versions of files, leaving the current ones intact. You can also
supply a path and only old versions under that path will be deleted,
eg `rclone cleanup remote:bucket/path/to/stuff`.
-Note that `cleanup` does not remove partially uploaded files
-from the bucket.
+Note that `cleanup` will remove partially uploaded files from the bucket
+if they are more than a day old.
When you `purge` a bucket, the current and the old versions will be
deleted then the bucket will be deleted.