【问题标题】:How to delete file after sync from EC2 to s3从 EC2 同步到 s3 后如何删除文件
【发布时间】:2018-10-16 15:16:10
【问题描述】:

我有一个文件系统,可以在其中将文件拖放到 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

【问题讨论】:

  • 您能解释一下为什么在同步后不使用rmaws s3 mv 吗?
  • 我将捕获“aws s3 sync yyyyy s3://xxxxxx-xxxxxx/”行的结果作为变量,并确认返回代码表明同步成功。然后编写一个 if 成功例程来 rm 文件)。

标签: linux bash shell amazon-web-services amazon-ec2


【解决方案1】:

您可以使用aws s3 mv(这是一个“移动”)来代替aws s3 sync

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

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

【讨论】:

    猜你喜欢
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2021-05-31
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    • 2016-12-17
    相关资源
    最近更新 更多