Skip to content

New parameters in New-AzureRmVMSqlServerAutoBackupConfig cmdlet to support Auto Backup for SQL Server 2016 VMs. #3313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Dec 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ResourceManager/Compute/AzureRM.Compute.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ CmdletsToExport = 'Remove-AzureRmAvailabilitySet', 'Get-AzureRmAvailabilitySet',
# VariablesToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()
AliasesToExport = @(
'New-AzureRmVMSqlServerAutoBackupConfig',
'New-AzureRmVMSqlServerAutoPatchingConfig',
'New-AzureRmVMSqlServerKeyVaultCredentialConfig')

# DSC resources to export from this module
# DscResourcesToExport = @()
Expand Down
8 changes: 8 additions & 0 deletions src/ResourceManager/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
- Additional information about change #1
-->
## Current Release
* New parameters in New-AzureRmVMSqlServerAutoBackupConfig cmdlet to support Auto Backup for SQL Server 2016 VMs.
- BackupSystemDbs : Specifies if system databases should be added to Sql Server Managed Backup.
- BackupScheduleType : Specifies the type of managed backup schedule, manual or automated. If it's manual, schedule settings need to be specified.
- FullBackupFrequency : Specifies the frequency of Full Backup, daily or weekly.
- FullBackupStartHour : Specifies the hour of the day when the Sql Server Full Backup should start.
- FullBackupWindowInHours : Specifies the window (in hours) when Sql Server Full Backup should occur.
- LogBackupFrequencyInMinutes : Specifies the frequency of Sql Server Log Backup.
* New-AzureVMSqlServer* cmdlets are renamed to New-AzureRmVMSqlServer* now. Old ones will continue to work however.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anilyela for the change log, can you talk about the new parameters in New-AzureRmVMSqlServerAutoBackupConfig?

* New parameters in ...
    - BackupSystemDbs: < brief description>
    - BackupScheduleType: <brief description>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more detail


