All Products
Search
Document Center

Object Storage Service:revert-versioning

Last Updated:Apr 03, 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.

  • This topic provides sample command lines that 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 command reference.

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 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 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

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 traffic and request fees. If you want the requester who accesses the resources in the specified path to pay 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.

      ./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 versions 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 versions 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 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.

      ./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 versions.

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

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

        
        ./ossutil64 revert-versioning oss://examplebucket --exclude "*.jpg" -r
  • Sample 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, 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 Common options.