0

I'm storing documents in GCS and I'd like to replicate the Windows/OSX notion of files moving to a Recycle Bin/Trash upon deletion so they can be recovered, rather than outright deleting them. In other words I'd like deleted files to still be accessible for a period of time (say a month). I don't need full versioning since I just care about the oops-I-deleted-something-important use case. How should I configure a lifecycle policy to support this while minimizing storage overhead?

1

To start, enabling versioning for your bucket will ensure nothing a user accidentally deletes is lost.

$ gsutil versioning set on gs://bucket

This is overkill though; we only care about the previous version of a file so we'll let GCS clean up unneeded versions with lifecycle management. First we can clean up any long-deleted content with a lifecycle rule like so:

{
  "action": {"type": "Delete"},
  "condition": {"isLive": false, "age": 30}
}

The next step is to clean up unnecessary versions that are younger than the date cutoff. If you only want to keep around an archived revision of deleted files, use this rule:

{
  "action": {"type": "Delete"},
  "condition": {"isLive": false, "numNewerVersions": 1}
}

For files that still exist, all archived versions will be deleted (since there's a newer, live, version), while for files that were deleted the most recently archived version will be the newest, and therefore won't be deleted. This is, in effect, a recycle bin.

If instead you'd like to keep around a prior version for all files you'd just tweak numNewerVersions to 2, however this would cause deleted files to keep around the past two revisions, rather than just one. Since there isn't a NumberOfNewerArchivedVersions condition you can't have it both ways and keep around exactly one archived version of any file, deleted or not.

0

I don't see how this would be possible at the moment. The Age lifecycle condition tests the object creation time which doesn't seem to be modified when deleting an object. Using

{
  "action": {"type": "Delete"},
  "condition": {"isLive": false, "age": 30}
}

won't work: If you upload an object to a bucket, keep it there for 30 days and then delete it, the lifecycle management will instantly (+ lag) delete the archived version, as the archived versions age is bigger than 30 days at this point. There doesn't seem to be any condition related to deletion time, so there is no way to use it in a lifecycle condition.

  • Ah, good to know, I didn't realize deletion didn't count as an age-affecting event. – dimo414 Jun 29 '16 at 21:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.