## Version 2.4.0
* Add Remove-AzureRmVMSecret cmdlet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.SqlIaaSExtensionTests\TestSqlIaaSExtension.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.SqlIaaSExtensionTests\TestSqlIaaSExtensionWith2016Image.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineBootDiagnosticsTests\TestLinuxVirtualMachineBootDiagnostics.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ public void TestSqlIaaSAKVExtension()
ComputeTestController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmVMSqlServerAKVExtension");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSqlIaaSExtensionWith2016Image()
{
ComputeTestController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmVMSqlServerExtensionWith2016Image");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,32 @@ function Test-SetAzureRmVMSqlServerAKVExtension

#Do actual changes and work here

$extensionName = "Microsoft.SqlServer.Management.SqlIaaSAgent";
$extensionName = "SqlIaaSExtension";

# 1) Installs the SqlIaaS extension by calling Set-AzureRmVMSqlServerExtension cmdlet on a VM.

$securepfxpwd = ConvertTo-SecureString –String "Amu6y/RzJcc7JBzdAdRVv6mk=" –AsPlainText –Force;
$aps_akv = New-AzureVMSqlServerKeyVaultCredentialConfig -ResourceGroupName $rgname -Enable -CredentialName "CredentialTesting" -AzureKeyVaultUrl "https://Testkeyvault.vault.azure.net/" -ServicePrincipalName "0326921f-bf005595337c" -ServicePrincipalSecret $securepfxpwd;
$aps_akv = New-AzureRmVMSqlServerKeyVaultCredentialConfig -ResourceGroupName $rgname -Enable -CredentialName "CredentialTesting" -AzureKeyVaultUrl "https://Testkeyvault.vault.azure.net/" -ServicePrincipalName "0326921f-bf005595337c" -ServicePrincipalSecret $securepfxpwd;
Set-AzureRmVMSqlServerExtension -KeyVaultCredentialSettings $aps_akv -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose;

# 2) Calls Get-AzureRmVMSqlServerExtension cmdlet to check the status of the extension installation.
$extension = Get-AzureRmVMSqlServerExtension -ResourceGroupName $rgname -VmName $vmName -Name $extensionName;

# 3) Verifies settings are correct given input

Assert-AreEqual $extension.KeyVaultCredentialSettings.CredentialName "CredentialTesting";
Assert-AreEqual $extension.KeyVaultCredentialSettings.Credentials.Count 1;
Assert-AreEqual $extension.KeyVaultCredentialSettings.Credentials[0].CredentialName "CredentialTesting"

# 4) Update extension values

$aps_akv = New-AzureVMSqlServerKeyVaultCredentialConfig -ResourceGroupName $rgname -Enable -CredentialName "CredentialTest" -AzureKeyVaultUrl "https://Testkeyvault.vault.azure.net/" -ServicePrincipalName "0326921f-82af-4ab3-9d46-bf005595337c" -ServicePrincipalSecret $securepfxpwd;
$aps_akv = New-AzureRmVMSqlServerKeyVaultCredentialConfig -ResourceGroupName $rgname -Enable -CredentialName "CredentialTest" -AzureKeyVaultUrl "https://Testkeyvault.vault.azure.net/" -ServicePrincipalName "0326921f-82af-4ab3-9d46-bf005595337c" -ServicePrincipalSecret $securepfxpwd;
Set-AzureRmVMSqlServerExtension -KeyVaultCredentialSettings $aps_akv -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose;

# 5) Verify changes
$extension = Get-AzureRmVMSqlServerExtension -ResourceGroupName $rgname -VmName $vmName -Name $extensionName;

Assert-AreEqual $extension.KeyVaultCredentialSettings.CredentialName "CredentialTest"

Assert-AreEqual $extension.KeyVaultCredentialSettings.Credentials.Count 2;
Assert-AreEqual $extension.KeyVaultCredentialSettings.Credentials[1].CredentialName "CredentialTest"

# 6) Test with correct Name and Version

Expand Down Expand Up @@ -183,11 +185,131 @@ function Test-SetAzureRmVMSqlServerExtension

#Do actual changes and work here

$extensionName = "SqlIaaSExtension";

# 1) Installs the SqlIaaS extension by calling Set-AzureRmVMSqlServerExtension cmdlet on a VM, with auto patching and auto backup settings.
$aps = New-AzureRmVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Thursday" -MaintenanceWindowStartingHour 20 -MaintenanceWindowDuration 120 -PatchCategory "Important"
$storageBlobUrl = "https://$stoname.blob.core.windows.net";
$storageKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $rgname -Name $stoname).Key1;
$storageKeyAsSecureString = ConvertTo-SecureString -String $storageKey -AsPlainText -Force;
$abs = New-AzureRmVMSqlServerAutoBackupConfig -Enable -RetentionPeriodInDays 5 -ResourceGroupName $rgname -StorageUri $storageBlobUrl -StorageKey $storageKeyAsSecureString
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -AutoBackupSettings $abs -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose -Name $extensionName;

# 2) Calls Get-AzureRmVMSqlServerExtension cmdlet to check the status of the extension installation.
$extension = Get-AzureRmVMSqlServerExtension -ResourceGroupName $rgname -VmName $vmName -Name $extensionName;

# 3) Verifies settings are correct given input
Assert-AreEqual $extension.AutoPatchingSettings.DayOfWeek "Thursday"
Assert-AreEqual $extension.AutoPatchingSettings.MaintenanceWindowStartingHour 20
Assert-AreEqual $extension.AutoPatchingSettings.MaintenanceWindowDuration 120
Assert-AreEqual $extension.AutoPatchingSettings.PatchCategory "Important"

Assert-AreEqual $extension.AutoBackupSettings.RetentionPeriod 5
Assert-AreEqual $extension.AutoBackupSettings.Enable $true

