Пример #1
0
        public void can_get_correct_error_glacier(string region1, string region2)
        {
            var vaultName1 = $"testing-{Guid.NewGuid()}";
            var vaultName2 = $"testing-{Guid.NewGuid()}";

            using (var clientRegion1 = new RavenAwsGlacierClient(GetGlacierSettings(region1, vaultName1)))
                using (var clientRegion2 = new RavenAwsGlacierClient(GetGlacierSettings(region2, vaultName2)))
                {
                    var e = Assert.Throws <VaultNotFoundException>(() =>
                    {
                        clientRegion2.UploadArchive(
                            new MemoryStream(Encoding.UTF8.GetBytes("321")),
                            "sample description");
                    });
                    Assert.Equal(e.Message, $"Vault name '{vaultName2}' doesn't exist in {region2}!");

                    e = Assert.Throws <VaultNotFoundException>(() =>
                    {
                        clientRegion1.UploadArchive(
                            new MemoryStream(Encoding.UTF8.GetBytes("321")),
                            "sample description");
                    });
                    Assert.Equal(e.Message, $"Vault name '{vaultName1}' doesn't exist in {region1}!");
                }
        }
Пример #2
0
        public async Task can_get_correct_error_glacier(string region1, string region2)
        {
            var vaultName1 = $"testing-{Guid.NewGuid()}";
            var vaultName2 = $"testing-{Guid.NewGuid()}";

            using (var clientRegion1 = new RavenAwsGlacierClient(AwsAccessKey, AwsSecretKey, region1, vaultName1))
                using (var clientRegion2 = new RavenAwsGlacierClient(AwsAccessKey, AwsSecretKey, region2, vaultName2))
                {
                    var e = await Assert.ThrowsAsync <VaultNotFoundException>(async() =>
                    {
                        await clientRegion2.UploadArchive(
                            new MemoryStream(Encoding.UTF8.GetBytes("321")),
                            "sample description");
                    });

                    Assert.Equal(e.Message, $"Vault name '{vaultName2}' doesn't exist in {region2}!");

                    e = await Assert.ThrowsAsync <VaultNotFoundException>(async() =>
                    {
                        await clientRegion1.UploadArchive(
                            new MemoryStream(Encoding.UTF8.GetBytes("321")),
                            "sample description");
                    });

                    Assert.Equal(e.Message, $"Vault name '{vaultName1}' doesn't exist in {region1}!");
                }
        }
Пример #3
0
 private void UploadToGlacier(string backupPath, PeriodicExportSetup localExportConfigs, bool isFullBackup)
 {
     using (var client = new RavenAwsGlacierClient(awsAccessKey, awsSecretKey, localExportConfigs.AwsRegionEndpoint ?? RavenAwsClient.DefaultRegion))
         using (var fileStream = File.OpenRead(backupPath))
         {
             var archiveId = client.UploadArchive(localExportConfigs.GlacierVaultName, fileStream, GetArchiveDescription(isFullBackup), 60 * 60);
             logger.Info(string.Format("Successfully uploaded backup {0} to Glacier, archive ID: {1}", Path.GetFileName(backupPath), archiveId));
         }
 }
Пример #4
0
        public void UploadArchive()
        {
            var glacierVaultName = "ravendb";

            using (var client = new RavenAwsGlacierClient("<aws_access_key>", "<aws_secret_key>", "<aws_region_for_bucket>"))
            {
                var archiveId = client.UploadArchive(glacierVaultName, new MemoryStream(Encoding.UTF8.GetBytes("321")), "sample description", 60 * 60);

                Assert.NotNull(archiveId);
            }
        }
Пример #5
0
 private void UploadToGlacier(string backupPath, PeriodicExportSetup localExportConfigs, bool isFullBackup)
 {
     if (awsAccessKey == Constants.DataCouldNotBeDecrypted ||
         awsSecretKey == Constants.DataCouldNotBeDecrypted)
     {
         throw new InvalidOperationException("Could not decrypt the AWS access settings, if you are running on IIS, make sure that load user profile is set to true.");
     }
     using (var client = new RavenAwsGlacierClient(awsAccessKey, awsSecretKey, localExportConfigs.AwsRegionEndpoint ?? RavenAwsClient.DefaultRegion))
         using (var fileStream = File.OpenRead(backupPath))
         {
             var archiveId = client.UploadArchive(localExportConfigs.GlacierVaultName, fileStream, GetArchiveDescription(isFullBackup), 60 * 60);
             logger.Info(string.Format("Successfully uploaded backup {0} to Glacier, archive ID: {1}", Path.GetFileName(backupPath), archiveId));
         }
 }
Пример #6
0
        private void UploadToGlacier(GlacierSettings settings, Stream stream, Progress progress)
        {
            using (var client = new RavenAwsGlacierClient(settings, _settings.Configuration, progress, TaskCancelToken.Token))
            {
                var key       = CombinePathAndKey(settings.RemoteFolderName ?? _settings.DatabaseName);
                var archiveId = client.UploadArchive(stream, key);
                if (_logger.IsInfoEnabled)
                {
                    _logger.Info($"{ReportSuccess(GlacierName)}, archive ID: {archiveId}");
                }

                var runner = new GlacierRetentionPolicyRunner(_retentionPolicyParameters, client);
                runner.Execute();
            }
        }
