简体   繁体   English

使用 PowerShell 递归删除 S3 存储桶下超过 30 天的文件而不删除文件夹

[英]Delete files older than 30 days under S3 bucket recursively without deleting folders using PowerShell

I can delete files and exclude folders with following script我可以使用以下脚本删除文件并排除文件夹

aws s3 rm s3://my-bucket/ --recursive --exclude="*" --include="*/*.*"

when i tried to add pipe to delete only older files, i'm unable to.. please help with the script.当我尝试添加 pipe 以仅删除旧文件时,我无法......请帮助脚本。

aws s3 rm s3://my-bucket/ --recursive --exclude="*" --include="*/*.*" | Where-Object {($_.LastModified -lt (Get-Date).AddDays(-31))} 

The approach should be to list the files you need, then pipe the results to a delete call (a reverse of what you have).该方法应该是list您需要的文件,然后 pipe delete调用的结果(与您所拥有的相反)。 This might be better managed by a full blown script rather than a one line shell command.这可能通过一个完整的脚本而不是一行 shell 命令来更好地管理。 There's an article on this and some examples here .这里有一篇关于此的文章和一些示例。

Going forward, you should letS3 versioning take care of this, then you don't have to manage a script or remember to run it.展望未来,您应该让S3 版本控制来处理这个问题,这样您就不必管理脚本或记得运行它。 Note: it'll only work with files that are added after versioning has been enabled.注意:它只适用于启用版本控制后添加的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 python 递归删除 S3 存储桶下的文件而不删除文件夹 - Delete files under S3 bucket recursively without deleting folders using python 如何删除 Amazon S3 中超过 7 天的文件? - How to delete files older than 7 days in Amazon S3? 从 S3 存储桶上的文件夹中删除文件 - Delete files from folders on S3 bucket 如何删除超过 7 天的文件但在 Amazon S3 中保留每月 1 号的最后 6 个文件? - How to delete files older than 7 days but keep last 6 files of 1st of every month in Amazon S3? Boto3 S3 存储桶生命周期策略 - 这么多天后删除文件夹和文件 - Boto3 S3 Bucket Lifecycle Policy - Delete folders and files after so many days 如何从 S3 存储桶中递归删除文件 - How to delete files recursively from an S3 bucket 从 S3 存储桶中的文件夹中删除文件 - Delete files from folder in S3 bucket S3 存储桶:当已经有数百万个文件时,删除所有早于 15 分钟的文件的简便方法 - S3 bucket: Easy way to remove all the files older than 15min when there are already millions of files 如何使用 AWS SDK 为 Python 递归列出 AWS S3 存储桶中的文件? - How to recursively list files in AWS S3 bucket using AWS SDK for Python? 如何在不使用 AWS CLI 删除现有标签的情况下将标签添加到 S3 存储桶? - How to add tags to an S3 Bucket without deleting the existing tags using AWS CLI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM