It looks like this is achievable, except for the deletion part.
This command will sync
only the specified files:
aws s3 sync s3://bucketA s3://bucketB --exclude "*" --include "File1.jpg" --include "File2.jpg" --include "File4.jpg"
However, the --delete
parameter seems to only look at the files in BucketA
that are included in the --include
parameter, causing all other files to 'invisible' and therefore deleted from BucketB.
This command:
aws s3 sync s3://bucketA s3://bucketB --delete --exclude "*" --include "File1.jpg" --include "File2.jpg" --include "File4.jpg"
actually deletes all files except File2.jpg
and File4.jpg
. So, it doesn't look like you can do a selective delete in the expected manner.
Here's a script to test all of the above:
aws s3 cp foo s3://bucketa/File1.jpg
aws s3 cp foo s3://bucketa/File2.jpg
aws s3 cp foo s3://bucketa/File3.jpg
aws s3 cp foo s3://bucketa/File4.jpg
aws s3 cp foo s3://bucketa/File5.jpg
aws s3 sync s3://bucketa s3://bucketb
aws s3 rm s3://bucketa/File1.jpg
aws s3 rm s3://bucketa/File3.jpg
aws s3 cp foo s3://bucketa/File6.jpg
aws s3 cp bar s3://bucketa/File2.jpg
aws s3 cp bar s3://bucketa/File4.jpg
aws s3 cp bar s3://bucketa/File5.jpg
aws s3 ls s3://bucketa
2015-07-23 08:50:44 49 File2.jpg
2015-07-23 08:50:49 49 File4.jpg
2015-07-23 08:50:53 49 File5.jpg
2015-07-23 08:50:20 24 File6.jpg
aws s3 ls s3://bucketb
2015-07-23 08:49:35 24 File1.jpg
2015-07-23 08:49:35 24 File2.jpg
2015-07-23 08:49:36 24 File3.jpg
2015-07-23 08:49:36 24 File4.jpg
2015-07-23 08:49:36 24 File5.jpg
aws s3 sync s3://bucketa s3://bucketb --exclude "*" --include "File1.jpg" --include "File2.jpg" --include "File4.jpg"