简体   繁体   English

AWS S3,上传后从本地目录中删除文件

[英]AWS S3, Deleting files from local directory after upload

I have backup files in different directories in one drive.我在一个驱动器的不同目录中有备份文件。 Files in those directories can be quite big up to 800GB or so.这些目录中的文件可能很大,高达 800GB 左右。 So I have a batch file with a set of scripts which upload/syncs files to S3.所以我有一个批处理文件,其中包含一组脚本,可以将文件上传/同步到 S3。

See example below:请参见下面的示例:

aws s3 sync R:\DB_Backups3\System s3://usa-daily/System/ --exclude "*" --include "*/*/Diff/*"

The upload time can vary but so far so good.上传时间可能会有所不同,但到目前为止还不错。

My question is, how do I edit the script or create a new one which checks in the s3 bucket that the files have been uploaded and ONLY if they have been uploaded then deleted them from the local drive, if not leave them on the drive?我的问题是,我该如何编辑脚本或创建一个新脚本来检查 s3 存储桶中的文件是否已上传,并且只有在文件已上传后才从本地驱动器中删除它们,如果没有将它们留在驱动器上?

(Ideally it would check each file) (理想情况下它会检查每个文件)

I'm not familiar with aws s3, or aws cli command that can do that?我不熟悉 aws s3 或可以执行此操作的 aws cli 命令? Please let me know if I made myself clear or if you need more details.如果我说清楚了或者您需要更多详细信息,请告诉我。

Any help will be very appreciated.任何帮助将不胜感激。

Best would be to use mv with --recursive parameter for multiple files最好将mv--recursive参数一起用于多个文件

When passed with the parameter --recursive , the following mv command recursively moves all files under a specified directory to a specified bucket and prefix while excluding some files by using an --exclude parameter.当使用参数--recursive传递时,以下mv命令递归地将指定目录下的所有文件移动到指定的存储桶和前缀,同时使用--exclude参数排除一些文件。 In this example, the directory myDir has the files test1.txt and test2.jpg:在此示例中,目录 myDir 具有文件 test1.txt 和 test2.jpg:

aws s3 mv myDir s3://mybucket/ --recursive --exclude "*.jpg"

Output:输出:

move: myDir/test1.txt to s3://mybucket2/test1.txt

Hope this helps.希望这可以帮助。

As the answer by @ketan shows, Amazon aws client cannot do batch move.正如@ketan 的回答所示,Amazon aws客户端无法进行批量移动。

You can use WinSCP put -delete command instead:您可以改用 WinSCP put -delete命令

winscp.com /log=S3.log /ini=nul /command ^
    "open s3://S3KEY:S3SECRET@s3.amazonaws.com/" ^
    "put -delete C:\local\path\* /bucket/" ^
    "exit"

You need to URL-encode special characters in the credentials .您需要对凭据中的特殊字符进行 URL 编码 WinSCP GUI can generate an S3 script template , like the one above, for you. WinSCP GUI 可以为您生成一个 S3 脚本模板,就像上面那个一样。

Alternatively, since WinSCP 5.19, you can use -username and -password switches, which do not need any encoding:或者,从 WinSCP 5.19 开始,您可以使用不需要任何编码的-username-password开关:

    "open s3://s3.amazonaws.com/ -username=S3KEY -password=S3SECRET" ^

(I'm the author of WinSCP) (我是 WinSCP 的作者)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM