When versioning is enabled for a bucket, overwritten or deleted data is preserved as previous versions. To minimize storage costs and enhance object listing performance, configure lifecycle rules to remove expired delete markers and unnecessary previous versions.
Prerequisites
Versioning must be enabled for the bucket. For more information, see Enable versioning.
Scenario description
After enabling versioning for the target bucket examplebucket, a user uploads a file named example.txt on February 8. The user then performs multiple overwrites or deletions on the file without specifying a version ID at various times throughout the year. OSS assigns a unique random string version ID to each operation and retains the file as a previous version in the bucket.
Following multiple overwrites and deletions without specifying a version ID, the user aims to:
Keep only the versions created on May 8 and September 10.
Restore the latest previous version from May 8 as the current version.
Procedure
-
Retain specified object versions
Assuming today is September 10, the user can configure a lifecycle rule to retain only the versions from May 8 and September 10 by following these steps:
Log on to the OSS console.
Click Buckets, and then select examplebucket.
Choose
.Click Create Rule and set up the lifecycle rule accordingly, keeping the default settings for other parameters.
Area
Configuration item
Configuration method
Basic Settings
Status
Select Enable.
Applied To
Select Whole Bucket.
Policy for Current Versions
Object Lifecycle
Select Clear Object Delete Markers.
Policy for Previous Versions
Object Lifecycle
Select Specified Days.
Lifecycle-based Rules
Select the last Modified Time 90 days. The object expires 90 days after it is converted to a previous version and is deleted on the second day after expiration.
NoteIn this example, the file uploaded on May 8 becomes a previous version on September 10, which is less than 90 days from the current date (September 10). Therefore, the file uploaded on May 8 is retained as a previous version and is not deleted.
Policy for Parts
Part Lifecycle
Select Specified Days.
Rules for Parts
Set to 90 days. The fragments generated by multipart upload expire 90 days later and are deleted on the second day after expiration.
Click OK.
-
Restore a specific object version
To restore the latest previous version of example.txt from May 8 as the current version, follow these steps:
Navigate to the examplebucket management page and select Object Management > Objects.
Click Show next to Previous Versions.
Locate the previous version of example.txt you want to restore.
Click Restore next to the desired previous version.
Considerations
When managing object versions with lifecycle expiration policies:
-
Expiration policy for the current version of an object
In a versioning-enabled bucket, applying an expiration policy to the current version results in OSS adding a delete marker, making the current version a previous version. The delete marker becomes the new current version.
In a versioning-suspended bucket, applying an expiration policy to the current version results in OSS adding a delete marker with a null version ID, which becomes the new current version. If a null version ID already exists, it is overwritten by the new delete marker, as only one such version is allowed.
-
Expiration policy for a previous version of an object
For buckets with enabled or suspended versioning, applying an expiration policy to a previous version permanently deletes that version, making it irrecoverable.
For more information, see Lifecycle rules based on the last modified time.
References
API operations can be used to restore objects. To revert a previous version to the current version, copy the previous version to the same bucket. OSS will then treat the copied version as the current one. For more information, see CopyObject.