Updated on 2024-05-31 GMT+08:00

Versioning

Scenarios

OBS can store multiple versions of an object. You can quickly search for and restore different versions or restore data in the event of accidental deletions or application faults.

By default, versioning is disabled for new OBS buckets. New objects will overwrite existing objects in case they have the same names.

Constraints

When you enable WORM for a bucket, OBS automatically enables versioning and versioning cannot be suspended later for that bucket.

Enabling Versioning

  • Enabling versioning does not change the versions or contents of existing objects in the bucket. The version ID of an object is null before versioning is enabled. If a namesake object is uploaded after versioning is enabled, a version ID will be assigned to the object. For details, see Figure 1.
    Figure 1 Versioning (enabled vs. disabled)
  • With versioning enabled, OBS automatically allocates a unique version ID to a newly uploaded object. When an object with the same name as an existing object is uploaded again, both objects are stored in OBS with the same name but different version IDs. For details, see Figure 2.
    Figure 2 Versioning (different version IDs for objects with the same name)
    Table 1 Version description

    Version

    Description

    Latest version

    After versioning is enabled, each operation on an object will result in saving of the object with a new version ID. The version ID generated upon the latest operation is called the latest version.

    Historical Version

    After versioning is enabled, each operation on an object will result in saving of the object with a new version ID. Version IDs generated upon operations other than the latest operation are called historical versions.

  • The latest objects in a bucket are returned by default after a GET Object request.
  • Objects can be downloaded by version IDs. By default, the latest object is downloaded if the version ID is not specified.
  • You can select an object and click Delete on the right to delete the object. After the object is deleted, OBS generates a Delete Marker with a unique version ID for the deleted object, and the deleted object is displayed in the Deleted Objects list. If you try to access the deleted object, a 404 error will be returned.
    Figure 3 Object with a delete marker
  • You can recover a deleted object by deleting the version having a delete marker.
  • After an object is deleted, you can specify the version number in Deleted Objects to permanently delete the object of the specified version.
  • An object is displayed either in the object list or the list of deleted objects. It will never be displayed in both the lists at the same time.

    For example, after object A is uploaded and deleted, it will be displayed in the Deleted Objects list. If you upload an object named A again, the object A will be displayed in the Objects list, and the previously deleted object A will no longer be displayed in the Deleted Objects list. For details, see Figure 4.

    Figure 4 Uploading a namesake object after the original one is deleted
  • All object versions except those with Delete Marker stored in OBS are charged.

Suspending Versioning

Once the versioning function is enabled, it can be suspended but cannot be disabled. Once versioning is suspended, version IDs will no longer be allocated to newly uploaded objects. If an object with the same name already exists and does not have a version ID, the object will be overwritten.

Figure 5 Object versions in the scenario when versioning is suspended

If versions of objects in a bucket do not need to be controlled, you can suspend the versioning function.

  • Historical versions will be retained in OBS. If you do not need these historical versions, manually delete them.
  • Objects can be downloaded by version IDs. By default, the latest object is downloaded if the version ID is not specified.
  • All historical object versions except those with Delete Marker stored in OBS are charged.

Differences Between Scenarios When Versioning Is Suspended and Disabled

If you delete an object when versioning is suspended, a null version with the Delete Marker is generated regardless of whether the object has historical versions. But, if versioning is disabled, the same operation will not generate a version with the Delete Marker.

After versioning is enabled, each historical version of an object is stored and occupies storage space. OBS charges storage fees for all versions. Exercise caution to avoid extra storage fees.

How to Use

You can configure versioning through the OBS Console, APIs, and SDKs.

Tool

Reference

OBS Console

Configuring Versioning

SDKs

OBS supports software development kits (SDKs) in multiple languages. For details, see the corresponding developer guide on the SDK Overview page.

API

Configuring Versioning for a Bucket