Restoring an object version in a versioned bucket
To restore object versions, the bucket must be versioned. 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 version using the management console is 25 seconds. Large versions might not successfully restore within this time. If restoring fails, use other tools, such as the AWS CLI or API.
To restore an object version:
- In the management console
, select Object Storage from the list of services and go to the bucket in question. - In the left-hand panel, select
Objects and find the object in the list. - Select the object whose version you want to restore, click
, and select Version history. - In the list of versions, click
Restore in the row with the version you need. This will restore the selected version and make it the current one.
To restore an object version using the AWS CLI:
-
Get the ID of the object version you need:
aws s3api list-object-versions \ --endpoint-url https://storage.yandexcloud.net \ --bucket <bucket_name> \ --prefix <object_key_prefix>
The result will be a list of versions for all objects whose keys start with the specified prefix. 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 select a single object:
-
Install and initialize jq
. -
Filter the result:
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 this article
of the AWS CLI command reference. -
-
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 to copy, specifying the version ID.--key
: Target object key. To restore the object version, make sure the keys of the target and source objects match.
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 this article
of the AWS CLI command reference.
To restore an object version:
- Get the ID of the object version you need using the listObjectVersions S3 API method.
- Copy the object version to the same bucket with the same key using the copy S3 API method.