2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Cloudflare R2 のバケツ容量を取る。AWS CLI で。

2
Posted at

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のやつ>

Cloudfalre の Dev Doc
Classmethod さん Blog

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. 結果

容量によって時間かかる:tea:

~/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

ありがとうございます。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?