自动删除具有特定扩展名和日期的 S3 文件

0

【以下的问题经过翻译处理】 我可以自动删除特定日期范围内的文件,但是我正在寻找自动删除具有特定扩展名和数据的60 天前的 s3 文件的工具。

profile picture
EXPERT
asked 5 months ago30 views
1 Answer
0

【以下的回答经过翻译处理】 我建造了这个工具

#!/bin/bash

SINCE_today=date --date '-13 weeks -1 days' +%F 2>/dev/null || date -v '-2w' -v '+2d' +%F

bucket=POC_DEV_Bucket

aws s3api list-objects --bucket "$bucket" --query 'Contents[?LastModified < '"$SINCE_today"']' --output text > 90days_old.txt && grep -i ".json" 90days_old.txt > s3file_with_extension_with_daysold.txt && cat s3file_with_extension_with_ZERO_daysold.txt && awk '{$1= ""; print $2}' s3file_with_extension_with_daysold.txt | xargs -I {} aws s3 rm s3://"$bucket"/{}
profile picture
EXPERT
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions