gpt4 book ai didi

linux - 从 EC2 同步到 s3 后如何删除文件

转载 作者:太空宇宙 更新时间:2023-11-04 09:12:50 25 4
gpt4 key购买 nike

我有一个文件系统,可以将文件放入 EC2 实例中,并且我运行一个 shell 脚本来将新放入的文件同步到 s3 存储桶。一旦文件同步,我希望从 E2C 实例中删除这些文件。具体来说,这些文件被放入“yyyyy”文件夹中。

下面是我的shell代码:

#!/bin/bash

inotifywait -m -r -e create "yyyyy" | while read -r NEWFILE
do
if lsof | grep "$NEWFILE" ; then
echo "$NEWFILE";
else
sleep 15
aws s3 sync yyyyy s3://xxxxxx-xxxxxx/
fi

最佳答案

您可以使用 aws s3 mv(这是一个“移动”),而不是使用 aws s3 sync

这会将文件复制到目标位置,然后删除原始文件(有效地“移动”文件)。

也可以与 --recursive 一起使用来移动整个文件夹,或者 --include--exclude 来指定多个文件.

关于linux - 从 EC2 同步到 s3 后如何删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52824885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com