Restoring an archived object - Amazon Simple Storage Service

Restoring an archived object

Amazon S3 objects that are stored in the S3 Glacier Flexible Retrieval or S3 Glacier Deep Archive storage classes are not immediately accessible. To access an object in these storage classes, you must restore a temporary copy of it to its S3 bucket for a specified duration (number of days). For information about using these storage classes, see Using Amazon S3 storage classes and Managing your storage lifecycle.

Restored objects from S3 Glacier Flexible Retrieval or S3 Glacier Deep Archive are stored in Amazon S3 Standard only for the number of days that you specify. If you want a permanent copy of the object, create a copy of it in your Amazon S3 bucket. Unless you make a copy, the object will still be stored in the S3 Glacier Flexible Retrieval or S3 Glacier Deep Archive storage classes.

To calculate the expiry date, Amazon S3 adds the number of days that you specify to the time that you request to restore the object, and then rounds to the next day at midnight UTC. This calculation applies to the initial restoration of the object and to any changes to availability that you request. For example, if an object was restored on October 15, 2012, at 10:30 AM UTC, and the number of days that you specified is 3, the object is available until October 19, 2012, at 00:00 UTC. If, on October 16, 2012, at 11:00 AM UTC, you change the number of days that you want the object to be accessible to 1, Amazon S3 makes the restored object available until October 18, 2012, at 00:00 UTC.

When you restore an archived object, you are paying for both the archive and a copy that you restored temporarily. For information about pricing, see Amazon S3 pricing.

You can restore an archived object by using the Amazon S3 console, the REST API, the AWS SDKs, and the AWS Command Line Interface (AWS CLI).

Use the following steps to restore an object that has been archived to the S3 Glacier Flexible Retrieval or S3 Glacier Deep Archive storage classes, to check the status, and to upgrade an in-progress restore. (The console uses the names S3 Glacier Flexible Retrieval and Glacier Deep Archive for these storage classes.)

To restore an archived object
  1. Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. In the Buckets list, choose the name of the bucket that contains the objects that you want to restore.

  3. In the Objects list, select the object or objects that you want to restore, choose Actions, and then choose Initiate restore.

  4. If you're restoring from S3 Glacier Flexible Retrieval or S3 Glacier Deep Archive, enter the number of days that you want your archived data to be accessible in the Initiate restore dialog box.

  5. In Retrieval options, do one of the following:

    • Choose Bulk retrieval or Standard retrieval, and then choose Restore.

    • Choose Expedited retrieval (available only for S3 Glacier Flexible Retrieval or S3 Intelligent-Tiering Archive Access).

  6. Provisioned capacity is only available for objects in S3 Glacier Flexible Retrieval. If you have provisioned capacity, choose Restore to start a provisioned retrieval.

    If you have provisioned capacity, all of your expedited retrievals are served by your provisioned capacity. For more information, see Provisioned capacity.

    • If you don't have provisioned capacity and you don't want to buy it, choose Restore.

    • If you don't have provisioned capacity, but you want to buy it, choose Add capacity unit, and then choose Buy. When you get the Purchase succeeded message, choose Restore to start provisioned retrieval.

You can upgrade the speed of your restoration while it is in progress.

To upgrade an in-progress restore to a faster tier
  1. Open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. In the Bucket name list, choose the name of the bucket that contains the objects that you want to restore.

  3. In the Objects list, select one or more of the objects that you are restoring, choose Actions, and then choose Restore from S3 Glacier Flexible Retrieval. For information about checking the restoration status of an object, see Checking restore status and expiration date.

  4. Choose the tier that you want to upgrade to, and then choose Restore.

    For information about upgrading to a faster restore tier, see Upgrading the speed of an in-progress restore.

    Note

    Standard and bulk restores for S3 Intelligent-Tiering are free of charge. However, subsequent restore requests called on an object that is already being restored are billed as a GET request.

Checking restore status and expiration date

You can check the progress of the restoration on the Object overview page. For more information, see Viewing an object overview in the Amazon S3 console. This page will show that the restoration is In progress.

If you're restoring from S3 Glacier Flexible Retrieval or S3 Glacier Deep Archive, the temporary copy of the Object overview shows the Restoration expiry date. Amazon S3 will remove the restored copy of your archive on this date.

Restored objects from S3 Glacier Flexible Retrieval or S3 Glacier Deep Archive are stored only for the number of days that you specify. If you want a permanent copy of the object, create a copy of it in your Amazon S3 bucket.