Пример #7
0
        public async Task upload_archive(string region)
        {
            var vaultName = $"testing-{Guid.NewGuid()}";

            using (var client = new RavenAwsGlacierClient(AwsAccessKey, AwsSecretKey, region, vaultName))
            {
                await client.PutVault();

                var archiveId = await client.UploadArchive(
                    new MemoryStream(Encoding.UTF8.GetBytes("321")),
                    "sample description");

                Assert.NotNull(archiveId);
            }
        }
Пример #8
0
        public void upload_archive(string region)
        {
            var vaultName = $"testing-{Guid.NewGuid()}";

            using (var client = new RavenAwsGlacierClient(GetGlacierSettings(region, vaultName)))
            {
                client.PutVault();

                var archiveId = client.UploadArchive(
                    new MemoryStream(Encoding.UTF8.GetBytes("321")),
                    "sample description");

                Assert.NotNull(archiveId);
            }
        }
Пример #9
0
        public void upload_archive_with_remote_folder_name(string region)
        {
            var vaultName = $"testing-{Guid.NewGuid()}";

            var glacierSettings = GetGlacierSettings(region, vaultName);

            glacierSettings.RemoteFolderName = Guid.NewGuid().ToString();
            using (var client = new RavenAwsGlacierClient(glacierSettings))
            {
                client.PutVault();

                var archiveId = client.UploadArchive(
                    new MemoryStream(Encoding.UTF8.GetBytes("321")),
                    "sample description");

                Assert.NotNull(archiveId);
            }
        }
Пример #10
0
        private async Task UploadToGlacier(
            GlacierSettings settings,
            Stream stream,
            string folderName,
            string fileName,
            Progress progress)
        {
            using (var client = new RavenAwsGlacierClient(settings.AwsAccessKey, settings.AwsSecretKey,
                                                          settings.AwsRegionName, settings.VaultName, progress, TaskCancelToken.Token))
            {
                var key       = CombinePathAndKey(_database.Name, folderName, fileName);
                var archiveId = await client.UploadArchive(stream, key);

                if (_logger.IsInfoEnabled)
                {
                    _logger.Info($"Successfully uploaded backup file '{fileName}' to Glacier, archive ID: {archiveId}");
                }
            }
        }
Пример #11
0
        private async Task UploadToGlacier(string exportPath, string fileName, bool isFullExport)
        {
            if (_awsAccessKey == Constants.DataCouldNotBeDecrypted ||
                _awsSecretKey == Constants.DataCouldNotBeDecrypted)
            {
                throw new InvalidOperationException("Could not decrypt the AWS access settings, if you are running on IIS, make sure that load user profile is set to true.");
            }

            using (var client = new RavenAwsGlacierClient(_awsAccessKey, _awsSecretKey, _configuration.AwsRegionName ?? RavenAwsClient.DefaultRegion))
                using (var fileStream = File.OpenRead(exportPath))
                {
                    var archiveId = await client.UploadArchive(_configuration.GlacierVaultName, fileStream, fileName, 60 *60);

                    if (_logger.IsInfoEnabled)
                    {
                        _logger.Info($"Successfully uploaded export {fileName} to Glacier, archive ID: {archiveId}");
                    }
                }
        }
Пример #12
0
        // ReSharper disable once InconsistentNaming
        private static async Task UploadArchive(string region,
                                                int sizeInMB, int minOnePartSizeInMB, UploadType uploadType)
        {
            var vaultName = $"testing-{Guid.NewGuid()}";

            var uploadProgress = new UploadProgress();
            var maxUploadArchiveSizeInBytes      = ExpressionHelper.CreateFieldSetter <RavenAwsGlacierClient, int>("MaxUploadArchiveSizeInBytes");
            var minOnePartUploadSizeLimitInBytes = ExpressionHelper.CreateFieldSetter <RavenAwsGlacierClient, int>("MinOnePartUploadSizeLimitInBytes");

            using (var client = new RavenAwsGlacierClient(AwsAccessKey, AwsSecretKey, region, vaultName, uploadProgress))
            {
                maxUploadArchiveSizeInBytes(client, 10 * 1024 * 1024); // 9MB
                minOnePartUploadSizeLimitInBytes(client, minOnePartSizeInMB * 1024 * 1024);

                await client.PutVault();

                var sb = new StringBuilder();
                for (var i = 0; i < sizeInMB * 1024 * 1024; i++)
                {
                    sb.Append("a");
                }

                long streamLength;
                using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())))
                {
                    streamLength = memoryStream.Length;
                    var archiveId = await client.UploadArchive(memoryStream,
                                                               $"testing-upload-archive-{Guid.NewGuid()}");

                    Assert.NotNull(archiveId);
                }

                Assert.Equal(UploadState.Done, uploadProgress.UploadState);
                Assert.Equal(uploadType, uploadProgress.UploadType);
                Assert.Equal(streamLength, uploadProgress.TotalInBytes);
                Assert.Equal(streamLength, uploadProgress.UploadedInBytes);
            }
        }
