문제 설명
GCS 버킷에서 큰 폴더를 삭제하는 빠른 방법 (Fast way to delete big folder on GCS bucket)
저에게는 몇 테라바이트의 데이터가 있는 여러 하위 디렉토리가 있는 매우 큰 GCS 버킷(몇 TB)이 있습니다.
이 폴더 중 일부를 삭제하고 싶습니다.
Cloud Shell에서 gsutil
을 사용하려고 했지만 시간이 오래 걸립니다.
참고로 사용 중인 명령은 다음과 같습니다.
gsutil ‑m rm ‑r "gs://BUCKET_NAME/FOLDER"
이 질문을 보고 사용할 수 있다고 생각했지만 폴더 이름으로 필터링할 수 없는 것 같고 필터링할 수 없습니다. 폴더에 혼합된 콘텐츠가 있기 때문에 다른 방법으로 사용할 수 있습니다.
지금까지 나의 마지막 수단은 삭제하려는 폴더가 "오래된" 폴더가 될 때까지 기다리는 것입니다.
참조 솔루션
방법 1:
It's just going to take a long time; you have to issue a DELETE request for each object with the prefix FOLDER/
.
GCS doesn't have the concept of "folders". Object names can share a common prefix, but they're all in a flat namespace. For example, if you have these three objects:
- /a/b/c/1.txt
- /a/b/c/2.txt
- /a/b/c/3.txt
...then you don't actually have folders named a
, b
, or c
. Once you deleted those three objects, the "folders" (i.e. the prefix that they shared) would no longer appear when you listed objects in your bucket.
See the docs for more details:
https://cloud.google.com/storage/docs/gsutil/addlhelp/HowSubdirectoriesWork
방법 2:
Creating a lifecycle rule with a matchesPrefix as the folder name is the best way to remove large folders in a bucket. It does take up to 24 hours to have an effect though. https://cloud.google.com/storage/docs/lifecycle#matchesprefix‑suffix