# How to Enable Spaces Versioning Spaces Object Storage is an S3-compatible service for storing and serving large amounts of data. The built-in Spaces CDN minimizes page load times, improves performance, and reduces bandwidth and infrastructure costs. S3 Versioning maintains previous versions of objects in your buckets, which allows you to restore a previous version of an object if a user or application overwrites or deletes it. Spaces [supports S3 Versioning](https://docs.digitalocean.com/reference/api/spaces/index.html.md#aws-s3-compatibility). By default, versioning is disabled on all buckets. You must use the Spaces API to enable or disable versioning. ## Check the Status of Versioning To check whether versioning is enabled for a bucket, go to the [DigitalOcean Control Panel](https://cloud.digitalocean.com), in the left menu, click **Spaces Object Storage**, click the bucket you want to check, and then click the **Settings** tab. ![Bucket versioning access settings page showing project name, Object Versioning disabled, and Access Logs disabled.](https://docs.digitalocean.com/screenshots/spaces/bucket-versioning-access-settings.90bb0df1bd9bb778606d666f757ecc746bebe87d50244d743d8af068b4801bca.png) The **Object Versioning** section shows whether versioning is **Enabled** or **Disabled**. You can only [enable versioning](#enable-spaces-versioning) via the DigitalOcena API. ## Get Prerequisites to Manage Versioning To manage versioning for a Spaces bucket, you need a DigitalOcean Spaces API key and the bucket’s regional endpoint. ### Get Spaces API Key To get your DigitalOcean Spaces API key, go to the [control panel](https://cloud.digitalocean.com), in the left menu, click **Spaces Object Storage**, click the bucket you want to manage versioning for, click the **Settings** tab, and then under the **Access Keys** section, save the **Access Key ID** and its secret key. To re-generate your key, on the right of the key, click **…**, and then click **Regenerate key** to get your new key details. If you don’t have a DigitalOcean Spaces API key, [create one](https://docs.digitalocean.com/products/spaces/how-to/manage-access/index.html.md#access-keys) ### Get Bucket’s Regional Endpoint The endpoint is always your bucket’s region followed by `.digitaloceanspaces.com`. Click **Copy** to copy the endpoint to your clipboard. Spaces versioning requires the regional endpoint, which always follows this format: `.digitaloceanspaces.com`. In the top right corner by the **Origin endpoint** field, copy your bucket origin endpoint (for example, `my-bucket.nyc3.digitaloceanspaces.com`). The origin endpoint cannot be used when managing versioning as it causes the versioning requests to fail. Remove the bucket name and use only the regional endpoint (for example, `nyc3.digitaloceanspaces.com`). ## Enable Spaces Versioning Before enabling versioning, you need your [DigitalOcean Spaces API key and your bucket’s regional endpoint](#prereqs). After getting your DigitalOcean Spaces API key details and endpoint, configure your AWS CLI using your key: ```bash aws configure ``` Run the following command to enable versioning on your bucket. Replace `your_bucket_name` with your bucket name and `your_region` with your bucket’s region (for example, `nyc3`). ```bash aws s3api put-bucket-versioning \ --bucket your_bucket_name \ --endpoint=https://your_region.digitaloceanspaces.com \ --versioning-configuration Status=Enabled ``` Verify that versioning is enabled: ```bash aws s3api get-bucket-versioning \ --bucket your_bucket_name \ --endpoint=https://your_region.digitaloceanspaces.com ``` If successful, the response shows that versioning is enabled and multi-factor authentication (MFA) is not required to delete objects. ```json { "Status": "Enabled", "MFADelete": "Disabled" } ``` ## Permanently Delete a Specific Version Deleting an object version permanently removes that version of the object. To permanently delete a specific object version, you need your [DigitalOcean Spaces API key and your bucket’s regional endpoint](#prereqs). Afterwards, list all bucket versions. Replace `your_filename`, `your_bucket_name`, and the endpoint with your specific values. ```bash aws s3api list-object-versions \ --prefix your_filename \ --bucket your_bucket_name \ --endpoint=https://your_region.digitaloceanspaces.com ``` Under `Versions`, find the `VersionId` you want to delete: ```json { "Versions": [ { "ETag": "\"\"", "Size": , "StorageClass": "STANDARD", "Key": "", "VersionId": "", "IsLatest": true, "LastModified": "", "Owner": { "DisplayName": "", "ID": "" } }, ... { "ETag": "\"\"", "Size": , "StorageClass": "STANDARD", "Key": "", "VersionId": "", "IsLatest": false, "LastModified": "", "Owner": { "DisplayName": "", "ID": "" } } ] } ``` Then, run the following command to delete a specific version of your bucket. Replace `your_bucket_name`, the endpoint, `your_filename`, and the `version_id_to_delete` with your specific values. ```bash aws s3api delete-object \ --bucket your_bucket_name \ --endpoint=https://your_region.digitaloceanspaces.com \ --key your_filename \ --version-id version_id_to_delete ``` A response returning the `VersionId` of the bucket version you wanted to delete confirms deletion. ## Retrieve a Deleted Object in a Versioning-Enabled Bucket Spaces creates a delete marker when you delete an object from a version-enabled bucket. The delete marker becomes the current version of the object, and the actual object becomes a previous version. Before retrieving a deleted object, you need your [DigitalOcean Spaces API key and your bucket’s regional endpoint](#prereqs). To retrieve a deleted object in a versioning-enabled bucket, first list all versions of the object. Replace `your_filename` and `your_bucket_name` and the endpoint with your specific values. ```bash aws s3api list-object-versions \ --prefix your_filename \ --bucket your_bucket_name \ --endpoint=https://your_region.digitaloceanspaces.com ``` This returns both object versions and delete markers. Find the `VersionId` of the deleted object you want to restore. ```json ... "DeleteMarkers": [ { "Owner": { "DisplayName": "", "ID": "" }, "Key": "", "VersionId": "", "IsLatest": true, "LastModified": "" } ] } ``` Then, remove the delete marker using the deleted bucket’s `VersionId`. Replace `your_bucket_name`, the endpoint, `your_filename`, and the `delete_market_version_id` with your specific values. ```bash aws s3api delete-object \ --bucket your_bucket_name \ --endpoint=https://your_region.digitaloceanspaces.com \ --key your_filename \ --version-id delete_marker_version_id ``` If successful, the file is restored, and the response returns stating the object is deleted along with its `VersionId`: ```json { "DeleteMarker": true, "VersionId": "delete_marker_version_id" } ```