public void TestLongTermRetentionV2ResourceGroupBasedCrud()
        {
            // MANUAL TEST INSTRUCTIONS
            // PlayBack Mode:
            //     Remove skip flag
            // Record Mode:
            //     Create a server and database and fill in the appropriate information below
            //     Set the weekly retention on the database so that the first backup gets picked up
            //     Wait about 18 hours until it gets properly copied and you see the backup when run get backups
            //
            string locationName      = "brazilsouth";
            string resourceGroupName = "brrg";
            string serverName        = "ltrtest3";
            string databaseName      = "mydb";

            using (SqlManagementTestContext context = new SqlManagementTestContext(this))
            {
                SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>();
                Database            database  = sqlClient.Databases.Get(resourceGroupName, serverName, databaseName);

                // Get the backups under the location, server, and database. Assert there is at least one backup for each call.
                //
                IPage <LongTermRetentionBackup> backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupLocation(resourceGroupName, locationName);
                Assert.True(backups.Count() >= 1);
                backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupServer(resourceGroupName, locationName, serverName);
                Assert.True(backups.Count() >= 1);
                backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupDatabase(resourceGroupName, locationName, serverName, databaseName);
                Assert.True(backups.Count() >= 1);

                // Get a specific backup using the previous call
                //
                LongTermRetentionBackup backup = sqlClient.LongTermRetentionBackups.GetByResourceGroup(resourceGroupName, locationName, serverName, databaseName, backups.First().Name);
                Assert.NotNull(backup);

                // Restore the backup
                //
                Database restoredDatabase = sqlClient.Databases.CreateOrUpdate(
                    resourceGroupName, serverName, databaseName: SqlManagementTestUtilities.GenerateName(),
                    parameters: new Database
                {
                    Location   = locationName,
                    CreateMode = CreateMode.RestoreLongTermRetentionBackup,
                    LongTermRetentionBackupResourceId = backup.Id
                });

                // Delete the backup.
                //
                sqlClient.LongTermRetentionBackups.DeleteByResourceGroupWithHttpMessagesAsync(resourceGroupName, locationName, serverName, databaseName, backup.Name);
            }
        }
Пример #2
0
        public void TestCopyLongTermRetentionBackup()
        {
            // MANUAL TEST INSTRUCTIONS
            // PlayBack Mode:
            //     Make sure information below matches what is gets recorded in Session Records
            // Record Mode:
            //     Create a server and database and fill in the appropriate information below
            //     Set the weekly retention on the database so that the first backup gets picked up
            //     Wait about 18 hours until it gets properly copied and you see the backup when run get backups
            //     OR
            //     Use existing instance/database that already has LTR backups
            //
            string locationName       = "southeastasia";
            string subscriptionId     = "01c4ec88-e179-44f7-9eb0-e9719a5087ab";
            string resourceGroupName  = "testrg";
            string sourceServerName   = "ayang-stage-seas";
            string sourceDatabaseName = "ltr3";
            string targetServerName   = "ayang-stage-seas-1";
            string targetDatabaseName = "ltr1";


            using (SqlManagementTestContext context = new SqlManagementTestContext(this))
            {
                SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>();
                Database            database  = sqlClient.Databases.Get(resourceGroupName, sourceServerName, sourceDatabaseName);

                // Get backups under database
                //
                IPage <LongTermRetentionBackup> backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupDatabase(resourceGroupName, locationName, sourceServerName, sourceDatabaseName);
                Assert.True(backups.Count() >= 1);

                // Get a single backup using the previous call
                //
                LongTermRetentionBackup backup = sqlClient.LongTermRetentionBackups.GetByResourceGroup(resourceGroupName, locationName, sourceServerName, sourceDatabaseName, backups.First().Name);
                Assert.NotNull(backup);

                // Copy the backup to target database
                //
                string targetServerResourceId = String.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/servers/{2}", subscriptionId, resourceGroupName, targetServerName);
                CopyLongTermRetentionBackupParameters copyParameters = new CopyLongTermRetentionBackupParameters(
                    targetSubscriptionId: subscriptionId,
                    targetResourceGroup: resourceGroupName,
                    targetServerResourceId: targetServerResourceId,
                    targetDatabaseName: targetDatabaseName);
                LongTermRetentionBackupOperationResult restoredDatabase = sqlClient.LongTermRetentionBackups.Copy(locationName, sourceServerName, sourceDatabaseName, backup.Name, copyParameters);
            }
        }
