All Products
Search
Document Center

Object Storage Service:revert-versioning

Last Updated:Aug 15, 2024

This topic describes how to run the revert-versioning command to restore an object in a versioning-enabled bucket to the most recent previous version.

Usage notes

  • To restore an object version, 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 directly use ossutil as the binary name in the command line. You do not need to update the binary name based on the operating system. For ossutil earlier than 1.6.16, you need to update the binary name based on the operating system. For more information, see ossutil command reference.

  • For more information about versioning, see Overview.

  • 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 table describes the parameters and options in the syntax.

Parameter/Option

Description

bucketname

The name of the bucket that contains the objects you want to restore.

prefix

The prefix in the names of resources, such as directories and objects.

--encoding-type

The encoding 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 whose names contain the prefix specified by the prefix option to the most recent previous version. If you do not specify this option, ossutil restores only the specified object to the most recent previous version.

--start-time

The beginning of the time range to filter objects by. The value is a UNIX timestamp. If you specify this option, objects deleted before this time are not restored.

--end-time

The end of the time range to filter objects by. The value is a UNIX timestamp. If you specify this option, objects deleted after this time are not restored.

--include

Includes all objects that meet the specified conditions.

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

--exclude

Excludes all objects that meet the specified conditions.

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

--payer

The payer of the fees that are generated by the operation. If you want the requester who accesses the resources in the specified path to pay for the traffic and request fees, set this option to requester.

Examples

  • Sample commands

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

      ossutil revert-versioning oss://examplebucket/exampleobject.jpg
    • Restore multiple deleted objects that are stored in the examplebucket bucket and whose names contain the specified destdir prefix to the most recent previous versions by specifying the -r option.

      ossutil revert-versioning oss://examplebucket/destdir -r
    • Restore all deleted objects in the examplebucket bucket to the most recent previous versions by specifying the -r option.

      ossutil revert-versioning oss://examplebucket  -r
    • Restore objects that are deleted during a specific period of time to the most recent previous versions.

      Restore objects that are deleted from 16:22:58 to 16:39:38 on June 16, 2020 (UTC+8) from the examplebucket bucket to the most recent previous versions by specifying the -r option.

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

      • Restore all deleted TXT objects in the examplebucket bucket to the most recent previous versions by specifying the -r option.

        ossutil revert-versioning oss://examplebucket --include "*.txt" -r
      • Restore all deleted objects in the examplebucket bucket, except JPG objects, to the most recent previous versions by specifying the -r option.

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

    A success response includes the number of restored objects and the amount of time consumed to restore these objects. Example:

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

Common options

If you use ossutil to switch to a bucket that is located in another region, add the -e option to the command to specify the endpoint of the region in which the specified bucket is located. If you use ossutil to switch to a bucket that belongs to another Alibaba Cloud account, add the -i option to the command to specify the AccessKey ID of the specified account, and add the -k option to the command to specify the AccessKey secret of the specified account.

For example, you can run the following command to restore the exampletest.png object in the testbucket bucket to the most recent previous version. The testbucket bucket is located in the China (Shanghai) region and owned by another Alibaba Cloud account.

ossutil revert-versioning oss://testbucket/exampletest.png -e oss-cn-shanghai.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA****  -k 67DLVBkH7EamOjy2W5RVAHUY9H****

For more information about common options, see Common options.