Skip to content

Instantly share code, notes, and snippets.

@keymon
Last active December 28, 2018 10:28
Show Gist options
  • Select an option

  • Save keymon/6e38941995a48af109e28192bff6c9cb to your computer and use it in GitHub Desktop.

Select an option

Save keymon/6e38941995a48af109e28192bff6c9cb to your computer and use it in GitHub Desktop.
Compare s3 versions. "Stolen" from https://stackoverflow.com/q/40138780/395686
#!/bin/bash
# s3-compare-last-versions.sh
set -eu -o pipefail
if [[ $# -ne 2 ]]; then
echo "Usage: `basename $0` <bucketName> <fileKey> "
exit 1
fi
tmpdir="$(mktemp -d)" && trap 'rm -rf "${tmpdir:-/tmp/foo}"' EXIT QUIT INT
bucketName=$1
fileKey=$2
for v in 0 1; do
VersionId=$(
aws s3api list-object-versions \
--bucket $bucketName \
--prefix $fileKey \
--max-items 2 \
--output json \
--query Versions[$v].VersionId
)
aws s3api get-object \
--bucket $bucketName \
--key $fileKey \
--version-id \
$VersionId ${tmpdir}/$v > /dev/null
done
${DIFFTOOL:-diff -Nur} ${tmpdir}/1 ${tmpdir}/0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment