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

Note
  • Sample command lines in this topic are based on the 64-bit Linux system. For other systems, replace ./ossutil64 in the commands with the corresponding binary name. For more information, see ossutil.
  • For more information about versioning, see Overview.
  • For more information about how to remove a delete maker, see Delete marker.

Command syntax

./ossutil64 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 that you can configure when you run this command.

Parameter Description
bucketname The name of the bucket that contains the objects you want to recover .
prefix The resources in the bucket, such as directories and objects.
--encoding-type The method used to encode the prefix specified by the object name that follows oss://bucket_name in the full object path. Valid value: url. If this parameter is not specified, the prefix is not encoded.
-r, --recursive If you specify this parameter in the command, ossutil recovers all objects whose names contain the prefix specified by this parameter to the most recent previous version. If you do not specify this parameter in the command, ossutil recovers only the specified object to the most recent previous version.
--start-time A UNIX timestamp. If you specify this option in the command, objects deleted before this time are not recovered.
--end-time A UNIX timestamp. If you specify this option in the command, objects deleted after this time are not recovered.
--include Specifies that the command applies to all objects that meet specified conditions.
--exclude Specifies that the command applies to all objects that do not meet specified conditions.
--payer The payer of the traffic and request fees incurred when the command is run. If you want the requester who accesses the resources in the specified path to pay for the traffic and request fees incurred during queries, set this parameter to requester.

Examples

  • Examples on how to recover specified objects
    • Recover the deleted exampleobject.jpg object in the examplebucket bucket to the most recent previous version.
      ./ossutil64 revert-versioning oss://examplebucket/exampleobject.jpg
    • Recover multiple deleted objects that are stored in the examplebucket bucket and whose names contain the specified destdir prefix to the most recent previous version by combining the -r option.
      ./ossutil64 revert-versioning oss://examplebucket/destdir -r
    • Recover all deleted objects in the examplebucket bucket to the most recent previous version by combining the -r option.
      ./ossutil64 revert-versioning oss://examplebucket  -r
    • Recover objects that have been deleted during a specified period of time to the most recent previous version.

      Recover objects that have been deleted between 16:22:58, 16 June 2020, UTC+8 and 16:39:38, 16 June 2020, UTC+8 and were stored in the examplebucket bucket to the most recent previous version by combining the -r option.

      ./ossutil64 revert-versioning oss://examplebucket -r --start-time 1592295778 --end-time 1592296778
    • Recover all deleted objects that match the specified conditions to the most recent previous version.
      • Recover all the deleted TXT objects in the examplebucket bucket to the most recent previous version by combining the -r option.
        ./ossutil64 revert-versioning oss://examplebucket --include "*.txt" -r
      • Recover all the deleted objects, except for the JPG objects, to the most recent previous version by combining the -r option.
        
        ./ossutil64 revert-versioning oss://examplebucket --exclude "*.jpg" -r
  • Returned results

    After the specified objects are recovered, a result that contains the number of recovered objects and the time taken to recover these objects is returned. Example:

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

Common options

To use ossutil to manage buckets that are located in different regions, you can use the -e option to use the endpoint of the specified bucket. To use ossutil to manage buckets that are owned by different Alibaba Cloud accounts, you can use the -i option to use the AccessKey ID of the specified account, and use the -k option to use the AccessKey secret of the specified account.

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

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

For more information about other common options that you can use for the revert-versioning command, see Common options.