Run revert-versioning to revert a deleted object in a versioning-enabled bucket back to its most recent previous version.
How it works
When you delete an object in a versioning-enabled bucket, OSS inserts a delete marker and keeps all previous versions intact. The revert-versioning command removes that delete marker, which makes the most recent previous version the current version again.
Note: revert-versioning only works on objects that have a delete marker as their current version. If an object was overwritten rather than deleted, the command has no effect on it.Prerequisites
Before you begin, ensure that you have:
A versioning-enabled OSS bucket
The
oss:ListObjectVersionsandoss:DeleteObjectVersionpermissions on the target bucket. For details, see Attach a custom policy to a RAM userossutil installed. For ossutil 1.6.16 and later, use
ossutildirectly as the binary name. For earlier versions, update the binary name based on your operating system. For details, see ossutil command reference
Syntax
ossutil revert-versioning oss://bucketname[/prefix]
[--encoding-type <value>]
[-r, --recursive]
[--start-time <value>]
[--end-time <value>]
[--include <value>]
[--exclude <value>]
[--payer <value>]Parameters and options
| Parameter/Option | Description |
|---|---|
bucketname | The name of the bucket that contains the objects to revert. |
prefix | A prefix to filter objects and directories by name. |
--encoding-type | The encoding of the prefix that follows oss://bucketname. Valid value: url. If not specified, the prefix is not encoded. |
-r, --recursive | Reverts all objects whose names match the specified prefix. Without this option, only the specified object is reverted. |
--start-time | A UNIX timestamp. Objects deleted before this time are not reverted. |
--end-time | A UNIX timestamp. Objects deleted after this time are not reverted. |
--include | Reverts only objects that match the specified pattern. For details, see Options --include and --exclude. |
--exclude | Skips objects that match the specified pattern. For details, see Options --include and --exclude. |
--payer | The fee payer for the operation. Set to requester to charge the requester for traffic and request fees. |
Examples
Revert a single object
ossutil revert-versioning oss://examplebucket/exampleobject.jpgRevert all objects with a prefix
ossutil revert-versioning oss://examplebucket/destdir -rRevert all deleted objects in a bucket
ossutil revert-versioning oss://examplebucket -rRevert objects deleted within a time range
The following command reverts objects deleted between 16:22:58 and 16:39:38 on June 16, 2020 (UTC+8):
ossutil revert-versioning oss://examplebucket -r --start-time 1592295778 --end-time 1592296778Revert objects by file type
Revert only TXT objects:
ossutil revert-versioning oss://examplebucket --include "*.txt" -rRevert all objects except JPG objects:
ossutil revert-versioning oss://examplebucket --exclude "*.jpg" -rSample output
A successful run returns the number of reverted objects and the elapsed time:
revert versioning object count is 10, batch list count is 10
0.066413(s) elapsedAccess a bucket in a different region or account
To access a bucket in a different region, add -e to specify the bucket's endpoint. To access a bucket owned by a different Alibaba Cloud account, add -i and -k to specify that account's AccessKey ID and AccessKey secret.
The following command reverts exampletest.png in testbucket, which is in the China (Shanghai) region and owned by a different account:
ossutil revert-versioning oss://testbucket/exampletest.png -e oss-cn-shanghai.aliyuncs.com -i yourAccessKeyID -k yourAccessKeySecretWhat's next
Overview — Learn how versioning works in OSS.
Delete marker — Understand how delete markers affect object retrieval.