- Newest
- Most votes
- Most comments
I will advice you to contact AWS Support team because the above answer is an AI generated answer.
Thanks
The behavior you're observing with the AWS CLI S3 sync command is not a bug, but it is indeed counterintuitive. The sync command is designed to copy new and updated files from the source to the destination, but it has a specific way of determining what "updated" means.
By default, the S3 sync command uses both the file size and the modification time to determine if a file needs to be updated. However, the comparison of modification times works in a way that might seem unexpected:
-
If the destination file is newer than the source file, the sync command will download the file from S3. This is because the command assumes that the S3 version is the "correct" or "authoritative" version, and that any local file with a more recent timestamp might be out of sync with S3.
-
If the source file in S3 is newer than the destination file, the sync command will not download the file. This is because the command assumes that the newer S3 version is already reflected in the local copy.
This behavior is designed to ensure that the local copy always matches the S3 version, even if local files have been modified. However, it can lead to unexpected results, as you've observed.
To modify this behavior, you can use additional flags:
- Use --exact-timestamps to only update files if the timestamps are different.
- Use --size-only to compare only the size of the files, ignoring the timestamps.
If you want to ensure that you always get the latest version from S3, regardless of local timestamps, you might consider using the --force-update flag, which will download all files from S3, overwriting the local copies.
Remember that the default behavior of S3 sync is designed to minimize unnecessary data transfer, but it may not always align with specific use cases. Always test the sync command with your particular setup to ensure it behaves as expected for your needs.
Sources
Amazon S3 examples using AWS CLI - AWS SDK Code Examples
We probably need a real AWS engineer to verify this AI-generated comment. Unfortunately, I'm not convinced by its answer.