Implementation for accessing Glacier Amazon Glacier is a storage solution for "cold data."

Amazon Glacier is an extremely low-cost storage service that provides secure, durable, and easy-to-use storage for data backup and archival. With Amazon Glacier, customers can store their data cost effectively for months, years, or decades. Amazon Glacier also enables customers to offload the administrative burdens of operating and scaling storage to AWS, so they don't have to worry about capacity planning, hardware provisioning, data replication, hardware failure and recovery, or time-consuming hardware migrations.

Amazon Glacier is a great storage choice when low storage cost is paramount, your data is rarely retrieved, and retrieval latency of several hours is acceptable. If your application requires fast or frequent access to your data, consider using Amazon S3. For more information, see Amazon Simple Storage Service (Amazon S3).

You can store any kind of data in any format. There is no maximum limit on the total amount of data you can store in Amazon Glacier.

If you are a first-time user of Amazon Glacier, we recommend that you begin by reading the following sections in the Amazon Glacier Developer Guide:

  • What is Amazon Glacier - This section of the Developer Guide describes the underlying data model, the operations it supports, and the AWS SDKs that you can use to interact with the service.

  • Getting Started with Amazon Glacier - The Getting Started section walks you through the process of creating a vault, uploading archives, creating jobs to download archives, retrieving the job output, and deleting archives.

Inheritance: AmazonServiceClient, IAmazonGlacier
Exemple #1
0
 /// <summary>
 /// Initializes a new downloader instance
 /// </summary>
 /// <param name="glacier">
 /// The Glacier client interface
 /// </param>
 /// <param name="vault">
 /// The current Glacier vault name
 /// </param>
 public GlacierDownloader(
     AmazonGlacierClient glacier,
     String vault)
 {
     this.glacier = glacier;
      this.vault = vault;
      this.jobStreams = new Dictionary<String, Stream>();
 }
        public void StartSession()
        {
            StopSession();

            disposed = false;
            Client = new AmazonGlacierClient(Mapping.AccessKey, Mapping.SecretKey, Mapping.Endpoint);
            Manager = new ArchiveTransferManager(Client);
        }
        public static List<GlacierJobDescription> listJobs(FolderVaultMapping mapping)
        {
            using (AmazonGlacierClient client = new AmazonGlacierClient(mapping.AccessKey, mapping.SecretKey, mapping.Endpoint))
            {
                ListJobsRequest req = new ListJobsRequest();
                req.AccountId = "-";
                req.Completed = false;
                req.VaultName = mapping.VaultName;

                return client.ListJobs(req).ListJobsResult.JobList;
            }
        }
 private static bool DeleteVault(string vaultName)
 {
     using (IAmazonGlacier client = new AmazonGlacierClient(RegionEndpoint.EUWest1))
     {
         DeleteVaultRequest request = new DeleteVaultRequest()
         {
             VaultName = vaultName
         };
         DeleteVaultResponse response = client.DeleteVault(request);
         return (response.HttpStatusCode == System.Net.HttpStatusCode.NoContent);
     }
 }
        public static DescribeJobResult describeJob(FolderVaultMapping mapping, string jobId)
        {
            using (AmazonGlacierClient client = new AmazonGlacierClient(mapping.AccessKey, mapping.SecretKey, mapping.Endpoint))
            {
                DescribeJobRequest req = new DescribeJobRequest();
                req.AccountId = "-";
                req.JobId = jobId;
                req.VaultName = mapping.VaultName;

                return client.DescribeJob(req).DescribeJobResult;
            }
        }
