Reputation: 312
I have a version enabled bucket "A" with many objects. I need to move all the objects from bucket "A" to another version enabled bucket "B". The condition is "I need to move the objects based on time of creation. The older objects in bucket "A" should be moved first"
How to do this using aws-cli?
Upvotes: 0
Views: 1009
Reputation: 367
Here it is the single command:
aws s3 ls s3://<from-bucket> --recursive | awk '{d=substr($0,1,10)}(d < "2019-10-25")' | cut -c 32- | awk '{print "--include "$0}' ORS=' ' | xargs aws s3 mv s3://<from-bucket> s3://<to-bucket> --recursive --exclude '*'
awk
we subtract the date and compare with a target date you specify by your owncut
subtract file namesawk
prepare include arguments for aws s3 mv
commandxargs
pass the arguments to aws s3 mv
Upvotes: 3