Created
February 1, 2018 01:48
-
-
Save reecestart/c90cd08e71079a3d7032499f7280552e to your computer and use it in GitHub Desktop.
Testing the effect of S3 Sync on an object with multiple Versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Tested using bash version 3.2.57 | |
echo Source Test Bucket? | |
read sourcetestbucketname | |
sourcetestbucket="s3://$sourcetestbucketname" | |
aws s3 mb $sourcetestbucket | |
echo Destination Test Bucket? | |
read destinationtestbucketname | |
destinationtestbucket="s3://$destinationtestbucketname" | |
aws s3 mb $destinationtestbucket | |
aws s3api put-bucket-versioning --bucket $sourcetestbucketname --versioning-configuration Status=Enabled | |
aws s3api put-bucket-versioning --bucket $destinationtestbucketname --versioning-configuration Status=Enabled | |
echo Test Directory? | |
read testdirectory | |
mkdir $testdirectory | |
testdirectory="$testdirectory/" | |
cd $testdirectory | |
echo Test File? | |
read testfile | |
testfile="$testfile.txt" | |
touch $testfile | |
echo "`date` User `whoami` started the script."$'\r' >> $testfile | |
sourcetestbucketpath="$sourcetestbucket/$testfile" | |
for ((i=1;i<=10;i++)); | |
do | |
echo "`date` User `whoami` started the script."$'\r' >> $testfile | |
aws s3 cp $testfile $sourcetestbucketpath | |
echo $i | |
done | |
versions=$(aws s3api list-object-versions --bucket $sourcetestbucketname --prefix $testfile --query 'reverse(Versions[].[VersionId,LastModified])' --output text) | |
versions="$(cut -d' ' -f2 <<<"$versions")" | |
versions=$(echo $versions | tr " " "\n") | |
i=1 | |
for x in $versions | |
do | |
[ $((i%2)) -eq 0 ] && echo "copying version" | |
echo $x | |
done | |
aws s3 sync $sourcetestbucket $destinationtestbucket |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment