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); } }
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); } }
public void Glacier(string file) { string vaultName = "GlacialTest"; string archiveToUpload = file; var credentials = new BasicAWSCredentials("XXX", "XXX"); var manager = new ArchiveTransferManager(credentials, Amazon.RegionEndpoint.USEast1); string archiveId = manager.Upload(vaultName, "archive description", archiveToUpload).ArchiveId; }//glacier
private void UploadToGlacier(string backupPath, PeriodicBackupSetup localBackupConfigs) { var awsRegion = RegionEndpoint.GetBySystemName(localBackupConfigs.AwsRegionEndpoint) ?? RegionEndpoint.USEast1; var manager = new ArchiveTransferManager(awsAccessKey, awsSecretKey, awsRegion); var archiveId = manager.Upload(localBackupConfigs.GlacierVaultName, GetArchiveDescription(), backupPath).ArchiveId; logger.Info(string.Format("Successfully uploaded backup {0} to Glacier, archive ID: {1}", Path.GetFileName(backupPath), archiveId)); }
public void UploadGlacier() { var vaultName = "test"; var archive = @"C:\Users\Rob\source\repos\Backup\archive\archive_2017-11-24_122504.zip"; var andrew = ""; var secret = ""; var manager = new ArchiveTransferManager(andrew, secret, RegionEndpoint.USEast1); // Upload an archive. string archiveId = manager.Upload(vaultName, "getting started archive test", archive).ArchiveId; Debug.WriteLine($"Archive ID: {archiveId}"); }
public AWSArchiveResult UploadFile(String filePath, String nativeChecksum, String archiveDescription) { using (manager = new ArchiveTransferManager(RegionEndpoint.USEast1)) { if (CheckRequiredFields()) { try { Form1.log.Info("Upload a Archive"); var uploadResult = manager.Upload(vaultName, archiveDescription, filePath); archiveId = uploadResult.ArchiveId; Form1.log.Info("Upload successful. Archive Id : " + uploadResult.ArchiveId + "Checksum : " + uploadResult.Checksum); var config = new AmazonDynamoDBConfig(); config.ServiceURL = "http://dynamodb.us-east-1.amazonaws.com"; client = new AmazonDynamoDBClient(config); Table dynamoTable = Table.LoadTable(client, "FL6119"); var entry = new Document(); entry["FileID"] = uploadResult.ArchiveId; entry["date"] = System.DateTime.Now; entry["checksum"] = uploadResult.Checksum; entry["archiveID"] = filePath; entry["NAtiveChecksum"] = nativeChecksum; dynamoTable.PutItem(entry); AWSArchiveResult ar = new AWSArchiveResult(); ar.ArchiveID = uploadResult.ArchiveId; ar.Checksum = uploadResult.Checksum; return(ar); } catch (AmazonGlacierException e) { Form1.log.Error(e.ToString()); } catch (AmazonServiceException e) { Form1.log.Error(e.ToString()); } } return(new AWSArchiveResult()); } }
static void Main(string[] args) { try { var manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USEast1); // Upload an archive. string archiveId = manager.Upload(vaultName, "upload archive test", archiveToUpload).ArchiveId; Console.WriteLine("Archive ID: (Copy and save this ID for use in other examples.) : {0}", archiveId); Console.WriteLine("To continue, press Enter"); Console.ReadKey(); } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("To continue, press Enter"); Console.ReadKey(); }
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 static void Main(string[] args) { try { var manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USWest2); // Upload an archive. string archiveId = manager.Upload(vaultName, "getting started archive test", archiveToUpload).ArchiveId; Console.WriteLine("Copy and save the following Archive ID for the next step."); Console.WriteLine("Archive ID: {0}", archiveId); Console.WriteLine("To continue, press Enter"); Console.ReadKey(); } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("To continue, press Enter"); Console.ReadKey(); }
/* * this appends a filename and file key pair to location specified in 'CopyArchiveKeys' */ public void runUpload() { CopyArchiveKeys cak = new CopyArchiveKeys(@"C:\Code\VisualStudio\Projects\AwsBackup2\KeyCopy\"); try{ var manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USEast1); string archiveID = manager.Upload(vaultName, "getting started test", archiveToUpload).ArchiveId; Console.WriteLine("Archive ID (copy and save for next step): {0}", archiveID); cak.copyThis(archiveToUpload + " " + "-" + " " + archiveID); //cak.copyThis("test"); //Console.ReadKey(); } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("To continue, press Enter"); Console.ReadKey(); }
public static void BackUpFuneralsToGlacier() { string vaultName = "examplevault"; string archiveToUpload = "C:\\Users\\Shane\\Videos\\bigbuck.mp4"; try { var manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USEast1); // Upload an archive. string archiveId = manager.Upload(vaultName, "getting started archive test", archiveToUpload).ArchiveId; Console.WriteLine("Copy and save the following Archive ID for the next step."); Console.WriteLine("Archive ID: {0}", archiveId); Console.WriteLine("To continue, press Enter"); Console.ReadKey(); } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("To continue, press Enter"); Console.ReadKey(); }
private void DoUpload(string backupPath, PeriodicBackupSetup backupConfigs) { var AWSRegion = RegionEndpoint.GetBySystemName(backupConfigs.AwsRegionEndpoint) ?? RegionEndpoint.USEast1; var desc = string.Format("Raven.Database.Backup {0} {1}", Database.Name, DateTimeOffset.UtcNow.ToString("u")); if (!string.IsNullOrWhiteSpace(backupConfigs.GlacierVaultName)) { var manager = new ArchiveTransferManager(awsAccessKey, awsSecretKey, AWSRegion); var archiveId = manager.Upload(backupConfigs.GlacierVaultName, desc, backupPath).ArchiveId; logger.Info(string.Format("Successfully uploaded backup {0} to Glacier, archive ID: {1}", Path.GetFileName(backupPath), archiveId)); return; } if (!string.IsNullOrWhiteSpace(backupConfigs.S3BucketName)) { var client = new Amazon.S3.AmazonS3Client(awsAccessKey, awsSecretKey, AWSRegion); using (var fileStream = File.OpenRead(backupPath)) { var key = Path.GetFileName(backupPath); var request = new PutObjectRequest(); request.WithMetaData("Description", desc); request.WithInputStream(fileStream); request.WithBucketName(backupConfigs.S3BucketName); request.WithKey(key); using (S3Response _ = client.PutObject(request)) { logger.Info(string.Format("Successfully uploaded backup {0} to S3 bucket {1}, with key {2}", Path.GetFileName(backupPath), backupConfigs.S3BucketName, key)); return; } } } }
private static void UploadGlacierArchive(Settings settings, string zipArchivePath) { var manager = new ArchiveTransferManager( settings.AWSAccessKeyID, settings.AWSSecretAccessKey, RegionEndpoint.GetBySystemName(settings.AWSS3Region.SystemName)); var options = new UploadOptions(); options.StreamTransferProgress += FileManager.UploadGlacierProgress; var fi = new FileInfo(zipArchivePath); // Upload an archive. string archiveId = manager.Upload( settings.AWSGlacierVault, fi.Name, zipArchivePath, options).ArchiveId; // TODO persist archive ID Debug.WriteLine($"Archive ID: {archiveId}"); }
static void UploadArchive(string filePath, Amazon.RegionEndpoint region) { bool error = false; int attempt = 1; do { error = false; int indexLastBackslash = filePath.LastIndexOf(@"\"); if (indexLastBackslash < 0) { Console.WriteLine("Can't find the file name in \"{0}\"", filePath); Console.WriteLine("Press a key to EXIT"); Console.ReadKey(); return; } string description = filePath.Substring(indexLastBackslash + 1); DateTime startDateTime = DateTime.Now; try { double archiveSizeInGigabytes = new System.IO.FileInfo(filePath).Length / 1024.0 / 1024.0 / 1024.0; WriteLogConsole(string.Format( "Upload \"{0}\" with size {1:N2} GB to {2}", filePath, archiveSizeInGigabytes, region.ToString())); WriteLogConsole("Start time: " + startDateTime.ToString("yyyy-MM-dd hh:mm:ss")); var manager = new ArchiveTransferManager(region); string archiveId = manager.Upload(s_vaultName, description, filePath).ArchiveId; WriteLogConsole("Save the following Archive ID for " + filePath + " to " + region.ToString() + ":"); WriteLogConsole(archiveId); } catch (AmazonGlacierException e) { WriteLogConsole("AmazonGlacierException for " + filePath + " to " + region.ToString() + ":" + e.Message); error = true; } catch (AmazonServiceException e) { WriteLogConsole("AmazonServiceException for " + filePath + " to " + region.ToString() + ":" + e.Message); error = true; } catch (Exception e) { WriteLogConsole("Exception for " + filePath + " to " + region.ToString() + ":" + e.Message); error = true; } DateTime endDateTime = DateTime.Now; WriteLogConsole("End time: " + endDateTime.ToString("yyyy-MM-dd hh:mm:ss")); TimeSpan timeTaken = endDateTime - startDateTime; WriteLogConsole("Time taken: " + timeTaken.ToString()); Email((error ? "Error: " : "") + string.Format("Amazon {0}: ", s_programName) + description + " (" + region.ToString() + ")", s_log.ToString()); if (error) { WriteLogConsole(string.Format("Try again. Attempt number {0}. {1}, {2}", ++attempt, filePath, region.ToString())); WriteLogConsole(""); } }while (error); s_processesAlive = Interlocked.Add(ref s_processesAlive, -1); WriteLogConsole(string.Format("Completed {0} to {1}. {2} processes alive (2)", filePath, region.ToString(), s_processesAlive)); }
static void Main(string[] args) { Amazon.RegionEndpoint region = null; if (!GetDataCenter(out region)) { return; } WriteLogConsole("To data center: " + region.ToString()); string filePath; if (!GetFilePath(out filePath)) { return; } int indexLastBackslash = filePath.LastIndexOf(@"\"); if (indexLastBackslash < 0) { Console.WriteLine("Can't find the file name in \"{0}\"", filePath); Console.WriteLine("Press a key to EXIT"); Console.ReadKey(); return; } string description = filePath.Substring(indexLastBackslash + 1); int attempt = 1; bool error = false; do { DateTime startDateTime = DateTime.Now; error = false; try { double archiveSizeInGigabytes = new System.IO.FileInfo(filePath).Length / 1024.0 / 1024.0 / 1024.0; WriteLogConsole(string.Format( "Upload \"{0}\" with size {1:N2} GB", filePath, archiveSizeInGigabytes)); WriteLogConsole("Start time: " + startDateTime.ToString("yyyy-MM-dd hh:mm:ss")); var manager = new ArchiveTransferManager(region); string archiveId = manager.Upload(s_vaultName, description, filePath).ArchiveId; WriteLogConsole("Save the following Archive ID: " + archiveId); } catch (AmazonGlacierException e) { WriteLogConsole("AmazonGlacierException: " + e.Message); error = true; } catch (AmazonServiceException e) { WriteLogConsole("AmazonServiceException" + e.Message); error = true; } catch (Exception e) { WriteLogConsole("Exception" + e.Message); error = true; } DateTime endDateTime = DateTime.Now; WriteLogConsole("End time: " + endDateTime.ToString("yyyy-MM-dd hh:mm:ss")); TimeSpan timeTaken = endDateTime - startDateTime; WriteLogConsole("Time taken: " + timeTaken.ToString()); Email((error ? "Error: " : "") + "Amazon Upload " + description + " (" + region.ToString() + ")", s_log.ToString()); if (error) { WriteLogConsole(string.Format("Try again. Attempt number {0}", ++attempt)); WriteLogConsole(""); } }while (error); Console.WriteLine("Press a key to EXIT"); Console.ReadKey(); }