Skip to content

Bucket Versioning

Last updated on

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”:

Terminal window
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.

Terminal window
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.

Terminal window
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”

Terminal window
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).

Terminal window
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 MkQxQjY3MDYtQTU0OC0xMUVDLTlEOEMtMTU3QzAwQkU0RTEw 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:

Terminal window
s5cmd bucket-version s3://bucketname
Terminal window
s5cmd bucket-version --set Enabled s3://bucketname
Terminal window
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”
Terminal window
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”
Terminal window
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”
Terminal window
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”
Terminal window
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”
Terminal window
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”
Terminal window
s5cmd rm --all-versions s3://bucket/object

See the official s5cmd client documentationfor further information.