After restoring an object, you can download it from the Overview page. For more information, see Viewing an object overview in the Amazon S3 console.

Java

The following example restores a copy of an object that has been archived by using the AWS SDK for Java. The example initiates a restoration request for the specified archived object and checks its restoration status.

For instructions on creating and testing a working sample, see Testing the Amazon S3 Java Code Examples.

import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.regions.Regions; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.RestoreObjectRequest; import java.io.IOException; public class RestoreArchivedObject { public static void main(String[] args) throws IOException { Regions clientRegion = Regions.DEFAULT_REGION; String bucketName = "*** Bucket name ***"; String keyName = "*** Object key ***"; try { AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withCredentials(new ProfileCredentialsProvider()) .withRegion(clientRegion) .build(); // Create and submit a request to restore an object from Glacier for two days. RestoreObjectRequest requestRestore = new RestoreObjectRequest(bucketName, keyName, 2); s3Client.restoreObjectV2(requestRestore); // Check the restoration status of the object. ObjectMetadata response = s3Client.getObjectMetadata(bucketName, keyName); Boolean restoreFlag = response.getOngoingRestore(); System.out.format("Restoration status: %s.\n", restoreFlag ? "in progress" : "not in progress (finished or failed)"); } catch (AmazonServiceException e) { // The call was transmitted successfully, but Amazon S3 couldn't process // it, so it returned an error response. e.printStackTrace(); } catch (SdkClientException e) { // Amazon S3 couldn't be contacted for a response, or the client // couldn't parse the response from Amazon S3. e.printStackTrace(); } } }
.NET

The following C# example initiates a request to restore an archived object for 2 days. Amazon S3 maintains the restoration status in the object metadata. After initiating the request, the example retrieves the object metadata and checks the value of the RestoreInProgress property.

For instructions on creating and testing a working sample, see Running the Amazon S3 .NET Code Examples.

using Amazon; using Amazon.S3; using Amazon.S3.Model; using System; using System.Threading.Tasks; namespace Amazon.DocSamples.S3 { class RestoreArchivedObjectTest { private const string bucketName = "*** bucket name ***"; private const string objectKey = "** archived object key name ***"; // Specify your bucket region (an example region is shown). private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2; private static IAmazonS3 client; public static void Main() { client = new AmazonS3Client(bucketRegion); RestoreObjectAsync(client, bucketName, objectKey).Wait(); } static async Task RestoreObjectAsync(IAmazonS3 client, string bucketName, string objectKey) { try { var restoreRequest = new RestoreObjectRequest { BucketName = bucketName, Key = objectKey, Days = 2 }; RestoreObjectResponse response = await client.RestoreObjectAsync(restoreRequest); // Check the status of the restoration. await CheckRestorationStatusAsync(client, bucketName, objectKey); } catch (AmazonS3Exception amazonS3Exception) { Console.WriteLine("An AmazonS3Exception was thrown. Exception: " + amazonS3Exception.ToString()); } catch (Exception e) { Console.WriteLine("Exception: " + e.ToString()); } } static async Task CheckRestorationStatusAsync(IAmazonS3 client, string bucketName, string objectKey) { GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest { BucketName = bucketName, Key = objectKey }; GetObjectMetadataResponse response = await client.GetObjectMetadataAsync(metadataRequest); Console.WriteLine("restoration status: {0}", response.RestoreInProgress ? "in-progress" : "finished or failed"); } } }

Amazon S3 provides an API for you to initiate an archive restoration. For more information, see RestoreObject in the Amazon Simple Storage Service API Reference.

Use the restore-object command to restore objects from S3 Glacier Flexible Retrieval.

The following example restores the object dir1/example.obj in DOC-EXAMPLE-BUCKET for 25 days.

aws s3api restore-object --bucket DOC-EXAMPLE-BUCKET --key dir1/example.obj --restore-request '{"Days":25,"GlacierJobParameters":{"Tier":"Standard"}}'

If the JSON syntax used in the example results in an error on a Windows client, replace the restore request with the following syntax:

--restore-request Days=25,GlacierJobParameters={"Tier"="Standard"}

To monitor the status of your restore-object request, use the following head-object command:

aws s3api head-object --bucket DOC-EXAMPLE-BUCKET --key dir1/example.obj

For more information, see restore-object in the AWS CLI Command Reference.