Restoring an object's version in a bucket with versioning
You can only restore object versions if a bucket supports versioning. You can only restore the versions that were uploaded with versioning enabled. To enable versioning, follow this guide.
Warning
The timeout for restoring an object's version through the management console is 25 seconds. It may expire before large versions are restored. If restoring fails, use other tools, such as the AWS CLI or API.
To restore an object's version:
- In the management console
, select Object Storage from the list of services and go to the bucket you need. - In the left-hand panel, select
Objects and find the object in the list. - Select the object whose version you want to restore and click
→ Version history. - In the list of versions, click
Restore in the row with the version you need. This restores the selected version and displays it as the current one.
To restore an object's version using the AWS CLI:
-
Get the ID of the desired object version:
aws s3api list-object-versions \ --endpoint-url https://storage.yandexcloud.net \ --bucket <bucket_name> \ --prefix <object_key_prefix>
As a result, a list of versions of all objects whose keys start with the specified prefix is displayed. Version IDs are available in the
VersionId
parameters.Example of getting a list of versions
Command:
aws s3api list-object-versions \ --endpoint-url https://storage.yandexcloud.net \ --bucket my-bucket \ --prefix index.html
Result:
{ "Versions": [ { "LastModified": "2015-11-10T00:20:11.000Z", "VersionId": "Rb_l2T8UHDkFEwCgJjhlgPOZ********", "ETag": "\"0622528de826c0df5db1258a********\"", "StorageClass": "STANDARD", "Key": "index.html", "Owner": { "DisplayName": "my-username", "ID": "7009a8971cd660687538875e7c86c5b672fe116bd438f46db45460dd********" }, "IsLatest": true, "Size": 38 }, { "LastModified": "2015-11-09T23:26:41.000Z", "VersionId": "rasWWGpgk9E4s0LyTJgusGeR********", "ETag": "\"06225825b8028de826c0df5d********\"", "StorageClass": "STANDARD", "Key": "index.html", "Owner": { "DisplayName": "my-username", "ID": "7009a8971cd660687538875e7c86c5b672fe116bd438f46db45460dd********" }, "IsLatest": false, "Size": 38 } ] }
To only select a single object:
-
Install and initialize jq
. -
Filter the results:
aws s3api list-object-versions \ --endpoint-url https://storage.yandexcloud.net \ --bucket <bucket_name> \ --prefix <object_key_prefix> \ | jq '.Versions | map(select(.Key == "<object_key>"))'
For more information about the command, see its description in the Amazon documentation
. -
-
Copy the object version to the same bucket with the same key to make it the current object version:
aws s3api copy-object \ --endpoint-url https://storage.yandexcloud.net \ --bucket <bucket_name> \ --copy-source <bucket_name>/<object_key>?versionId=<version_ID> \ --key <object_key>
Where:
--bucket
: Bucket name.--copy-source
: Source object for copying stating the version ID.--key
: Target object key. To restore the object version, make sure the keys of the target and source objects are the same.
Result:
{ "CopyObjectResult": { "LastModified": "<date_and_time_of_last_object_modification>", "ETag": "\"589c8b79c230a6ecd5a7e1d040a9a030\"" }, "VersionId": "<ID_of_restored_object_version>" }
For more information about the command, see its description in the Amazon documentation
.
To restore an object's version:
- Get the ID of the required object version using the listObjectVersions S3 API method.
- Copy the object version to the same bucket with the same key using the copy S3 API method.