Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting Cloud Storage Objects in Batch

Whats the best way to delete many cloudstorage objects? I have a bucket that contains ~500K objects and I'd like to delete them all.

Do you I have to make 1 api request for each object I want to delete or is there some sort of batch method? I'm currently using gsutil to delete one at a time.

like image 489
aloo Avatar asked Feb 18 '23 12:02

aloo


2 Answers

You need to make 1 api request for each object. The simplest way to accomplish this would be with gsutil:

$ gsutil -m rm gs://bucket_with_many_objects/**

The -m option enables multithreading, which will delete many objects in parallel.

like image 56
Brandon Yarbrough Avatar answered Feb 20 '23 03:02

Brandon Yarbrough


Note that with gsutil the "*" wildcard will only match the top-level objects (up to the next "/" in the path name). If you want to delete all the objects you can either use:

$ gsutil -m rm -R gs://bucket_with_many_objects

or

$ gsutil -m rm gs://bucket_with_many_objects/**

Mike Schwartz, Google Cloud Storage Team

like image 32
Mike Schwartz Avatar answered Feb 20 '23 03:02

Mike Schwartz