Luke
Luke

Reputation: 7099

gsutil to list all files in a bucket that have been deleted

How do you list all objects in a bucket that have been deleted when object versioning has been enabled? I'd like to use gsutil for this if possible.

Edit: It seems like there is no built in tool to do this. Could there perhaps be a way to do it via some combination of gsutil and another bash tool?

When you have a large amount of files, listing all versions is too much information and obscures what one might be looking for: do I have any deleted files and should I permanently delete them or restore them.

Upvotes: 4

Views: 3746

Answers (3)

Steven Ensslen
Steven Ensslen

Reputation: 1386

Since November 2023 (GCloud 454.0.0), gcloud storage ls gs://path --soft-deleted shows the soft-deleted blobs.

The fully deleted blobs are gone, as is their metadata.

Upvotes: 1

Artemis Georgakopoulou
Artemis Georgakopoulou

Reputation: 1221

When working with Object Versioning in GCP, the only documented command to list archived objects, is the one listing both live and archived versions of an object and view their generation numbers, as aforementioned by @mhouglum.

gsutil ls -a gs://[BUCKET_NAME]

However, there are some additional flags, that can help you identify the archived objects. You can use the -L flag along with the -a flag. This command will give you the Archived Time for non-live versions of an object, but not for the live ones. Example:

Archived object

enter image description here

Live object

enter image description here

When an object has been permanently deleted, you can not list it anymore and the only way to view this operation deletion is by visiting the Logs.

Upvotes: 2

mhouglum
mhouglum

Reputation: 2593

Running gsutil help ls shows that the -a flag will do this:

  -a          Includes non-current object versions / generations in the listing
              (only useful with a versioning-enabled bucket). If combined with
              -l option also prints metageneration for each listed object.

Note that this will show objects that were deleted while versioning was enabled. If an object is deleted when versioning is not turned on, it is permanently deleted.

Upvotes: 5

Related Questions