# Enable Versioning

Simple Object Storage's versioning and lock support lets you
protect and archive data in your applications. It prevents data
loss and enables you to restore objects that are accidentally
deleted or overwritten via the user interface or API.

> [!NOTE]"In progress"
> Please note that Web portal support for versioning is currently in progress and will be released soon.

## Versioning

By default buckets are un-versioned and versioning needs to be activated. Once
activated, it will modify the following behaviors for an object:

* If an object is deleted, SOS will instead keep the object and add the delete marker.
Therefore the object could still be restored.
* If an object is overwritten, then SOS will create a new version instead to the object
keeping the previous one intact. The previous version can be then restored any time
referring to its version ID.

## Object Lock

Exoscale SOS implements the S3 compatible object lock feature with the *Legal hold*
feature. An object bearing the lock protection cannot be deleted indefinitely until
the legal hold has been explicitly removed.

## Pricing considerations

Bucket versioning is a free feature and does not trigger additional charges
when activated on a bucket whether it is used or not. However there is a cost implied
by having multiple versions of an object. For example, if you have 5 versions of an
object, each version 1 GB of storage volume, then your charge will be for 5 GB.

Object lock is as well a free feature, with the normal SOS charge applying for the
duration the object is stored on Exoscale.

## Getting Started

This guide will walk you through various operations involving bucket versioning and locking using the Minio client, one of the open-source tools compatible with S3 for managing your buckets.

Prerequisites:

-  Install the Minio client by referring to the official Minio documentation [here](https://min.io/docs/minio/linux/reference/minio-mc.html).

- Obtain an access key and a secret key to manage your buckets using the Minio client. For detailed instructions, please refer to our guide [here]({{< ref "/product/security/iam/quick-start/" >}}).


### Configure the Minio client

```bash
mc alias set myminio https://sos-de-fra-1.exo.io
```

Storage API Endpoint: https://sos-{zone}.exo.io

Replace {zone} with the intended value. Available sos zones are : ch-dk-2, ch-gva-2, de-fra-1, de-muc-1, at-vie-1, at-vie-2, bg-sof-1.

### Create a bucket

```bash
mc mb --with-lock myminio/mylockedbucket
```

> [!NOTE]
> You can only enable object locking during bucket creation as per S3 behavior. 
> You cannot enable object locking on a bucket created without locking enabled. 
> You can then configure object retention rules at any time. 
> Object locking requires versioning and enables the feature implicitly.

### Listing buckets

```bash
mc ls myminio
```

### Listing bucket content recursively

```bash
mc ls --recursive myminio/mylockedbucket
```

### Verify bucket versioning status

```bash
mc stat myminio/mylockedbucket
```

Output:

```bash
Name : mylockedbucket
Date : 2023-10-26 22:10:26 CET
Size : N/A
Type : folder

Properties:
Versioning: Enabled
Location: de-fra-1
Anonymous: Disabled
ILM: Disabled

Usage:
Total size: 0 B
Objects count: 0
Versions count: 0
```

### Upload an object to bucket

```bash
mc cp file_to_upload.txt myminio/mylockedbucket
```

### List all versions of my objects in a bucket

```bash
mc ls --versions myminio/mylockedbucket
```

### Delete a specific version of an object

```bash
mc rm myminio/mylockedbucket/file_to_upload.txt --version-id "916619044952888425"
```

### Remove a bucket and all its content      

```bash
mc rb --force myminio/mylockedbucket
```

### Set up the lock configuration for a bucket

```bash
mc retention set --default GOVERNANCE "30d" myminio/mylockedbucket
```


For additional details on Retention MODE and DURATION, please refer to this [guide](https://min.io/docs/minio/linux/administration/object-management/object-retention.html#id9).

### Show bucket configuration

Now that lock configuration was set, the `stat` command shows its status:

```bash
mc stat myminio/mylockedbucket
```

Output:

```bash
Name : mylockedbucket
Date : 2023-10-26 23:33:34 CET
Size : N/A
Type : folder

Properties:
Versioning: Enabled
LockConfiguration:
RetentionMode: GOVERNANCE
Retention Until Date: 30DAYS
Location: de-fra-1
Anonymous: Disabled
ILM: Disabled

Usage:
Total size: 0 B
Objects count: 0
Versions count: 0
```

Alternatively:

```bash
mc retention info myminio/mylockedbucket
```

Output:

```bash
Object locking 'GOVERNANCE' is configured for 30DAYS.
```

