Manage bucket versioning in Object Storage
Last updated on
Bucket versioning preserves multiple versions of an object in the same bucket. When versioning is enabled, each upload creates a version rather than overwriting the existing object. This protects against accidental deletion and data corruption.
Prerequisites
Section titled “Prerequisites”- Object Storage enabled and credentials configured: Enable Object Storage
- AWS CLI or s5cmd installed and configured for STACKIT Object Storage
Enable versioning
Section titled “Enable versioning”put-bucket-versioning \ --bucket $BUCKET_NAME \ --versioning-configuration Status=Enabled ```</TabItem><TabItem label="s5cmd">```bash s5cmd bucket-version --set Enabled s3://$BUCKET_NAME ```</TabItem></Tabs>
## Get versioning status
<Tabs syncKey="cli-tool"><TabItem label="AWS CLI">```bashaws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api get-bucket-versioning \ --bucket $BUCKET_NAMEExample output when versioning is enabled:
{ "Status": "Enabled"}s5cmd bucket-version s3://$BUCKET_NAMESuspend versioning
Section titled “Suspend versioning”Once versioning has been enabled on a bucket, it cannot be disabled. It can only be suspended. Suspended versioning stops creating versions but keeps existing ones.
put-bucket-versioning \ --bucket $BUCKET_NAME \ --versioning-configuration Status=Suspended ```</TabItem><TabItem label="s5cmd">```bash s5cmd bucket-version --set Suspended s3://$BUCKET_NAME ```</TabItem></Tabs>
## List object versions
<Tabs syncKey="cli-tool"><TabItem label="AWS CLI">List all versions of all objects in a bucket:
```bashaws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api list-object-versions \ --bucket $BUCKET_NAMEEach version has a unique VersionId. Example output:
{ "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" } } ]}List all versions of a specific object:
s5cmd ls --all-versions s3://$BUCKET_NAME/$OBJECT_KEYList all versions of objects with a prefix:
s5cmd ls --all-versions "s3://$BUCKET_NAME/prefix*"List all versions of all objects in a bucket:
s5cmd ls --all-versions "s3://$BUCKET_NAME/*"Download a specific object version
Section titled “Download a specific object version”Download a specific version of an object by providing its VersionId:
aws --endpoint-url https://object.storage.eu01.onstackit.cloud s3api get-object \ --bucket $BUCKET_NAME \ --key $OBJECT_KEY \ --version-id $VERSION_ID \ output-filenames5cmd cp --version-id $VERSION_ID s3://$BUCKET_NAME/$OBJECT_KEY .Delete a specific version
Section titled “Delete a specific version”bash s5cmd rm --version-id $VERSION_ID s3://$BUCKET_NAME/$OBJECT_KEY
Delete all versions of an object
Section titled “Delete all versions of an object”bash s5cmd rm --all-versions s3://$BUCKET_NAME/$OBJECT_KEY For full details on available commands, see the AWS CLI documentation or the s5cmd documentation.