Google 클라우드 저장소에 버킷이 있습니다. 버킷에 tmp 폴더가 있습니다. 이 디렉토리에는 매일 수천 개의 파일이 생성됩니다. 매일 밤 1 일보다 오래된 파일을 삭제하고 싶습니다. 나는이 직업에 대해 gsutil에 대한 논쟁을 찾을 수 없었다. 이렇게하기 위해서는 고전적이고 간단한 쉘 스크립트를 사용해야했습니다. 그러나 파일은 매우 느리게 삭제됩니다.마지막 날부터 이전 파일을 삭제하는 gsutil 명령
폴더에 650,000 개의 파일이 있습니다. 540K는 삭제해야합니다. 그러나 내 자신의 쉘 스크립트는 하루 동안 작동하고 단지 34K 파일을 삭제할 수 있습니다.
gsutil주기 기능은 내가 원하는 것을 정확하게 수행 할 수 없습니다. 그는 양동이를 청소하고 있습니다. 난 그냥 특정 폴더의 하단에있는 파일을 정기적으로 삭제하고 싶습니다 .. 동시에 내가 빨리 삭제 싶어요.
귀하의 제안과 도움을 드리지 않습니다. 단일 gsutil 명령으로이 작업을 수행 할 수 있습니까? 또는 다른 방법? 내가 테스트를 위해 만든
간단한 스크립트 (I 일시적으로 대량 파일을 삭제하기 위해 준비했다.)
## step 1 - I pull the files together with the date format and save them to the file list1.txt.
gsutil -m ls -la gs://mygooglecloudstorage/tmp/ | awk '{print $2,$3}' > /tmp/gsutil-tmp-files/list1.txt
## step 2 - I filter the information saved in the file list1.txt. Based on the current date, I save the old dated files to file list2.txt.
cat /tmp/gsutil-tmp-files/list1.txt | awk -F "T" '{print $1,$2,$3}' | awk '{print $1,$3}' | awk -F "#" '{print $1}' |grep -v `date +%F` |sort -bnr > /tmp/gsutil-tmp-files/list2.txt
## step 3 - After the above process, I add the gsutil delete command to the first line and convert it into a shell script.
cat /tmp/gsutil-tmp-files/list2.txt | awk '{$1 = "/root/google-cloud-sdk/bin/gsutil -m rm -r "; print}' > /tmp/gsutil-tmp-files/remove-old-files.sh
## step 4 - I'm set the script permissions and delete old lists.
chmod 755 /tmp/gsutil-tmp-files/remove-old-files.sh
rm -rf /tmp/gsutil-tmp-files/list1.txt /tmp/gsutil-tmp-files/list2.txt
## step 5 - I run the shell script and I destroy it after it is done.
/bin/sh /tmp/gsutil-tmp-files/remove-old-files.sh
rm -rf /tmp/gsutil-tmp-files/remove-old-files.sh
내가 gcsfuse 도구를 사용하여 내 버킷을 장착하여이 문제를 해결했다. 이제 로컬 디스크처럼 버킷을 관리 할 수 있습니다. 그러나 디스크에서 많은 작업을 수행하는 것은 여전히 느립니다. 그래도 지금은 빨리 취소 할 수 있습니다. gcsfuse에 대한 자세한 내용은을 (를) 참조하십시오. https://cloud.google.com/storage/docs/gcs-fuse 하지만 Google은 이러한 요구에 맞는 자동 솔루션이 필요하다고 생각합니다. 비슷한 문제가있는 사용자는이 방법을 사용할 수 있습니다. 나는 이와 관련하여 더 나은 방법을 가진 사람들의 새로운 아이디어에 대해 개방적이다. – spala