program tip

AWS S3 : 사용중인 디스크 공간을 확인하려면 어떻게해야합니까?

radiobox 2020. 8. 21. 07:31
반응형

AWS S3 : 사용중인 디스크 공간을 확인하려면 어떻게해야합니까?


AWS 계정이 있습니다. S3를 사용하여 다른 서버의 백업을 저장하고 있습니다. 질문은 AWS 콘솔에 S3 클라우드에서 얼마나 많은 디스크 스파 스가 사용되는지에 대한 정보가 있습니까?


Yippe-AWS CLI 업데이트를 통해 버킷을 통해 재귀 적으로 ls ...

aws s3 ls s3://<bucketname> --recursive  | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}'

원래 질문이 3 년 전이라는 점을 감안할 때 이것이 AWSCLI에 언제 추가되었는지 확실하지 않지만 명령 줄 도구는 다음을 실행하여 멋진 요약을 제공합니다.

aws s3 ls s3://mybucket --recursive --human-readable --summarize

AWS 콘솔을 사용하여 S3 버킷의 크기를 확인하려면 :

  1. S3 버킷 이름을 클릭합니다.
  2. "관리"탭을 선택합니다.
  3. "메트릭"탐색 버튼을 클릭합니다.
  4. 기본적으로 버킷의 저장소 측정 항목이 표시됩니다.

도움이 되었기를 바랍니다.


s3cmd는를 실행 s3cmd du하고 선택적으로 버킷 이름을 인수로 전달하여 이를 표시 할 수 있습니다 .


이제 AWS CLI --queryJMESPath 표현식을 사용 하는 파라미터를 지원합니다 .

이 방법은 당신에 의해 주어진 크기 값의 합 수 있습니다 list-objects사용 sum(Contents[].Size)과 같은 계산을 length(Contents[]).

이는 아래와 같이 공식 AWS CLI를 사용하여 실행할 수 있으며 2014 년 2 월 에 도입되었습니다.

 aws s3api list-objects --bucket BUCKETNAME --output json --query "[sum(Contents[].Size), length(Contents[])]"

python( pip설치 프로그램 포함) grepawkAWS CLI (EC2, S3 및 기타 여러 서비스 용 명령 줄 도구 ) 가있는 Linux 상자에서

sudo pip install awscli

그런 다음 .awssecret아래와 같은 내용으로 홈 폴더에 파일 을 만듭니다 (필요에 따라 키, 암호 및 지역 조정).

[default]
aws_access_key_id=<YOUR_KEY_HERE>
aws_secret_access_key=<YOUR_SECRET_KEY_HERE>
region=<AWS_REGION>

이 파일을 사용자에게만 읽기 / 쓰기로 만듭니다.

sudo chmod 600 .awssecret

환경으로 내보내십시오.

 export AWS_CONFIG_FILE=/home/<your_name>/.awssecret

그런 다음 터미널에서 실행합니다 ( \여기에서 쉽게 읽을 수 있도록로 구분 된 한 줄 명령 ).

aws s3 ls s3://<bucket_name>/foo/bar | \
grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | \
awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}'
  • aws부분 (임의로 또는 "서브 폴더") 버킷 나열
  • grep(사용 부품 제거합니다 -v) 정규 표현식 (사용하여 일치하는 라인 -E). ^$빈 줄, --출력의 구분 줄aws s3 ls
  • 지난 awk단순히 추가 total한 후 결과 출력 (KB의 크기)의 3 콜럼 마지막에 표시

참고이 명령은 재귀 적이 아닌 현재 버킷 또는 '폴더'에 대해 작동합니다.


https://serverfault.com/questions/84815/how-can-i-get-the-size-of-an-amazon-s3-bucket을 참조 하십시오.

의해 답변을 Vic ...

<?php
if (!class_exists('S3')) require_once 'S3.php';

// Instantiate the class
$s3 = new S3('accessKeyId', 'secretAccessKey');
S3::$useSSL = false;

// List your buckets:
echo "S3::listBuckets(): ";
echo '<pre>' . print_r($s3->listBuckets(), 1). '</pre>';

$totalSize = 0;
$objects = $s3->getBucket('name-of-your-bucket');
foreach ($objects as $name => $val) {
    // If you want to get the size of a particular directory, you can do
    // only that.
    // if (strpos($name, 'directory/sub-directory') !== false)
    $totalSize += $val['size'];
}

echo ($totalSize / 1024 / 1024 / 1024) . ' GB';
?>

Cloud watch also allows you to create metrics for your S3 bucket. It shows you metrics by the size and object count. Services> Management Tools> Cloud watch. Pick the region where your S3 bucket is and the size and object count metrics would be among those available metrics.


Getting large buckets size via API (either aws cli or s4cmd) is quite slow. Here's my HowTo explaining how to parse S3 Usage Report using bash one liner:

cat report.csv | awk -F, '{printf "%.2f GB %s %s \n", $7/(1024**3 )/24, $4, $2}' | sort -n

In addition to Christopher's answer.

If you need to count total size of versioned bucket use:

aws s3api list-object-versions --bucket BUCKETNAME --output json --query "[sum(Versions[].Size)]"

It counts both Latest and Archived versions.


The AWS console wont show you this but you can use Bucket Explorer or Cloudberry Explorer to get the total size of a bucket. Both have free versions available.

Note: these products still have to get the size of each individual object, so it could take a long time for buckets with lots of objects.


Based on @cudds's answer:

function s3size()
{
    for path in $*; do
        size=$(aws s3 ls "s3://$path" --recursive | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | awk 'BEGIN {total=0}{total+=$3}END{printf "%.2fGb\n", (total/1024/1024/1024)}')
        echo "[s3://$path]=[$size]"
    done
}

...

$ s3size bucket-a bucket-b/dir
[s3://bucket-a]=[24.04Gb]
[s3://bucket-b/dir]=[26.69Gb]

Also, Cyberduck conveniently allows for calculation of size for a bucket or a folder.


Mini John's answer totally worked for me! Awesome... had to add

--region eu-west-1 

from Europe though


This is an old inquiry, but since I was looking for the answer I ran across it. Some of the answers made me remember I use S3 Browser to manage data. You can click on a bucket and hit properties and it shows you the total. Pretty simple. I highly recommend the browser: https://s3browser.com/default.aspx?v=6-1-1&fam=x64


Well, you can do it also through an S3 client if you prefer a human friendly UI.

I use CrossFTP, which is free and cross-platform, and there you can right-click on the folder directory -> select "Properties..." -> click on "Calculate" button next to Size and voila.


s3admin is an opensource app (UI) that lets you browse buckets, calculate total size, show largest/smallest files. It's tailored for having a quick overview of your Buckets and their usage.


You asked: information in AWS console about how much disk space is using on my S3 cloud?

I so to the Billing Dashboard and check the S3 usage in the current bill.

They give you the information - MTD - in Gb to 6 decimal points, IOW, to the Kb level.

It's broken down by region, but adding them up (assuming you use more than one region) is easy enough.

BTW: You may need specific IAM permissions to get to the Billing information.


I use Cloud Turtle to get the size of individual buckets. If the bucket size exceeds >100 Gb, then it would take some time to display the size. Cloud turtle is freeware.

참고URL : https://stackoverflow.com/questions/8975959/aws-s3-how-do-i-see-how-much-disk-space-is-using

반응형