public static void DeleteArchive(string vaultName, string archiveId, Amazon.RegionEndpoint awsRegion) { Logger.LogMessage($"Deleting archive '{archiveId}' from {vaultName}..."); using (var manager = new ArchiveTransferManager(awsRegion)) { manager.DeleteArchive(vaultName, archiveId); } }
public void Execute() { VaultInventory vaultInventory = VaultInventoryParser.Parse(_vaultInventoryFile); NasFiles nasFiles = NasBackup.GetFiles(_nasPath); IEnumerable <GlacierFile> glacierFiles = vaultInventory.ArchiveList; IEnumerable <File> localFiles = nasFiles.Files; IEnumerable <GlacierFile> glacierExtraAgeFiles = FileMatcher.GetGlacierExtraFiles(glacierFiles, localFiles, _glacierOlderThan); var deleteFileResults = new List <GlacierDeleteFileResult>(); using (var mgr = new ArchiveTransferManager(RegionEndpoint.USWest2)) { foreach (GlacierFile g in glacierExtraAgeFiles) { string deleteFailure = null; bool isOldEnough = g.AgeDays > 90; if (isOldEnough) { try { mgr.DeleteArchive(vaultName: "backup-home", archiveId: g.ArchiveId); } catch (Exception ex) { deleteFailure = ex.Message; } } else { deleteFailure = string.Format("File is not old enough to be deleted. Age: [{0}]", g.AgeDays); } var deleteFileResult = new GlacierDeleteFileResult(g.NormalizedFilePath, deleteFailure, g.SizeBytes); deleteFileResults.Add(deleteFileResult); } } var result = new DeleteGlacierFilesResult(deleteFileResults); ConsoleView.Show(result); }
static void Main(string[] args) { if (CheckRequiredFields()) { using (manager = new ArchiveTransferManager(RegionEndpoint.USWest2)) { try { // Creates a new Vault Console.WriteLine("Create Vault"); manager.CreateVault(vaultName); // Uploads the specified file to Glacier. Console.WriteLine("Upload a Archive"); var uploadResult = manager.Upload(vaultName, "Archive Description", filePath); archiveId = uploadResult.ArchiveId; Console.WriteLine("Upload successful. Archive Id : {0} Checksum : {1}", uploadResult.ArchiveId, uploadResult.Checksum); // Downloads the file from Glacier // This operation can take a long time to complete. // The ArchiveTransferManager.Download() method creates an Amazon SNS topic, // and an Amazon SQS queue that is subscribed to that topic. // It then initiates the archive retrieval job and polls the queue for the // archive to be available. This polling takes about 4 hours. // Once the archive is available, download will begin. Console.WriteLine("Download the Archive"); var options = new DownloadOptions(); options.StreamTransferProgress += OnProgress; manager.Download(vaultName, archiveId, downloadFilePath, options); Console.WriteLine("Delete the Archive"); manager.DeleteArchive(vaultName, archiveId); } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } } } }
public async Task <VerfiedUploadLocation> Upload(VerifiedFileLocation fileLocation, IProgress <string> progress, CancellationToken cancellationToken) { string vaultName = await GetVaultNameAsync(cancellationToken).ConfigureAwait(false); string archiveDescription = fileLocation.BackupFileName; using (ArchiveTransferManager transferManager = new ArchiveTransferManager(Amazon.RegionEndpoint.USEast2)) { UploadResult transfer = await transferManager.UploadAsync(vaultName, archiveDescription, fileLocation.FileInfo.FullName, new UploadOptions { StreamTransferProgress = (sender, args) => progress.Report($"{archiveDescription}:{args.PercentDone}%") }).ConfigureAwait(false); if (transfer.Checksum != fileLocation.FileInfo.Checksum()) { transferManager.DeleteArchive(vaultName, transfer.ArchiveId); _logger.Error(new InvalidChecksumException(), "Failed to upload backup '{0}'. Checksum mismatch.", fileLocation.BackupFileName); } return(new VerfiedUploadLocation(transfer.ArchiveId, archiveDescription, transfer.Checksum, DateTime.Now.ToUniversalTime().ToString("O"))); } }