简体   繁体   中英

Upload only newly modified files to S3 bucket using Golang 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 <dir> <bucket> which does exactly what I need, however I couldn't find anything equivalent on aws-sdk documentation.

Appreciate the help, thank you!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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