All Products
Search
Document Center

Object Storage Service:revert-versioning

Last Updated:Sep 24, 2026

The revert-versioning command restores a deleted object in a versioning-enabled bucket to its most recent version.

Usage notes

  • To restore a version of an object, you must have the oss:ListObjectVersions and oss:DeleteObjectVersion permissions. For more information, see Attach a custom policy to a RAM user.

  • For ossutil 1.6.16 and later, you can use ossutil as the binary name in commands. You do not need to change the binary name for different operating systems. For versions of ossutil earlier than 1.6.16, you must change the binary name based on the operating system. For more information, see ossutil command reference.

  • For more information about versioning, see Versioning.

  • For more information about delete markers, see Delete marker.

Command syntax

ossutil revert-versioning oss://bucketname[/prefix]
[--encoding-type <value>]
[-r,--recursive]
[--start-time <value> ]
[--end-time <value>]
[--include <value>]
[--exclude <value>]
[--payer <value>]

The following describes the parameters and options:

Parameter/Option

Description

bucketname

The name of the bucket.

prefix

Resources in a bucket, such as folders and files.

--encoding-type

The encoding type of the prefix that follows oss://bucket_name. Valid value: url. If you do not specify this option, the prefix is not encoded.

-r, --recursive

If you specify this option, ossutil restores all objects that match the prefix to their most recent versions. If you do not specify this option, ossutil restores only the specified object to its most recent version.

--start-time

The start of the time range. The value is a UNIX timestamp. If you specify this option, objects deleted before this time are ignored.

--end-time

The end of the time range. The value is a UNIX timestamp. If you specify this option, objects deleted after this time are ignored.

--include

Includes all objects that meet the specified conditions.

For more information, see --include and --exclude options.

--exclude

There are no objects that meet the specified conditions.

For more information, see --include and --exclude options.

--payer

The payer for the request. If you want the requester who accesses the resources in the specified path to pay for fees such as traffic and requests, set this option to requester.

Examples

  • Recovery scenario

    • Restore the deleted object exampleobject.jpg in the bucket examplebucket to its most recent version.

      ossutil revert-versioning oss://examplebucket/exampleobject.jpg
    • Use the -r option to restore multiple deleted objects that match the prefix destdir in the bucket examplebucket to their most recent versions.

      ossutil revert-versioning oss://examplebucket/destdir -r
    • Use the -r option to restore all deleted objects in the bucket examplebucket to their most recent versions.

      ossutil revert-versioning oss://examplebucket  -r
    • Restore objects that were deleted within a specified time range to their most recent versions.

      Use the -r option to restore objects that were deleted from the bucket examplebucket between 16:22:58 and 16:39:38 (UTC+8) on June 16, 2020 to their most recent versions.

      ossutil revert-versioning oss://examplebucket -r --start-time 1592295778 --end-time 1592296778
    • Restore all deleted objects that match specified conditions to their most recent versions.

      • Use the -r option to restore all deleted TXT objects in the bucket examplebucket to their most recent versions.

        ossutil revert-versioning oss://examplebucket --include "*.txt" -r
      • Use the -r option to restore all deleted objects, except for JPG objects, in the bucket examplebucket to their most recent versions.

        
        ossutil revert-versioning oss://examplebucket --exclude "*.jpg" -r
  • Sample output

    If the objects are restored, the output includes the number of restored objects and the time taken. The following is a sample output:

    revert versioning object count is 10, batch list count is 10
    
    0.066413(s) elapsed

Common options

To access a bucket in a different region, use -e to specify the endpoint. To access a bucket owned by a different Alibaba Cloud account, use -i for the AccessKey ID and -k for the AccessKey secret.

For example, to restore the deleted object exampletest.png in the bucket testbucket to its most recent version, run the following command. The bucket is in the China (Shanghai) region and belongs to another Alibaba Cloud account.

ossutil revert-versioning oss://testbucket/exampletest.png -e oss-cn-shanghai.aliyuncs.com -i yourAccessKeyID  -k yourAccessKeySecret

Common options.