如何按修改日期列出 Amazon S3 存储桶内容? [英] How list Amazon S3 bucket contents by modified date?

查看:28
本文介绍了如何按修改日期列出 Amazon S3 存储桶内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数情况下,我们将文件加载到公共 S3 存储桶中,因此很难找出其中的数据.

Most of the time it happens that we load files in a common S3 bucket due to which it becomes hard to figure out data in it.

如何查看在特定日期上传的对象?

How can I view objects uploaded on a particular date?

推荐答案

一种解决方案可能是使用 s3api.如果您的对象少于 1000 个,它很容易工作,否则您需要使用分页.

One solution would probably to use the s3api. It works easily if you have less than 1000 objects, otherwise you need to work with pagination.

s3api 可以列出所有对象,并且对于 s3 中导入的键的 lastmodified 属性有一个属性.然后可以对其进行排序,查找日期之后或之前的文件,匹配日期...

s3api can list all objects and has a property for the lastmodified attribute of keys imported in s3. It can then be sorted, find files after or before a date, matching a date ...

运行此类选项的示例

  1. 给定日期的所有文件

DATE=$(date +%Y-%m-%d)
bucket=test-bucket-fh
aws s3api list-objects-v2 --bucket "$bucket" 
    --query 'Contents[?contains(LastModified, `'"$DATE"'`)]'

  1. 某个日期之后的所有文件

SINCE=`date --date '-2 weeks +2 days' +%F 2>/dev/null || date -v '-2w' -v '+2d' +%F`
#      ^^^^ GNU style                                    ^^^^ BSD style
bucket=test-bucket-fh
aws s3api list-objects-v2 --bucket "$bucket" 
    --query 'Contents[?LastModified > `'"$SINCE"'`]'

s3api 将返回一个 元数据很少,因此您可以过滤特定元素

s3api will return a few metadata so you can filter for specific elements

DATE=$(date +%Y-%m-%d)
bucket=test-bucket-fh
aws s3api list-objects-v2 --bucket "$bucket" 
    --query 'Contents[?contains(LastModified, `'"$DATE"'`)].Key'

这篇关于如何按修改日期列出 Amazon S3 存储桶内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