[英]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.