寻找某个日期的s3cmd下载命令 [英] looking for s3cmd download command for a certain date

查看:160
本文介绍了寻找某个日期的s3cmd下载命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚s3cmd命令将按日期从存储桶中下载文件的原因,例如,我有一个名为"test"的存储桶,并且在该存储桶中有不同日期的不同文件.我正在尝试获取昨天上传的文件.该命令是什么?

I am trying to figure out on what the s3cmd command would be to download files from bucket by date, so for example i have a bucket named "test" and in that bucket there are different files from different dates. I am trying to get the files that were uploaded yesterday. what would the command be?

推荐答案

没有单个命令允许您执行此操作.您必须编写一个类似这样的脚本.或使用允许您执行此操作的SDK.下面的脚本是一个示例脚本,将从最近30天获取S3文件.

There is no single command that will allow you to do that. You have to write a script some thing like this. Or use a SDK that allows you to do this. Below script is a sample script that will get S3 files from last 30 days.

#!/bin/bash
# Usage: ./getOld "bucketname" "30 days"
s3cmd ls s3://$1 | while read -r line;  do

createDate=`echo $line|awk {'print $1" "$2'}`
createDate=`date -d"$createDate" +%s`
olderThan=`date -d"-$2" +%s`
if [[ $createDate -lt $olderThan ]]
  then 
    fileName=`echo $line|awk {'print $4'}`
    echo $fileName
    if [[ $fileName != "" ]]
      then
        s3cmd get "$fileName"
    fi
fi
done;

这篇关于寻找某个日期的s3cmd下载命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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