/// <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; } }
/// <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; } }
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; }
/// <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; }
/// <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; }
public PWGlacierAPI(string vaultName, string archiveName) { _amazonGlacierClient = new AmazonGlacierClient(Amazon.RegionEndpoint.USEast1); _vault = vaultName; _archive = archiveName; }
/// <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 } ); }
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; } }
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); } } } }
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); } }