private void UploadSingleFile(IAmazonGlacier client, string vaultName, string accountId, string filePath, string description) { using (var transferManager = new ArchiveTransferManager(client)) { var runner = new ProgressRunner(this); var uploadOptions = new UploadOptions { AccountId = accountId }; var tracker = new UploadProgressTracker(runner, handler => uploadOptions.StreamTransferProgress += handler, filePath); var output = new CmdletOutput(); runner.SafeRun(() => { #if DESKTOP var result = transferManager.Upload(vaultName, description, filePath, uploadOptions); #else var result = transferManager.UploadAsync(vaultName, description, filePath, uploadOptions).GetAwaiter().GetResult(); #endif output.PipelineOutput = new FileUploadResult(filePath, result); }, tracker, output); // write as we go so that any subsequent error doesn't cause the user to lose // the ids of archives we have successfully uploaded so far ProcessOutput(output); } }
private void UploadSingleFile(IAmazonGlacier client, string vaultName, string accountId, string startingFolder, string filePath, int thisFileIndex, int allFilesCount) { using (var transferManager = new ArchiveTransferManager(client)) { var runner = new ProgressRunner(this); var uploadOptions = new UploadOptions { AccountId = accountId }; var tracker = new UploadFolderProgressTracker(runner, handler => uploadOptions.StreamTransferProgress += handler, startingFolder, filePath, thisFileIndex, allFilesCount); var output = new CmdletOutput(); runner.SafeRun(() => { #if DESKTOP var result = transferManager.Upload(vaultName, "", filePath, uploadOptions); #else var result = transferManager.UploadAsync(vaultName, "", filePath, uploadOptions).GetAwaiter().GetResult(); #endif output.PipelineOutput = new FileUploadResult(filePath, result); }, tracker, output); ProcessOutput(output); } }
public void Upload(FileInfo file, DateTime backupDate) { var task = _manager.UploadAsync(_name, $"Confluence Backup for {backupDate.ToShortDateString()}", file.FullName); task.Wait(); if (task.IsCompletedSuccessfully) { _archives.Add(new GlacierArchive(task.Result.ArchiveId, backupDate)); Save(); } }
static async void MainAsync(string[] args) { if (CheckRequiredFields()) { var glacierClient = new AmazonGlacierClient(); using (manager = new ArchiveTransferManager(glacierClient)) { try { // Creates a new Vault Console.WriteLine("Create Vault"); await manager.CreateVaultAsync(vaultName); // Uploads the specified file to Glacier. Console.WriteLine("Upload a Archive"); var uploadResult = await manager.UploadAsync(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; await manager.DownloadAsync(vaultName, archiveId, downloadFilePath, options); Console.WriteLine("Delete the Archive"); await manager.DeleteArchiveAsync(vaultName, archiveId); } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } } } }
public static async Task Main() { try { var manager = new ArchiveTransferManager(RegionEndpoint.USWest2); // Upload an archive. var response = await manager.UploadAsync(VaultName, "upload archive test", ArchiveToUpload); Console.WriteLine("Copy and save the ID for use in other examples."); Console.WriteLine($"Archive ID: {response.ArchiveId}"); Console.WriteLine("To continue, press Enter"); Console.ReadKey(); } catch (AmazonGlacierException ex) { Console.WriteLine(ex.Message); } }
public Task <UploadResult> SaveFileAsync(string filename, object metadata, string vaultName, bool compress) { var json = JsonConvert.SerializeObject(metadata); var fi = new FileInfo(filename); var shortFile = Path.GetFileName(filename); _log.InfoFormat("Uploading {0}, {1} bytes", filename, fi.Length); var vault = GetTrimmedVaultName(vaultName); var options = new UploadOptions() { AccountId = _accountId, StreamTransferProgress = (sender, args) => { Console.WriteLine($"{shortFile}:{args.PercentDone}%"); } }; return(_transferManager.UploadAsync(vault, json, filename, options)); }
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"))); } }
void BackupFile(string file) { var backupFile = new BackupFile(file, _opts.RelativeRoot); var result = new BackupResult { Region = _opts.Region, Vault = _opts.VaultName, Backup = backupFile }; for (var i = 1; i <= RETRY_COUNT; i++) { var attempt = i > 1 ? $" (attempt {i})" : string.Empty; try { Console.WriteLine($" - backing up {backupFile.GlacierDescription}{attempt}"); result.Result = _atm.UploadAsync(_opts.VaultName, backupFile.GlacierDescription, backupFile.FullPath).Result; lock (_lockObj) { _resultWriter.WriteResult(result); } return; } catch (Exception ex) { Console.WriteLine($" - error backing up {backupFile.GlacierDescription}{attempt}: {ex.Message}"); var ms = _rand.Next(START_WAIT_TIME_MS) * i; // wait for a random amount of time, and increase as the number of tries increases Thread.Sleep(ms); } } Console.WriteLine($" ** unable to backup {backupFile.GlacierDescription} **"); }
public static void Main(string[] args) { var directories = Directory.EnumerateDirectories(ArchiveToUpload); foreach (var directory in directories) { if (DateTime.Now.Subtract(Directory.GetLastWriteTime(directory)) > TimeSpan.FromDays(60)) { try { var manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USWest2); var archiveId = manager.UploadAsync(VaultName, "upload archive test", directory).Result.ArchiveId; var archiveName = Path.Combine(ArchiveToUpload, directory + "-ARCHIVE"); File.WriteAllText(archiveName, archiveId); Directory.Delete(Path.Combine(ArchiveToUpload, directory), true); } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } } } }
public async Task RunCode() { var client = new AmazonGlacierClient(); var manager = new ArchiveTransferManager(client); #region ArchiveTransferManager için kullanılan Kod Bloğu Console.Write("Yeni bir vault oluşturmak istiyor musunuz ?: [y/n] "); ConsoleKeyInfo decisionCreate = Console.ReadKey(); Console.WriteLine(); if (decisionCreate.Key == ConsoleKey.Y) { // High-Level API ile vault oluşturma işlemi Console.Write("Oluşturmak istediğiniz glacier vault ismini giriniz : "); var createVaultName = Console.ReadLine(); await manager.CreateVaultAsync(createVaultName); Console.WriteLine($"{createVaultName} isimli vault oluşturuldu"); } AddSpace(); Console.Write("Bir vault içine upload yapmak istiyor musnuz ?: [y/n] "); ConsoleKeyInfo decisionUpload = Console.ReadKey(); Console.WriteLine(); if (decisionUpload.Key == ConsoleKey.Y) { // High-Level API ile archive oluşturma işlemi Console.Write("Upload yapmak istediğiniz glacier vault ismini giriniz : "); var uploadVaultName = Console.ReadLine(); Console.Write("Oluşturmak istediğiniz archive açıklamasını giriniz : "); var archiveDesc = Console.ReadLine(); Console.Write("Upload etmek istediğiniz dosya yolunu giriniz : "); var filePath = Console.ReadLine(); var response = await manager.UploadAsync(uploadVaultName, archiveDesc, filePath); Console.WriteLine($"Yüklemiş olduğunuz dosya kaydedilmiştir. ArchiveId : {response.ArchiveId} "); } AddSpace(); Console.Write("Yeni bir download yapmak istiyor musunuz ?: [y/n] "); ConsoleKeyInfo decisionDownload = Console.ReadKey(); Console.WriteLine(); if (decisionDownload.Key == ConsoleKey.Y) { // High-Level API ile archive download etme işlemi Console.Write("Download yapmak istediğiniz glacier vault ismini giriniz : "); var downloadVaultName = Console.ReadLine(); Console.Write("İndirmek istediğiniz archive için ArchiveId giriniz : "); var archiveId = Console.ReadLine(); Console.Write("Download etmek istediğiniz local dosya yolunu giriniz : "); var downloadPath = Console.ReadLine(); await manager.DownloadAsync(downloadVaultName, archiveId, downloadPath); Console.WriteLine($"Dosyanız başarılı şekilde indirildi."); } AddSpace(); Console.Write("Bir vault Silmek istiyor musunuz ?: [y/n] "); ConsoleKeyInfo decisionDelete = Console.ReadKey(); Console.WriteLine(); if (decisionDelete.Key == ConsoleKey.Y) { // High-Level API ile vault silme işlemi Console.Write("Silmek istediğiniz glacier vault ismini giriniz : "); var deleteVaultName = Console.ReadLine(); await manager.DeleteVaultAsync(deleteVaultName); Console.WriteLine($"{deleteVaultName} isimli vault başarı ile silindi."); } AddSpace(); #endregion }