R2 のバケツ量をとる
AWS CLI を使う。
1. credential を作る
~/AWS $ aws configure --profile cfr2
aws configure
AWS Access Key ID [None]: <R2のやつ>
AWS Secret Access Key [None]: <R2のやつ>
Default region name [None]: auto
Default output format [None]: json
~/AWS $ cat ~/.aws/credentials
[cfr2]
aws_access_key_id = <R2のやつ>
aws_secret_access_key = <R2のやつ>
2. AWS用の script を編集する
#!/bin/bash
set +x
PROFILE="< ↑cred のプロファイル名 >"
ACCOUNTID="< Cloudflare のアカウント ID >"
R2END="https://${ACCOUNTID}.r2.cloudflarestorage.com"
function calcs3bucketsize() {
sizeInBytes=`aws --profile ${PROFILE} s3 ls s3://"${1}" --recursive --human-readable --summarize --endpoint-url ${R2END} | awk END'{print}'`
echo ${1},${sizeInBytes} >> allregions-buckets-s3-sizes.csv
printf "DONE. Size of the bucket ${1}. %s\n " "${sizeInBytes}"
}
[ -f allregions-buckets-s3-sizes.csv ] && rm -fr allregions-buckets-s3-sizes.csv
buckets=`aws --profile ${PROFILE} s3 ls --endpoint-url ${R2END} | awk '{print $3}'`
i=1
for j in ${buckets}; do
printf "calculating the size of the bucket[%s]=%s. \n " "${i}" "${j}"
i=$((i+1))
# to expedite the calculation, make the cli commands run parallel in the background
calcs3bucketsize ${j} &
done
こちらから引用元してます AWS 文書
3. 結果
容量によって時間かかる![]()
~/AWS $ ./r2.bucket.size.sh
calculating the size of the bucket[1]=logpush.
calculating the size of the bucket[2]=logpush-workers.
%
~/AWS $ DONE. Size of the bucket logpush-workers. Total Size: 58.7 KiB
DONE. Size of the bucket logpush. Total Size: 789.2 MiB
ありがとうございます。