Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare versions of an Amazon S3 object?

Versioning of Amazon S3 buckets is nice, but I don't see any easy way to compare versions of a file - either through the console or through any other app I found.

S3Browser seems to have the best versioning support, but no comparison.

Is there a way to compare versions of a file on S3 without downloading both versions and comparing them manually?

--

EDIT: I just started thinking that some basic automation should not be too hard, see snippet below. Question remains though: is there any tool that supports this properly? This script may be fine for me, but not for non-dev users.

#!/bin/bash

# s3-compare-last-versions.sh

if [[ $# -ne 2 ]]; then
    echo "Usage: `basename $0` <bucketName> <fileKey> "
    exit 1
fi

bucketName=$1
fileKey=$2

latestVersionId=$(aws s3api list-object-versions --bucket $bucketName --prefix $fileKey --max-items 2 | json Versions[0].VersionId)
previousVersionId=$(aws s3api list-object-versions --bucket $bucketName --prefix $fileKey --max-items 2 | json Versions[1].VersionId)

aws s3api get-object --bucket $bucketName --key $fileKey --version-id $latestVersionId $latestVersionId".js"
aws s3api get-object --bucket $bucketName --key $fileKey --version-id $previousVersionId $previousVersionId".js"

diff $latestVersionId".js" $previousVersionId".js"
like image 825
Free Willaert Avatar asked Oct 19 '16 18:10

Free Willaert


People also ask

How do I see the versions of an S3 object?

Using the S3 console In the Objects list, choose the name of the object. Choose Versions. Amazon S3 shows all the versions for the object. Select the check box next to the Version ID for the versions that you want to retrieve.

Can we compare two Amazon S3 bucket?

You can use the sync command with the --dryrun option to compare instead of syncing. You can, of course, also use it to compare a local directory with a bucket.

How AWS S3 flags the current version of an object?

You can use S3 Versioning to keep multiple versions of an object in one bucket and enable you to restore objects that are accidentally deleted or overwritten. For example, if you delete an object, instead of removing it permanently, Amazon S3 inserts a delete marker, which becomes the current object version.

Does S3 have version control?

Versioning in Amazon S3 is a means of keeping multiple variants of an object in the same bucket. You can use the S3 Versioning feature to preserve, retrieve, and restore every version of every object stored in your buckets.


1 Answers

You can't view file contents at all via S3, so you definitely can't compare the contents of files via S3. You would have to download the different versions and then use a tool like diff to compare them.

like image 191
Mark B Avatar answered Nov 03 '22 01:11

Mark B