Search code examples
google-cloud-storage

What is the quickest way to delete many blobs from GCS?


I have a bucket containing many millions of blobs that I want to delete however I can't simply delete the bucket. This is the best method I have come up with to delete millions of blobs in the quickest time possible:

gsutil ls gs://bucket/path/to/dir/ | xargs gsutil -m rm -r

For what I want to do (which involves removing about 30million blobs) it still takes many hours to run, partly I guess because its at the mercy of the speed of my broadband connection.

Anyone know of a quicker way of achieving this? I had kinda hoped it'd be an instantaneous operation as in the backend the location could simply be marked as deleted - clearly not.


Solution

  • Google recommend using the console to do this

    The Cloud Console can bulk delete up to several million objects and does so in the background. The Cloud Console can also be used to bulk delete only those objects that share a common prefix, which appear as part of a folder when using the Cloud Console.

    https://cloud.google.com/storage/docs/best-practices#deleting

    That said (personal opinion here) using the console might be quicker but you haven't a clue how far its got. At least with cli option you do know.