【问题标题】:How to obtain all the recent files based on a prefix on a bucket S3?如何根据存储桶 S3 上的前缀获取所有最近的文件?
【发布时间】:2019-10-11 12:48:38
【问题描述】:

我需要获取所有大于时间戳的文件,带有前缀条件。例如,所有包含myfile*.zip > 2019-11-11 13:00:00,000 的文件,如果我收到以下内容:

myfile1.zip - 2019-11-10 13:00:00,000
myfile2.zip - 2019-11-11 10:00:00,000
myfile3.zip - 2019-11-11 13:00:00,000
myfile4.zip - 2019-11-11 17:00:00,000

我想要下一个结果:

myfile3.zip - 2019-11-11 13:00:00,000
myfile4.zip - 2019-11-11 17:00:00,000

我需要使用 Python boto3、bash 或 Airflow S3KeySensor 来做到这一点。

【问题讨论】:

    标签: python bash amazon-s3 airflow


    【解决方案1】:

    Bash 解决方案:

    您可以使用touch -tfind -newer 的组合。 touch 将创建一个具有特定修改日期的文件,find -newer 将仅列出比创建的文件新的文件。例如:

    # for 2019-11-11 13:00:00,000
    # Edit: This is currently in the future, so no results for you!
    touch -t 201911111300 mytempfile.temp 
    find . -name 'myfile*.zip' -newer mytempfile.temp
    rm mytempfile.temp
    

    来自touch --help

    -t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time
        --time=WORD        change the specified time:
                             WORD is access, atime, or use: equivalent to -a
                             WORD is modify or mtime: equivalent to -m
    

    【讨论】:

    • 但该解决方案不在 Amazon S3 之上,您提出的解决方案是针对“普通”文件系统
    猜你喜欢
    • 2016-07-02
    • 1970-01-01
    • 2021-02-22
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多