Skip to content

Instantly share code, notes, and snippets.

@reecestart
Created February 1, 2018 01:48
Show Gist options
  • Save reecestart/c90cd08e71079a3d7032499f7280552e to your computer and use it in GitHub Desktop.
Save reecestart/c90cd08e71079a3d7032499f7280552e to your computer and use it in GitHub Desktop.
Testing the effect of S3 Sync on an object with multiple Versions
#!/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