英文:
Upload only newly modified files to S3 bucket using Golang aws-sdk
问题
我正在尝试在我的代码中实现一个将备份上传到S3存储桶的机制。
每当满足某个条件时,我需要将整个目录内容上传到S3存储桶。
我正在使用这个代码示例:
它创建了一个目录内容的迭代器,然后使用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:
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 <dir> <bucket>
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论