Exemple #6
0
 /// <summary>
 /// Initializes a new vault archive uploader
 /// </summary>
 /// <param name="glacier">
 /// The Glacier client interface
 /// </param>
 /// <param name="vault">
 /// The current Glacier vault name
 /// </param>
 public GlacierUploader(AmazonGlacierClient glacier, String vault)
 {
     this.glacier = glacier;
      this.vault = vault;
      this.partOffset = 0;
      this.partStream = IO.FileSystem.Temp();
      this.partStream.SetLength(PartSize);
      this.readBuffer = new Byte[65536];
      this.partChecksums = new List<String>();
      this.archiveOffset = 0;
      this.uploadID = this.glacier.InitiateMultipartUpload(
     new InitiateMultipartUploadRequest()
     {
        VaultName = this.vault,
        PartSize = PartSize
     }
      ).InitiateMultipartUploadResult.UploadId;
 }
 private static bool DeleteArchive(string vaultName, string archiveId)
 {
     try
     {
         using (IAmazonGlacier client = new AmazonGlacierClient(RegionEndpoint.EUWest1))
         {
             DeleteArchiveRequest request = new DeleteArchiveRequest()
             {
                 VaultName = vaultName,
                 ArchiveId = archiveId
             };
             DeleteArchiveResponse response = client.DeleteArchive(request);
             return (response.HttpStatusCode == System.Net.HttpStatusCode.NoContent);
         }
     }
     catch (ResourceNotFoundException)
     {
         return true; // already removed
     }
 }
 private static string RequestInventory(string vaultName)
 {
     using (IAmazonGlacier client = new AmazonGlacierClient(RegionEndpoint.EUWest1))
     {
         InitiateJobRequest initJobRequest = new InitiateJobRequest()
         {
             VaultName = vaultName,
             JobParameters = new JobParameters()
             {
                 Type = "inventory-retrieval",
                 Format = "CSV"
             }
         };
         InitiateJobResponse initJobResponse = client.InitiateJob(initJobRequest);
         return initJobResponse.JobId;
     }
 }
        private static List<GlacierJobDescription> ListInventory(string vaultName)
        {
            using (IAmazonGlacier client = new AmazonGlacierClient(RegionEndpoint.EUWest1))
            {
                ListJobsRequest request = new ListJobsRequest()
                {
                    VaultName = vaultName
                };

                ListJobsResponse response = client.ListJobs(request);
                return response.JobList;
            }
        }
        private static bool IsInventoryReady(string jobId, string vaultName)
        {
            using (IAmazonGlacier client = new AmazonGlacierClient(RegionEndpoint.EUWest1))
            {
                DescribeJobRequest request = new DescribeJobRequest()
                {
                    JobId = jobId,
                    VaultName = vaultName
                };

                DescribeJobResponse response = client.DescribeJob(request);
                return response.Completed;
            }
        }
