使用Golang的aws-sdk将仅上传新修改的文件到S3存储桶。

huangapple go评论89阅读模式
英文:

Upload only newly modified files to S3 bucket using Golang aws-sdk

问题

我正在尝试在我的代码中实现一个将备份上传到S3存储桶的机制。
每当满足某个条件时,我需要将整个目录内容上传到S3存储桶。

我正在使用这个代码示例:

https://github.com/aws/aws-sdk-go/tree/c20265cfc5e05297cb245e5c7db54eed1468beb8/example/service/s3/sync

它创建了一个目录内容的迭代器,然后使用s3manager.Upload.UploadWithIterator来上传它们。

一切都正常工作,但我注意到它会上传所有文件,并覆盖存储桶中已存在的文件,即使它们自上次备份以来没有被修改,我只想上传每个备份之间的增量部分。

我知道aws cli有一个命令aws s3 sync <dir> <bucket>可以实现我需要的功能,但我在aws-sdk文档中找不到类似的内容。

感谢帮助,谢谢!

英文:

I'm trying to implement a backup mechanism to S3 bucket in my code.
Each time a condition is met I need to upload an entire directory contents to an S3 bucket.

I am using this code example:

https://github.com/aws/aws-sdk-go/tree/c20265cfc5e05297cb245e5c7db54eed1468beb8/example/service/s3/sync

Which creates an iterator of the directory content's and then use s3manager.Upload.UploadWithIterator to upload them.

Everything works, however I noticed it uploads all files and overwrites existing files on the bucket even if they weren't modified since last backup, I only want to upload the delta between each backup.

I know aws cli has the command aws s3 sync &lt;dir&gt; &lt;bucket&gt; which does exactly what I need, however I couldn't find anything equivalent on aws-sdk documentation.

Appreciate the help, thank you!

答案1

得分: 2

在aws-sdk中没有这样的功能。您可以为每个文件自行添加代码来检查上传之前两个对象的哈希值。或者使用社区提供的解决方案https://www.npmjs.com/package/s3-sync-client。

英文:

There is no such feature in aws-sdk. You could instrument it yourself for each file to check the hash of both objects before upload. Or use a community solution https://www.npmjs.com/package/s3-sync-client

huangapple
  • 本文由 发表于 2022年9月20日 19:23:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/73785902.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定