# 4) Update extension values
$aps = New-AzureRmVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Monday" -MaintenanceWindowStartingHour 20 -MaintenanceWindowDuration 120 -PatchCategory "Important"
$abs = New-AzureRmVMSqlServerAutoBackupConfig -Enable -RetentionPeriodInDays 10 -ResourceGroupName $rgname -StorageUri $storageBlobUrl -StorageKey $storageKeyAsSecureString
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -AutoBackupSettings $abs -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose -Name $extensionName;

# 5) Verify changes

$extension = Get-AzureRmVMSqlServerExtension -ResourceGroupName $rgname -VmName $vmName -Name $extensionName;
Assert-AreEqual $extension.AutoPatchingSettings.DayOfWeek "Monday"
Assert-AreEqual $extension.AutoBackupSettings.RetentionPeriod 10

# 6) Test with correct Name and Version
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -AutoBackupSettings $abs -ResourceGroupName $rgname -VMName $vmName -Name $extensionName -Version "1.2"

# 7) Test with correct Name and incorrect Version
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -AutoBackupSettings $abs -ResourceGroupName $rgname -VMName $vmName -Name $extensionName -Version "1.*"
}
finally
{
# Cleanup
if(Get-AzureRmResourceGroup -Name $rgname -Location $loc)
{
#Remove-AzureRmResourceGroup -Name $rgname -Force;
}
}
}

