Skip to content

Bucket Versioning

See the official AWS client documentation for further information.

You can enable versioning on a bucket using aws cli s3api using the argument “put-bucket-versioning”:

aws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api put-bucket-versioning --bucket $BUCKET\_NAME --versioning-configuration Status=Enabled for example: aws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api put-bucket-versioning --bucket versioning-testbucket --versioning-configuration Status=Enabled

If you want to know if bucket versioning is enabled on a bucket you can simply use aws cli s3api using the argument “get-bucket-versioning”

aws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api get-bucket-versioning --bucket $BUCKET\_NAME for example: aws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api get-bucket-versioning --bucket versioning-testbucket { "Status": "Enabled" }

Once the bucket versioning has been enabled, it cannot be disabled completely. It can only be suspended.

If you want to suspend versioning on a bucket you can use aws cli s3api with the argument “put-bucket-versioning —versioning-configuration Status=Suspended”

aws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api put-bucket-versioning --bucket $BUCKET\_NAME --versioning-configuration Status=Suspended for example: aws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api put-bucket-versioning --bucket versioning-testbucket --versioning-configuration Status=Suspended check the status: aws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api get-bucket-versioning --bucket versioning-testbucket { "Status": "Suspended" }

You can list object versions within a given bucket using the “list-object-versions” argument.

This will return all versions of all objects within your bucket.

Each object version gets it´s own unique ID displayed as “VersionID”

aws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api list-object-versions --bucket $BUCKETNAME for example: aws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api list-object-versions --bucket versioning-testbucket { "Versions": [ { "ETag": "\\"1a6fcf50c1eafb9db3b1916c80131a8c\\"", "Size": 56, "StorageClass": "STANDARD", "Key": "testfile.txt", "VersionId": "NDM0ODQ5NEEtQTU0OC0xMUVDLTkyNEItOTFFRTAwQkU0RTEw", "IsLatest": true, "LastModified": "2022-03-16T16:43:52.668000+00:00", "Owner": { "DisplayName": "f1ba3206-eaf2-4f1d-b01a-5679c5e82dfd", "ID": "88612969136594181457" } }, { "ETag": "\\"1a6fcf50c1eafb9db3b1916c80131a8c\\"", "Size": 56, "StorageClass": "STANDARD", "Key": "testfile.txt", "VersionId": "NDBBRjA1NUMtQTU0OC0xMUVDLTk4MzMtNzM2NzAwQzEyQ0Yx", "IsLatest": false, "LastModified": "2022-03-16T16:43:48.308000+00:00", "Owner": { "DisplayName": "f1ba3206-eaf2-4f1d-b01a-5679c5e82dfd", "ID": "88612969136594181457" } }, { "ETag": "\\"caf69a19c1017882a0e33a22d72b30df\\"", "Size": 40, "StorageClass": "STANDARD", "Key": "testfile.txt", "VersionId": "MkQxQjY3MDYtQTU0OC0xMUVDLTlEOEMtMTU3QzAwQkU0RTEw", "IsLatest": false, "LastModified": "2022-03-16T16:43:15.464000+00:00", "Owner": { "DisplayName": "f1ba3206-eaf2-4f1d-b01a-5679c5e82dfd", "ID": "88612969136594181457" } } ] }

You can download a specific Object Version by specifying the object version on the get request. The object version ID is shown if you list the object versions (see: “List Object Versions”)

aws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api get-object --bucket $BUCKET\_NAME --key $OBJECT\_KEY --version-id $VERSION\_ID for example: aws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api get-object --bucket versioning-test --key testfile.txt --version-id MkQxQjY3MDYtQTU0OC0xMUVDLTlEOEMtMTU3QzAw QkU0RTEw testfile\_new { "AcceptRanges": "bytes", "LastModified": "2022-03-16T16:43:15+00:00", "ContentLength": 40, "ETag": "\\"caf69a19c1017882a0e33a22d72b30df\\"", "VersionId": "MkQxQjY3MDYtQTU0OC0xMUVDLTlEOEMtMTU3QzAwQkU0RTEw", "ContentType": "binary/octet-stream", "ServerSideEncryption": "AES256", "Metadata": {} }

To enable versioning on an Object storage bucket using s5cmd, you can follow these steps:

s5cmd bucket-version s3://bucketname
s5cmd bucket-version --set Enabled s3://bucketname
s5cmd bucket-version --set Suspended s3://bucketname

List all versions of an object in the bucket

Section titled “List all versions of an object in the bucket”
s5cmd ls --all-versions s3://bucket/object

List all versions of all objects that starts with a prefix in the bucket

Section titled “List all versions of all objects that starts with a prefix in the bucket”
s5cmd ls --all-versions "s3://bucket/prefix*"

List all versions of all objects in the bucket

Section titled “List all versions of all objects in the bucket”
s5cmd ls --all-versions "s3://bucket/*"

Download the specific version of a remote object to working directory

Section titled “Download the specific version of a remote object to working directory”
s5cmd cp --version-id VERSION\_ID s3://bucket/prefix/object.

Delete the specific version of a remote object’s content to stdout

Section titled “Delete the specific version of a remote object’s content to stdout”
s5cmd rm --version-id VERSION\_ID s3://bucket/prefix/object

Delete all versions of an object in the bucket

Section titled “Delete all versions of an object in the bucket”
s5cmd rm --all-versions s3://bucket/object

See the official s5cmd client documentationfor further information.