All Products
Search
Document Center

Object Storage Service:revert-versioning

Last Updated:Oct 11, 2023

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

  • 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 delete markers, 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 options that you can configure to run the revert-versioning command.

Option

Description

bucketname

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

prefix

The resources in the bucket whose names contain the specified prefix, such as directories or objects.

--encoding-type

The method used to encode 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

A UNIX timestamp. If you specify this option, objects deleted before this time are not restored.

--end-time

A UNIX timestamp. If you specify this option, objects deleted after this time are not restored.

--include

Specifies that the command applies to all objects that meet the specified conditions.

For more information, see revert-versioning.

--exclude

Specifies that the command applies to all objects that do not meet the specified conditions.

For more information, see revert-versioning.

--payer

The payer of the request. 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

  • Examples on how to restore specific objects

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

      ./ossutil64 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 version by specifying the -r option.

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

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

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

      ./ossutil64 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 version.

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

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

        
        ./ossutil64 revert-versioning oss://examplebucket --exclude "*.jpg" -r
  • Output

    After the specified objects are restored, a result that indicates the number of restored objects and the amount of time consumed to restore these objects is returned. 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, you can 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.

./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 sync command, see View options.