Esempio n. 1
0
        public void CreateBackupTest()
        {
            DisasterRecoveryService service = new DisasterRecoveryService();
            string databaseName             = "SqlToolsService_TestBackup_" + new Random().Next(10000000, 99999999);

            var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);

            using (SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName))
                using (DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true))
                    using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo))
                    {
                        string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);

                        BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
                                                                        BackupType.Full,
                                                                        new List <string>()
                        {
                            backupPath
                        },
                                                                        new Dictionary <string, int>()
                        {
                            { backupPath, (int)DeviceType.File }
                        });
                        BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);

                        // Backup the database
                        service.PerformBackup(backupOperation);

                        VerifyAndCleanBackup(sqlConn, backupPath);
                    }
        }
Esempio n. 2
0
        /// <summary>
        /// Test creating backup with advanced options set.
        /// </summary>
        //[Fact]
        public void CreateBackupWithAdvancedOptionsTest()
        {
            DisasterRecoveryService service   = new DisasterRecoveryService();
            string             databaseName   = "testbackup_" + new Random().Next(10000000, 99999999);
            SqlTestDb          testDb         = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName);
            var                liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
            DatabaseTaskHelper helper         = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
            SqlConnection      sqlConn        = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo);
            string             backupPath     = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);

            string certificateName         = CreateCertificate(testDb);
            string cleanupCertificateQuery = string.Format(CleanupCertificateQueryFormat, certificateName);

            BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
                                                            BackupType.Full,
                                                            new List <string>()
            {
                backupPath
            },
                                                            new Dictionary <string, int>()
            {
                { backupPath, (int)DeviceType.File }
            });

            backupInfo.ContinueAfterError  = true;
            backupInfo.FormatMedia         = true;
            backupInfo.SkipTapeHeader      = true;
            backupInfo.Initialize          = true;
            backupInfo.MediaName           = "backup test media";
            backupInfo.MediaDescription    = "backup test";
            backupInfo.RetainDays          = 90;
            backupInfo.CompressionOption   = (int)BackupCompressionOptions.On;
            backupInfo.EncryptionAlgorithm = (int)BackupEncryptionAlgorithm.Aes128;
            backupInfo.EncryptorType       = (int)BackupEncryptorType.ServerCertificate;
            backupInfo.EncryptorName       = certificateName;

            BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);

            // Backup the database
            Console.WriteLine("Perform backup operation..");
            service.PerformBackup(backupOperation);

            // Remove the backup file
            Console.WriteLine("Verify the backup file exists and remove..");
            VerifyAndCleanBackup(backupPath);

            // Delete certificate and master key
            Console.WriteLine("Remove certificate and master key..");
            testDb.RunQuery(cleanupCertificateQuery);

            // Clean up the database
            Console.WriteLine("Clean up database..");
            testDb.Cleanup();
        }