Upload() публичный Метод

Uploads the specified file to Amazon Glacier for archival storage in the specified vault in the specified user's account. For small archives, this method uploads the archive directly to Glacier. For larger archives, this method uses Glacier's multipart upload API to split the upload into multiple parts for better error recovery if any errors are encountered while streaming the data to Amazon Glacier.
public Upload ( string vaultName, string archiveDescription, string filepath ) : UploadResult
vaultName string The name of the vault to upload the file to.
archiveDescription string A description for the archive.
filepath string The file path to the file to upload.
Результат UploadResult
Пример #1
0
        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);
                    }
                }
            }
        }
Пример #2
0
 /*
  * 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();
 }
Пример #3
0
		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));
		}
		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;
					}
				}
			}
		}
Пример #5
0
        public static void Upload(string[] args)
        {
            string id = args[0];
            string access = args[1];
            string secret = args[2];
            RegionEndpoint region = ParseRegion(args[3]);
            string vault = args[4];
            string path = args[5];
            string desc = args[6];

            var info = new FileInfo(path);
            long size = 0;

            if (info.Exists)
                size = info.Length;
            else
            {
                Console.Error.Write("The given path does not exist.\n");
                Usage();
            }

            Console.Write("About to perform the following upload:\n\n" +
                String.Format("{0,-16}{1}\n", "Path:", path) +
                String.Format("{0,-16}{1:f6} GiB\n", "Size:",
                    (decimal)size / (1024m * 1024m * 1024m)) +
                String.Format("{0,-16}\"{1}\"\n", "Description:", desc) +
                String.Format("\n{0,-16}{1}\n", "Region:", region.DisplayName) +
                String.Format("{0,-16}{1}\n", "Vault:", vault) +
                String.Format("\n{0,-16}${1:f2}/month\n", "Storage cost:",
                    ((decimal)size / (1024m * 1024m * 1024m) * 0.01m)) +
                String.Format("{0,-16}${1:f2} (< 90 days)\n", "Deletion fee:",
                    ((decimal)size / (1024m * 1024m * 1024m) * 0.03m)) +
                String.Format("{0,-16}${1:f2}\n", "Retrieval cost:",
                    ((decimal)size / (1024m * 1024m * 1024m) * 0.12m)) +
                String.Format("\n{0,-16}{1}\n", "Account ID:", id) +
                String.Format("{0,-16}{1}\n", "Access key:", access) +
                String.Format("{0,-16}{1}\n", "Secret key:", secret) +
                "\nARE YOU SURE YOU WANT TO PROCEED? [y/N] ");

            bool proceed = false;
            do
            {
                ConsoleKeyInfo key = Console.ReadKey(true);

                switch (Char.ToLower(key.KeyChar))
                {
                case 'y':
                    Console.WriteLine(key.KeyChar);
                    proceed = true;
                    break;
                case 'n':
                    Console.Write(key.KeyChar);
                    goto case '\n';
                case '\n':
                    Console.WriteLine();
                    Console.Write("Upload aborted.\n");
                    Environment.Exit(0);
                    break;
                }
            }
            while (!proceed);

            Console.Write("\nUpload started at {0:G}.\n", DateTime.Now);

            Console.CancelKeyPress += CtrlC;

            var progress = new Progress();

            var options = new UploadOptions();
            options.AccountId = id;
            options.StreamTransferProgress += progress.Update;

            var creds = new BasicAWSCredentials(access, secret);
            var manager = new ArchiveTransferManager(creds, region);

            progress.Start();

            /* not asynchronous */
            UploadResult result = manager.Upload(vault, desc, path, options);

            Console.Write("\n\nUpload complete.\n" +
                String.Format("Archive ID: {0}\n", result.ArchiveId));
        }
Пример #6
0
 public void upload(ArchiveTransferManager manager, string vaultName, string basePath)
 {
     ArchiveId = manager.Upload(vaultName, ArchiveDescription, basePath + "\\" + RelativePath).ArchiveId;
     CreationDate = DateTime.Now;
     IsDirty = true;
 }
Пример #7
0
 public string Upload(string archiveFilename, string archiveDescription = "")
 {
     var manager = new ArchiveTransferManager(RegionEndpoint);
     return manager.Upload(Name, archiveDescription, archiveFilename).ArchiveId;
 }