Exemple #11
0
        private void retrieveMetadata_Click(object sender, EventArgs e)
        {
            try
            {
                AmazonGlacierClient client = new AmazonGlacierClient(this.getRegionEndpoint());
                DescribeVaultRequest describeVaultRequest = new DescribeVaultRequest()
                {
                    VaultName = vaultName.Text
                };
                DescribeVaultResponse describeVaultResponse = client.DescribeVault(describeVaultRequest);
                DescribeVaultResult describeVaultResult = describeVaultResponse.DescribeVaultResult;

                String result =
                    "VaultName: " + describeVaultResult.VaultName +
                    "\nVaultARN: " + describeVaultResult.VaultARN +
                    "\nVaultCreationDate: " + describeVaultResult.CreationDate +
                    "\nNumberOfArchives: " + describeVaultResult.NumberOfArchives +
                    "\nSizeInBytes: " + describeVaultResult.SizeInBytes +
                    "\nLastInventoryDate:" + describeVaultResult.LastInventoryDate
                ;
                MessageBox.Show(result, "Vault description");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private OperationResult EstablishClient(AddonManifest manifest, DeveloperOptions devOptions, out AmazonGlacierClient client)
        {
            OperationResult result;

            bool requireCreds;
            //var accessKey = manifest.ProvisioningUsername;
            //var secretAccessKey = manifest.ProvisioningPassword;
            var accessKey = devOptions.AccessKey;
            var secretAccessKey = devOptions.SecretAccessKey;

            var prop =
                manifest.Properties.First(
                    p => p.Key.Equals("requireDevCredentials", StringComparison.InvariantCultureIgnoreCase));

            if (bool.TryParse(prop.Value, out requireCreds) && requireCreds)
            {
                if (!ValidateDevCreds(devOptions))
                {
                    client = null;
                    result = new OperationResult()
                    {
                        IsSuccess = false,
                        EndUserMessage =
                            "The add on requires that developer credentials are specified but none were provided."
                    };
                    return result;
                }

                accessKey = devOptions.AccessKey;
                secretAccessKey = devOptions.SecretAccessKey;
            }

            AmazonGlacierConfig config = new AmazonGlacierConfig() { RegionEndpoint = RegionEndpoint.USEast1 };
            client = new AmazonGlacierClient(devOptions.AccessKey, devOptions.SecretAccessKey, config);
            result = new OperationResult { IsSuccess = true };
            return result;
        }
Exemple #13
0
 /// <summary>
 /// Commits the current vault archive
 /// </summary>
 /// <returns>
 /// The completed vault archive identifier
 /// </returns>
 public String Complete()
 {
     // upload any oustatanding buffered part data
      if (this.partOffset > 0)
     Flush();
      // complete the vault archive and clean up
      var archiveID = this.glacier.CompleteMultipartUpload(
     new CompleteMultipartUploadRequest()
     {
        VaultName = this.vault,
        UploadId = this.uploadID,
        ArchiveSize = this.Length.ToString(),
        Checksum = TreeHashGenerator.CalculateTreeHash(this.partChecksums)
     }
      ).CompleteMultipartUploadResult.ArchiveId;
      this.glacier = null;
      this.vault = null;
      this.partStream.Dispose();
      this.partStream = null;
      this.readBuffer = null;
      this.partChecksums = null;
      this.uploadID = null;
      this.archiveOffset = 0;
      return archiveID;
 }
        private void completeJob(Dictionary<string, string> properties, string action)
        {
            FolderVaultMapping mapping = Context.Mapping;
            string jobId = properties.ContainsKey("JobId") ? properties["JobId"] : null;

            if (jobId != null)
            {
                using (AmazonGlacierClient client = new AmazonGlacierClient(mapping.AccessKey, mapping.SecretKey, mapping.Endpoint))
                {
                    GetJobOutputRequest gReq = new GetJobOutputRequest();
                    GetJobOutputResponse gResp;
                    GetJobOutputResult gResult;

                    gReq.AccountId = "-";
                    gReq.JobId = jobId;
                    gReq.VaultName = mapping.VaultName;
                    gResp = client.GetJobOutput(gReq);
                    gResult = gResp.GetJobOutputResult;

                    using (Stream input = gResult.Body)
                    {
                        if (action == "InventoryRetrieval")
                        {
                            handleInventory(properties, input);
                        }
                        else if (action == "ArchiveRetrieval")
                        {
                            handleArchive(properties, input);
                        }
                    }
                }
            }
        }
        public string run()
        {
            if (!KeepRunning())
            {
                return null;
            }

            string jobId;
            using (AmazonGlacierClient client = new AmazonGlacierClient(Mapping.AccessKey, Mapping.SecretKey, Mapping.Endpoint))
            {
                InitiateJobRequest iReq = new InitiateJobRequest();

                iReq.AccountId = "-";
                iReq.VaultName = Mapping.VaultName;
                iReq.JobParameters = getJobParameters();

                try
                {
                    jobId = client.InitiateJob(iReq).InitiateJobResult.JobId;
                    if (SendJobScheduledNotification)
                    {
                        Notification notice = getJobScheduledNotification(jobId);
                        if (notice != null)
                        {
                            notice.publish(Mapping, false);
                        }
                    }
                }
                catch (ResourceNotFoundException)
                {
                    jobId = null;
                }
            }

            return jobId;
        }
Exemple #16
0
 /// <summary>
 /// Releases the resources associated with the store
 /// </summary>
 public void Dispose()
 {
     if (this.s3 != null)
     this.s3.Dispose();
      if (this.glacier != null)
     this.glacier.Dispose();
      this.s3 = null;
      this.glacier = null;
 }
Exemple #17
0
 public PWGlacierAPI(string vaultName, string archiveName)
 {
     _amazonGlacierClient = new AmazonGlacierClient(Amazon.RegionEndpoint.USEast1);
     _vault = vaultName;
     _archive = archiveName;
 }
Exemple #18
0
 /// <summary>
 /// Opens the connection to the store
 /// </summary>
 public void Open()
 {
     // connect to AWS S3 and Glacier
      var credentials = new BasicAWSCredentials(
     this.AccessKey,
     this.SecretKey
      );
      this.arn = new AmazonIdentityManagementServiceClient(credentials)
     .GetUser().GetUserResult.User.Arn;
      this.s3 = Amazon.AWSClientFactory.CreateAmazonS3Client(credentials);
      this.glacier = new AmazonGlacierClient(credentials);
      // ensure the bucket for the store exists
      this.s3.PutBucket(
     new PutBucketRequest()
     {
        BucketName = this.Bucket
     }
      );
 }
Exemple #19
0
        public ListJobsResult ListJobs()
        {
            AmazonGlacierClient client = new AmazonGlacierClient(awsCredentials, glacierConfig);
            ListJobsRequest request = new ListJobsRequest().WithVaultName(vaultName);
            ListJobsResponse response = client.ListJobs(request);
            System.Console.WriteLine(response.ListJobsResult.JobList.Count);

            return response.ListJobsResult;
        }
        private UploadArchiveResponse StoreArchive(Stream uncompressedContent, string archiveDescription)
        {
            using (
                var glacierClient = new AmazonGlacierClient(new BasicAWSCredentials(GlacierAccessKey, new Secrets().GetGlacierSecretKey()),
                    GlacierRegion))
            {
                // zip to memory stream
                var ms = new MemoryStream();
                var zipper = new GZipStream(ms, CompressionLevel.Optimal);
                uncompressedContent.CopyTo(zipper);
                ms.Seek(0, SeekOrigin.Begin);


                //calculate sha256 hash
                var shaTree = TreeHashGenerator.CalculateTreeHash(ms);
                ms.Seek(0, SeekOrigin.Begin);

                var result =
                    glacierClient.UploadArchive(new UploadArchiveRequest()
                    {
                        AccountId = GlacierOwnerAccountID,
                        VaultName = GlacierVaultName,
                        ArchiveDescription = archiveDescription,
                        Body = ms,
                        Checksum = shaTree,
                    });

                return result;
            }
        }
Exemple #21
0
        private DescribeVaultResult GetMetadata()
        {
            var client = new AmazonGlacierClient(RegionEndpoint);

            var describeVaultRequest = new DescribeVaultRequest()
            {
                VaultName = Name
            };

            var describeVaultResponse = client.DescribeVault(describeVaultRequest);
            return describeVaultResponse.DescribeVaultResult;
            //            Console.WriteLine("\nVault description...");
            //            Console.WriteLine(
            //                "\nVaultName: " + describeVaultResult.VaultName +
            //                "\nVaultARN: " + describeVaultResult.VaultARN +
            //                "\nVaultCreationDate: " + describeVaultResult.CreationDate +
            //                "\nNumberOfArchives: " + describeVaultResult.NumberOfArchives +
            //                "\nSizeInBytes: " + describeVaultResult.SizeInBytes +
            //                "\nLastInventoryDate: " + describeVaultResult.LastInventoryDate
            //                );
        }
        private static void GetInventory(string jobId, string vaultName, string filename)
        {
            using (IAmazonGlacier client = new AmazonGlacierClient(RegionEndpoint.EUWest1))
            {
                GetJobOutputRequest getJobOutputRequest = new GetJobOutputRequest()
                {
                    JobId = jobId,
                    VaultName = vaultName,
                };

                GetJobOutputResponse getJobOutputResponse = client.GetJobOutput(getJobOutputRequest);
                using (Stream webStream = getJobOutputResponse.Body)
                {
                    using (Stream fileToSave = File.OpenWrite(filename))
                    {
                        CopyStream(webStream, fileToSave);
                    }
                }

            }
        }
Exemple #23
0
        public static void Main(string[] args)
        {
            // Required Config Values
            DirectoryToArchive = ConfigurationManager.AppSettings["DirectoryToArchive"];
            if(string.IsNullOrEmpty(DirectoryToArchive))
                throw new ConfigurationException("Please specify the 'DirectoryToArchive' setting in the application configuration file.");

            VaultName = ConfigurationManager.AppSettings["VaultName"];
            if (string.IsNullOrEmpty(VaultName))
                throw new ConfigurationException("Please specify the 'VaultName' setting in the application configuration file.");

            BackupFilePath = ConfigurationManager.AppSettings["BackupFilePath"];
            if (string.IsNullOrEmpty(BackupFilePath))
            {
                BackupFilePath = Path.Combine(Path.GetTempPath(),
                                              Path.GetTempFileName()).Replace(".tmp", ".zip");
            }

            ArchiveDescription = ConfigurationManager.AppSettings["ArchiveDescription"];
            ArchiveDescription = (string.IsNullOrEmpty(ArchiveDescription))
                                     ? string.Format("Archive of {0}", DirectoryToArchive)
                                     : ArchiveDescription;

            using (var backup = new ZipFile())
            {
                backup.AddDirectory(DirectoryToArchive);

                backup.SaveProgress += WriteZipProgress;

                backup.Save(BackupFilePath);
            }

            AmazonGlacier client;
            var partChecksumList = new List<string>();
            try
            {
                using (client = new AmazonGlacierClient(Amazon.RegionEndpoint.USEast1))
                {
                    System.Console.WriteLine("Uploading an archive.");
                    string uploadId = InitiateMultipartUpload(client);
                    partChecksumList = UploadParts(uploadId, client);
                    string archiveId = CompleteMPU(uploadId, client, partChecksumList);
                    System.Console.WriteLine();
                    System.Console.WriteLine("Archive ID: {0}", archiveId);
                }

                File.Delete(BackupFilePath);

                System.Console.WriteLine("Operations successful. To continue, press Enter");
                System.Console.ReadKey();
            }
            catch (AmazonGlacierException e)
            {
                System.Console.WriteLine(e.Message);
            }
            catch (AmazonServiceException e)
            {
                System.Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        }