Пример #3
0
        [Fact(Skip = "Manual test due to long setup time required (over 18 hours).")]        public void TestUpdateLongTermRetentionBackup()
        {
            // MANUAL TEST INSTRUCTIONS
            // PlayBack Mode:
            //     Remove skip flag
            // Record Mode:
            //     Create a server and database and fill in the appropriate information below
            //     Set the weekly retention on the database so that the first backup gets picked up
            //     Wait about 18 hours until it gets properly copied and you see the backup when run get backups
            //
            string locationName      = "Southeast Asia";
            string resourceGroupName = "testrg";
            string serverName        = "ayang-stage-seas";
            string databaseName      = "ltr3";

            using (SqlManagementTestContext context = new SqlManagementTestContext(this))
            {
                SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>();
                Database            database  = sqlClient.Databases.Get(resourceGroupName, serverName, databaseName);

                // Get backups under database
                //
                IPage <LongTermRetentionBackup> backups = sqlClient.LongTermRetentionBackups.ListByResourceGroupDatabase(resourceGroupName, locationName, serverName, databaseName);
                Assert.True(backups.Count() >= 1);

                // Get a single backup using the previous call
                //
                LongTermRetentionBackup backup = sqlClient.LongTermRetentionBackups.GetByResourceGroup(resourceGroupName, locationName, serverName, databaseName, backups.First().Name);
                Assert.NotNull(backup);

                // Update the Backup Storage Redundancy of the backup
                //
                UpdateLongTermRetentionBackupParameters updateParameters = new UpdateLongTermRetentionBackupParameters(requestedBackupStorageRedundancy: "Geo");
                LongTermRetentionBackupOperationResult  restoredDatabase = sqlClient.LongTermRetentionBackups.Update(locationName, serverName, databaseName, backup.Name, updateParameters);
            }
        }
Пример #4
0
        public void TestLongTermRetentionV2Crud()
        {
            // MANUAL INSTRUCTIONS
            // Create a server and database and fill in the appropriate information below
            // Set the weekly retention on the database so that the first backup gets picked up
            // Wait about 18 hours until it gets properly copied and you see the backup when run get backups
            //
            string locationName      = "";
            string resourceGroupName = "";
            string serverName        = "";
            string databaseName      = "";

            using (SqlManagementTestContext context = new SqlManagementTestContext(this))
            {
                SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>();
                Database            database  = sqlClient.Databases.Get(resourceGroupName, serverName, databaseName);

                // Set the retention policy to two weeks for the weekly retention policy
                //
                Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy parameters = new Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy(weeklyRetention: "P2W");
                var policyResult = sqlClient.BackupLongTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serverName, databaseName, parameters).Result;
                sqlClient.GetPutOrPatchOperationResultAsync(policyResult, new Dictionary <string, List <string> >(), CancellationToken.None).Wait();

                // Get the policy and verify the weekly policy is two weeks
                //
                Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy policy = sqlClient.BackupLongTermRetentionPolicies.Get(resourceGroupName, serverName, databaseName);
                Assert.Equal(parameters.WeeklyRetention, policy.WeeklyRetention);

                // Get the backups under the location, server, and database. Assert there is at least one backup for each call.
                //
                IPage <LongTermRetentionBackup> backups = sqlClient.LongTermRetentionBackups.ListByLocation(locationName);
                Assert.True(backups.Count() >= 1);
                backups = sqlClient.LongTermRetentionBackups.ListByServer(locationName, serverName);
                Assert.True(backups.Count() >= 1);
                backups = sqlClient.LongTermRetentionBackups.ListByDatabase(locationName, serverName, databaseName);
                Assert.True(backups.Count() >= 1);

                // Get a specific backup using the previous call
                //
                LongTermRetentionBackup backup = sqlClient.LongTermRetentionBackups.Get(locationName, serverName, databaseName, backups.First().Name);
                Assert.NotNull(backup);

                // Restore the backup
                //
                Database restoredDatabase = sqlClient.Databases.CreateOrUpdate(
                    resourceGroupName, serverName, databaseName: SqlManagementTestUtilities.GenerateName(),
                    parameters: new Database
                {
                    Location   = locationName,
                    CreateMode = CreateMode.RestoreLongTermRetentionBackup,
                    LongTermRetentionBackupResourceId = backup.Id
                });

                // Delete the backup.
                //
                var deleteResult = sqlClient.LongTermRetentionBackups.BeginDeleteWithHttpMessagesAsync(locationName, serverName, databaseName, backup.Name).Result;
                sqlClient.GetPutOrPatchOperationResultAsync(deleteResult, new Dictionary <string, List <string> >(), CancellationToken.None).Wait();

                // Verify the backup is gone.
                //
                try
                {
                    sqlClient.LongTermRetentionBackups.Get(locationName, serverName, databaseName, backup.Name);
                }
                catch (CloudException e)
                {
                    Assert.Contains(string.Format("'{0}' was not found.", backup.Name), e.Message);
                }

                // Set the retention policy back to one week for the weekly retention policy
                //
                parameters   = new Microsoft.Azure.Management.Sql.Models.BackupLongTermRetentionPolicy(weeklyRetention: "P1W");
                policyResult = sqlClient.BackupLongTermRetentionPolicies.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, serverName, databaseName, parameters).Result;
                sqlClient.GetPutOrPatchOperationResultAsync(policyResult, new Dictionary <string, List <string> >(), CancellationToken.None).Wait();

                // Get the policy and verify the weekly policy is two weeks
                //
                policy = sqlClient.BackupLongTermRetentionPolicies.Get(resourceGroupName, serverName, databaseName);
                Assert.Equal(parameters.WeeklyRetention, policy.WeeklyRetention);
            }
        }