# Test setting up VM with Sql Server 2016 image. (Includes testing for AutoBackup V2)
function Test-SetAzureRmVMSqlServerExtensionWith2016Image
{
Set-StrictMode -Version latest; $ErrorActionPreference = 'Stop'

# Setup
$rgname = Get-ComputeTestResourceName
$loc = Get-ComputeVMLocation

try
{
# Common
New-AzureRmResourceGroup -Name $rgname -Location $loc -Force;

# VM Profile & Hardware
$vmsize = 'Standard_A2';
$vmname = 'vm' + $rgname;
$p = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize;
Assert-AreEqual $p.HardwareProfile.VmSize $vmsize;

# NRP
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
$vnet = New-AzureRmVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
$vnet = Get-AzureRmVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
$subnetId = $vnet.Subnets[0].Id;
$pubip = New-AzureRmPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
$pubip = Get-AzureRmPublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
$pubipId = $pubip.Id;
$nic = New-AzureRmNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
$nic = Get-AzureRmNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;
$nicId = $nic.Id;

$p = Add-AzureRmVMNetworkInterface -VM $p -Id $nicId;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].Id $nicId;

# Storage Account
$stoname = 'sto' + $rgname;
$stotype = 'Standard_GRS';
New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
Retry-IfException { $global:stoaccount = Get-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname; }

$osDiskName = 'osDisk';
$osDiskCaching = 'ReadWrite';
$osDiskVhdUri = "https://$stoname.blob.core.windows.net/test/os.vhd";
$dataDiskVhdUri1 = "https://$stoname.blob.core.windows.net/test/data1.vhd";

$p = Set-AzureRmVMOSDisk -VM $p -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption FromImage;
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;

# OS & Image
$user = "localadmin";
$password = $PLACEHOLDER;
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
$computerName = 'test';
$vhdContainer = "https://$stoname.blob.core.windows.net/test";

$p = Set-AzureRmVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred -ProvisionVMAgent;
$p = Set-AzureRmVMSourceImage -VM $p -PublisherName MicrosoftSQLServer -Offer SQL2016-WS2012R2 -Skus Enterprise -Version "latest"

# Virtual Machine
New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $p;

#Do actual changes and work here

$extensionName = "Microsoft.SqlServer.Management.SqlIaaSAgent";

# 1) Installs the SqlIaaS extension by calling Set-AzureRmVMSqlServerExtension cmdlet on a VM.
$aps = New-AzureVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Thursday" -MaintenanceWindowStartingHour 20 -MaintenanceWindowDuration 120 -PatchCategory "Important"
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose -Name $extensionName;
# 1) Installs the SqlIaaS extension by calling Set-AzureRmVMSqlServerExtension cmdlet on a VM, with auto patching and auto backup settings.
$aps = New-AzureRmVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Thursday" -MaintenanceWindowStartingHour 20 -MaintenanceWindowDuration 120 -PatchCategory "Important"
$storageBlobUrl = "https://$stoname.blob.core.windows.net";
$storageKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $rgname -Name $stoname).Key1;
$storageKeyAsSecureString = ConvertTo-SecureString -String $storageKey -AsPlainText -Force;
$abs = New-AzureRmVMSqlServerAutoBackupConfig -Enable -RetentionPeriodInDays 5 -ResourceGroupName $rgname -StorageUri $storageBlobUrl -StorageKey $storageKeyAsSecureString `
-BackupScheduleType Manual -BackupSystemDbs -FullBackupStartHour 10 -FullBackupWindowInHours 5 -FullBackupFrequency Daily -LogBackupFrequencyInMinutes 30
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -AutoBackupSettings $abs -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose -Name $extensionName;

# 2) Calls Get-AzureRmVMSqlServerExtension cmdlet to check the status of the extension installation.
$extension = Get-AzureRmVMSqlServerExtension -ResourceGroupName $rgname -VmName $vmName -Name $extensionName;
Expand All @@ -198,19 +320,33 @@ function Test-SetAzureRmVMSqlServerExtension
Assert-AreEqual $extension.AutoPatchingSettings.MaintenanceWindowDuration 120
Assert-AreEqual $extension.AutoPatchingSettings.PatchCategory "Important"

Assert-AreEqual $extension.AutoBackupSettings.RetentionPeriod 5
Assert-AreEqual $extension.AutoBackupSettings.Enable $true
Assert-AreEqual $extension.AutoBackupSettings.BackupScheduleType "Manual"
Assert-AreEqual $extension.AutoBackupSettings.FullBackupFrequency "Daily"
Assert-AreEqual $extension.AutoBackupSettings.BackupSystemDbs $true
Assert-AreEqual $extension.AutoBackupSettings.FullBackupStartTime 10
Assert-AreEqual $extension.AutoBackupSettings.FullBackupWindowHours 5
Assert-AreEqual $extension.AutoBackupSettings.LogBackupFrequency 30

# 4) Update extension values
$aps = New-AzureVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Monday" -MaintenanceWindowStartingHour 20 -MaintenanceWindowDuration 120 -PatchCategory "Important"
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose -Name $extensionName;
$aps = New-AzureRmVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Monday" -MaintenanceWindowStartingHour 20 -MaintenanceWindowDuration 120 -PatchCategory "Important"
$abs = New-AzureRmVMSqlServerAutoBackupConfig -Enable -RetentionPeriodInDays 10 -ResourceGroupName $rgname -StorageUri $storageBlobUrl `
-StorageKey $storageKeyAsSecureString -BackupScheduleType Automated
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -AutoBackupSettings $abs -ResourceGroupName $rgname -VMName $vmname -Version "1.2" -Verbose -Name $extensionName;

# 5) Verify changes
$extension = Get-AzureRmVMSqlServerExtension -ResourceGroupName $rgname -VmName $vmName -Name $extensionName;
Assert-AreEqual $extension.AutoPatchingSettings.DayOfWeek "Monday"
Assert-AreEqual $extension.AutoBackupSettings.RetentionPeriod 10
Assert-AreEqual $extension.AutoBackupSettings.Enable $true
Assert-AreEqual $extension.AutoBackupSettings.BackupScheduleType "Automated"

# 6) Test with correct Name and Version
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -ResourceGroupName $rgname -VMName $vmName -Name $extensionName -Version "1.2"
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -AutoBackupSettings $abs -ResourceGroupName $rgname -VMName $vmName -Name $extensionName -Version "1.2"

# 7) Test with correct Name and incorrect Version
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -ResourceGroupName $rgname -VMName $vmName -Name $extensionName -Version "1.*"
Set-AzureRmVMSqlServerExtension -AutoPatchingSettings $aps -AutoBackupSettings $abs -ResourceGroupName $rgname -VMName $vmName -Name $extensionName -Version "1.*"
}
finally
{
Expand Down
Loading