Versioning

Activate and make use of S3’s versioning capabilities.

In S3, you can benefit from versioning by storing different versions of the same object in a bucket. This ensures additional data security and recovery options.

Step 0: Create a bucket with versioning enabled (without Object Lock)

If you do not have a bucket with versioning, which you can/want to use in this example, you can use the following command to create a bucket with versioning. aws s3api create-bucket --bucket <bucket-name> --region <region> --create-bucket-configuration LocationConstraint=<region> --endpoint-url=https://<endpoint>

You then need to enable versioning with the following command. This can of course also be used for existing buckets with objects. aws s3api put-bucket-versioning --bucket <bucket-name> --versioning-configuration Status=Enabled --endpoint-url=https://<endpoint>

With the Object Lock you have already set up (from Part 3 Step 2), versioning is already activated. The following example shows you how to upload objects, create new versions, and access previous versions.

Upload objects

Use the aws s3 cp command to upload an object to your bucket: aws s3 cp <local-file-path> s3://<bucket-name>/<destination-file-path> --endpoint-url=https://<endpoint>

<local-file-path>: The path to the file on your computer to be uploaded. <bucketname>: The name of your bucket. <destination file path>: The desired location and name of the uploaded object in the bucket. <endpoint>: The corresponding endpoint for your plusserver S3.

Overwrite the object

Upload an updated version of the same object using the following command: aws s3 cp <new-local-file-path> s3://<bucketname>/<destination-file-path> --endpoint-url=https://<endpoint>

The target file path must be identical to the path from step 1.

Access previous versions

To access previous versions of the object, use the version ID generated by S3. Use the following command to display the version ID:

aws s3api list-object-versions --bucket <bucketname> --prefix <target file path> --endpoint-url=https://<endpoint>

<bucketname>: The name of your bucket. <target file path>: The location and name of the object in the bucket.

Select the desired version ID from the list displayed.

Example output:

{
    "Versions": [
        {
            "ETag": "\"66b45f0d975835364c3ddba89be46516\"",
            "Size": 57,
            "StorageClass": "STANDARD",
            "Key": "testfile",
            "VersionId": "fe11c7b4-e63c-f2df-bd54-1402ec8ef4c8",
            "IsLatest": true,
            "LastModified": "2023-08-11T13:29:30.098000+00:00",
            "Owner": {
                "ID": "2bf748417f89cbbca94465e9121a2507"
            }
        },
        {
            "ETag": "\"40375ddc11cbe7f92789df9e8f73fb41\"",
            "Size": 40,
            "StorageClass": "STANDARD",
            "Key": "testfile",
            "VersionId": "fe11c7b4-eeae-f76f-a6ff-1402ec8ef430",
            "IsLatest": false,
            "LastModified": "2023-08-11T13:29:15.929000+00:00",
            "Owner": {
                "ID": "2bf748417f89cbbca94465e9121a2507"
            }
        }
    ]
}

Download a previous version

Use the version ID to download a specific version of the object: aws s3 cp s3://<bucketname>/<target-file-path>?versionId=<version-id> <local-file-path> --endpoint-url=https://<endpoint>

<bucketname>: The name of the bucket. <target-file-path>: The location and name of the object in the bucket. <version-id>: The selected version ID. <local-file-path>: The path on your computer where the downloaded file should be saved.

By combining Object Lock and automatic versioning, you have the ability to access previous states of objects and protect your data from accidental changes.

Last modified 2023-10-26: Initial insertion of content. (87587ca)