How do I delete old object versions?
    • 18 Dec 2023
    • 2 Minutes to read
    • PDF

    How do I delete old object versions?

    • PDF

    Article summary

    What is Versioning:

    The Wasabi versioning feature allows you to preserve, retrieve, and restore every version of every object stored in a Wasabi bucket. Once you enable versioning for a bucket, Wasabi preserves existing objects anytime you perform a PUT, POST, COPY, or DELETE operation on them. By default, GET requests will retrieve the most recently written version. Older versions of an overwritten or deleted object can be retrieved by specifying a version in the request. 

    While there is no native feature to mass delete all old object versions that have accumulated, below are some tips on how you can go about this.

    Note that this config example discusses the use of Wasabi's us-east-2 storage region. To use other Wasabi storage regions, please use the appropriate Wasabi service URL as described in this here.

    1. AWS CLI

    From the AWS CLI (How do I use AWS CLI with Wasabi?), you can delete a specific version of a file by specifying the --version-id in the delete message. The version-id is something you can get using the aws cli command to list the objects along with their version-id

    aws s3api list-object-versions --bucket  --endpoint-url https://s3.us-east-2.wasabisys.com 

    This will list the objects with their versions.

    {
        "DeleteMarkers": [
            {
                "Owner": {
                    "DisplayName": "wasabisupport", 
                    "ID": "64FC53EBEA41CD99146391187E793B721167132B88F80CB6D63D39A3C91182CD"
                }, 
                "IsLatest": true, 
                "VersionId": "001558365475266751389-VwaBekKLGa", 
                "Key": "Folder_with_ten_5MB_files/", 
                "LastModified": "2019-05-20T15:17:55.000Z"
            }, 
            {
                "Owner": {
                    "DisplayName": "wasabisupport", 
                    "ID": "64FC53EBEA41CD99146391187E793B721167132B88F80CB6D63D39A3C91182CD"
                }, 
                "IsLatest": true, 
                "VersionId": "001552912074127114450-S1bSJDBWTH", 
                "Key": "Folder_with_ten_5MB_files/5MB-copy-8.zip", 
                "LastModified": "2019-03-18T12:27:54.000Z"
            }, 
    ...

    Then select the version Id from the "VersionId" field in the JSON formatted output, you can use the LastModifiedDate as a reference to select the most recent or the most outdated version of the file. After you've got the version-id, you can delete it by using the following command.

    aws s3api delete-object --bucket  --key  --version-id   --endpoint-url https://s3.us-east-2.wasabisys.com

    For example:

    $ aws s3api delete-object  --bucket mytestbucketwithversions  --key "Folder_with_ten_5MB_files/5MB-copy-8.zip" --version-id 001552912074127114450-S1bSJDBWTH --endpoint-url=https://s3.us-east-2.wasabisys.com
    {
        "VersionId": "001552912074127114450-S1bSJDBWTH", 
        "DeleteMarker": true
    }


    2. S3 Browser

    As an alternative, we've used a free software application called S3 Browser that allows you to see and remove versioned objects. While this is manual, it does let you go in and delete any object versions to trim down on your total storage volume.

    mceclip1.png

    For more details on S3 Browser, see How do I use S3 Browser with Wasabi?

    A feature that customers sometimes enable along with versioning, is compliance, with an option to delete after retention. This feature is well paired with versioning because it allows you to update files (versioning), but not delete or edit the original versions (compliance), and then automatically delete all versions after the specified period of time (delete after retention). Note that all versions includes the current version as well. See this KB article for more details: Testing Compliance


    ESC

    Eddy AI, facilitating knowledge discovery through conversational intelligence