Пример #13
0
        // ReSharper disable once InconsistentNaming
        private static async Task UploadArchiveAsync(string region,
                                                     int sizeInMB, int minOnePartSizeInMB, UploadType uploadType)
        {
            var vaultName = $"testing-{Guid.NewGuid()}";

            var progress = new Progress();

            using (var client = new RavenAwsGlacierClient(GetGlacierSettings(region, vaultName), DefaultConfiguration, progress))
            {
                client.MaxUploadArchiveSize      = new Size(9, SizeUnit.Megabytes);
                client.MinOnePartUploadSizeLimit = new Size(minOnePartSizeInMB, SizeUnit.Megabytes);

                await client.PutVaultAsync();

                var sb = new StringBuilder();
                for (var i = 0; i < sizeInMB * 1024 * 1024; i++)
                {
                    sb.Append("a");
                }

                long streamLength;
                using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())))
                {
                    streamLength = memoryStream.Length;
                    var archiveId = client.UploadArchive(memoryStream,
                                                         $"testing-upload-archive-{Guid.NewGuid()}");

                    Assert.NotNull(archiveId);
                }

                Assert.Equal(UploadState.Done, progress.UploadProgress.UploadState);
                Assert.Equal(uploadType, progress.UploadProgress.UploadType);
                Assert.Equal(streamLength, progress.UploadProgress.TotalInBytes);
                Assert.Equal(streamLength, progress.UploadProgress.UploadedInBytes);
            }
        }
Пример #14
0
        public async Task TestPeriodicBackupCredentials()
        {
            var type = GetQueryStringValueAndAssertIfSingleAndNotEmpty("type");

            if (Enum.TryParse(type, out PeriodicBackupConnectionType connectionType) == false)
            {
                throw new ArgumentException($"Unknown backup connection: {type}");
            }

            using (ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context))
            {
                DynamicJsonValue result;
                try
                {
                    var connectionInfo = await context.ReadForMemoryAsync(RequestBodyStream(), "test-connection");

                    switch (connectionType)
                    {
                    case PeriodicBackupConnectionType.S3:
                        var s3Settings = JsonDeserializationClient.S3Settings(connectionInfo);
                        using (var awsClient = new RavenAwsS3Client(s3Settings, ServerStore.Configuration.Backup, cancellationToken: ServerStore.ServerShutdown))
                        {
                            awsClient.TestConnection();
                        }
                        break;

                    case PeriodicBackupConnectionType.Glacier:
                        var glacierSettings = JsonDeserializationClient.GlacierSettings(connectionInfo);
                        using (var glacierClient = new RavenAwsGlacierClient(glacierSettings, ServerStore.Configuration.Backup, cancellationToken: ServerStore.ServerShutdown))
                        {
                            glacierClient.TestConnection();
                        }
                        break;

                    case PeriodicBackupConnectionType.Azure:
                        var azureSettings = JsonDeserializationClient.AzureSettings(connectionInfo);
                        using (var azureClient = RavenAzureClient.Create(azureSettings, ServerStore.Configuration.Backup, cancellationToken: ServerStore.ServerShutdown))
                        {
                            azureClient.TestConnection();
                        }
                        break;

                    case PeriodicBackupConnectionType.GoogleCloud:
                        var googleCloudSettings = JsonDeserializationClient.GoogleCloudSettings(connectionInfo);
                        using (var googleCloudClient = new RavenGoogleCloudClient(googleCloudSettings, ServerStore.Configuration.Backup, cancellationToken: ServerStore.ServerShutdown))
                        {
                            await googleCloudClient.TestConnection();
                        }
                        break;

                    case PeriodicBackupConnectionType.FTP:
                        var ftpSettings = JsonDeserializationClient.FtpSettings(connectionInfo);
                        using (var ftpClient = new RavenFtpClient(ftpSettings))
                        {
                            ftpClient.TestConnection();
                        }
                        break;

                    case PeriodicBackupConnectionType.Local:
                    case PeriodicBackupConnectionType.None:
                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    result = new DynamicJsonValue
                    {
                        [nameof(NodeConnectionTestResult.Success)] = true,
                    };
                }
                catch (Exception e)
                {
                    result = new DynamicJsonValue
                    {
                        [nameof(NodeConnectionTestResult.Success)] = false,
                        [nameof(NodeConnectionTestResult.Error)]   = e.ToString()
                    };
                }

                await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    context.Write(writer, result);
                }
            }
        }
Пример #15
0
 public GlacierRetentionPolicyRunner(RetentionPolicyBaseParameters parameters, RavenAwsGlacierClient client)
     : base(parameters)
 {
     _client = client;
 }