mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Azure SQL Hybrid Cloud Toolkit Notebooks Extension Command (#13286)
* added extension folder incomplete * WIP extension progress * notebook finally opens in side panel * notebook now opens via notebook extension * html file spaces restored * package json fixed * fixed vscode import issue * more cleanup * remove git stuff * placeholder icon logos added * fixed gulpfile * cleanup changes * vscode import fixed * fixed main and yarn.lock * added provided notebooks view * formatting for package.json * removed first command as its not necessary * fixed notebook typo * readded spaces
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"name": "python3",
|
||||
"display_name": "Python 3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python",
|
||||
"version": "3.7.8",
|
||||
"mimetype": "text/x-python",
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"pygments_lexer": "ipython3",
|
||||
"nbconvert_exporter": "python",
|
||||
"file_extension": ".py"
|
||||
}
|
||||
},
|
||||
"nbformat_minor": 2,
|
||||
"nbformat": 4,
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"Migrate a Database to a Azure SQL Managed Instance\n",
|
||||
"=============================================\n",
|
||||
"\n",
|
||||
"Description\n",
|
||||
"-----\n",
|
||||
"\n",
|
||||
"Copies the database from an on-premises SQL instance to an Azure SQL Managed Instance."
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "5353c044-9920-478b-b1f8-e98119b73a21"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,339 @@
|
||||
{
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"name": "powershell",
|
||||
"display_name": "PowerShell"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "powershell",
|
||||
"codemirror_mode": "shell",
|
||||
"mimetype": "text/x-sh",
|
||||
"file_extension": ".ps1"
|
||||
}
|
||||
},
|
||||
"nbformat_minor": 2,
|
||||
"nbformat": 4,
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"Migrate SQL Server Instance to Azure SQL Server VM\n",
|
||||
"================================"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "f706da59-22c3-4317-bf41-c00dde794097"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"### Load Required Modules\r\n",
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "67e288c6-63df-475e-9cad-bab323d30c4e"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"Import-Module dbatools\r\n",
|
||||
"Import-Module Az.Resources\r\n",
|
||||
"Import-Module Az.Storage"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "26df73fa-6f4f-40b4-8c47-10ce7e2db404",
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"### Choose Migration Source\r\n",
|
||||
"\r\n",
|
||||
"Required parameters:\r\n",
|
||||
"\r\n",
|
||||
"- Server Name\r\n",
|
||||
"- Database Name\r\n",
|
||||
"- "
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "1e70b806-c94d-4be2-87cf-ad73fb85821d"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"$Credential = Get-Credential -Message \"Type the name and password of the local administrator account.\"\r\n",
|
||||
"$Credential"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "41faae8f-6245-4acb-88d5-dbb0b92ad7f5"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"# Variables\r\n",
|
||||
"\r\n",
|
||||
"## Global\r\n",
|
||||
"$Location = \"West US 2\"\r\n",
|
||||
"$ResourceGroupName = \"sqlmig\"\r\n",
|
||||
"\r\n",
|
||||
"## Storage\r\n",
|
||||
"$StorageName = $ResourceGroupName + \"storage\"\r\n",
|
||||
"$StorageSku = \"Premium_LRS\"\r\n",
|
||||
"\r\n",
|
||||
"## Network\r\n",
|
||||
"$InterfaceName = $ResourceGroupName + \"ServerInterface\"\r\n",
|
||||
"$NsgName = $ResourceGroupName + \"nsg\"\r\n",
|
||||
"$VNetName = $ResourceGroupName + \"VNet\"\r\n",
|
||||
"$SubnetName = \"Default\"\r\n",
|
||||
"$VNetAddressPrefix = \"10.0.0.0/16\"\r\n",
|
||||
"$VNetSubnetAddressPrefix = \"10.0.0.0/24\"\r\n",
|
||||
"$TCPIPAllocationMethod = \"Dynamic\"\r\n",
|
||||
"$DomainName = $ResourceGroupName\r\n",
|
||||
"\r\n",
|
||||
"##Compute\r\n",
|
||||
"$VMName = $ResourceGroupName + \"VM\"\r\n",
|
||||
"$ComputerName = $ResourceGroupName + \"Server\"\r\n",
|
||||
"$VMSize = \"Standard_DS13_v2\"\r\n",
|
||||
"$OSDiskName = $VMName + \"OSDisk\"\r\n",
|
||||
"\r\n",
|
||||
"##Image\r\n",
|
||||
"$PublisherName = \"MicrosoftSQLServer\"\r\n",
|
||||
"$OfferName = \"SQL2017-WS2016\"\r\n",
|
||||
"$Sku = \"SQLDEV\"\r\n",
|
||||
"$Version = \"latest\"\r\n",
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "7e251e62-b47c-4800-986d-b71be8bc0a21"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"# Resource Group\r\n",
|
||||
"New-AzResourceGroup -Name $ResourceGroupName -Location $Location\r\n",
|
||||
"$ResourceGroupName\r\n",
|
||||
"$Location"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "eea4904c-55f0-47a4-81a3-5daf0a864687"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"# Storage\r\n",
|
||||
"$StorageAccount = New-AzStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageName -SkuName $StorageSku -Kind \"Storage\" -Location $Location\r\n",
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "b19f1450-0283-4772-862a-3e59b65d0e75"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"$StorageAccount = Get-AzStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageName"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "42602cef-76ed-4c91-a2f0-a7a8a6132eff"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"# Network\r\n",
|
||||
"$SubnetConfig = New-AzVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix $VNetSubnetAddressPrefix\r\n",
|
||||
"$VNet = New-AzVirtualNetwork -Name $VNetName -ResourceGroupName $ResourceGroupName -Location $Location -AddressPrefix $VNetAddressPrefix -Subnet $SubnetConfig\r\n",
|
||||
"$PublicIp = New-AzPublicIpAddress -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -AllocationMethod $TCPIPAllocationMethod -DomainNameLabel $DomainName\r\n",
|
||||
"#$NsgRuleRDP = New-AzNetworkSecurityRuleConfig -Name \"RDPRule\" -Protocol Tcp -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow\r\n",
|
||||
"$NsgRuleSQL = New-AzNetworkSecurityRuleConfig -Name \"MSSQLRule\" -Protocol Tcp -Direction Inbound -Priority 1001 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 1433 -Access Allow\r\n",
|
||||
"#$Nsg = New-AzNetworkSecurityGroup -ResourceGroupName $ResourceGroupName -Location $Location -Name $NsgName -SecurityRules $NsgRuleRDP,$NsgRuleSQL\r\n",
|
||||
"$Nsg = New-AzNetworkSecurityGroup -ResourceGroupName $ResourceGroupName -Location $Location -Name $NsgName -SecurityRules $NsgRuleSQL\r\n",
|
||||
"$Interface = New-AzNetworkInterface -Name $InterfaceName -ResourceGroupName $ResourceGroupName -Location $Location -SubnetId $VNet.Subnets[0].Id -PublicIpAddressId $PublicIp.Id -NetworkSecurityGroupId $Nsg.Id\r\n",
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "0435fd83-3e9c-4929-930a-2b7022db3f99"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"$StorageAccount"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "37e1869b-eb9f-465a-87d3-78120e4c6d06"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"# Compute\r\n",
|
||||
"$VirtualMachine = New-AzVMConfig -VMName $VMName -VMSize $VMSize\r\n",
|
||||
"#$Credential = Get-Credential -Message \"Type the name and password of the local administrator account.\"\r\n",
|
||||
"$VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName $ComputerName -Credential $Credential -ProvisionVMAgent -EnableAutoUpdate #-TimeZone = $TimeZone\r\n",
|
||||
"$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $Interface.Id\r\n",
|
||||
"#$OSDiskUri = $StorageAccount.PrimaryEndpoints.Blob.ToString() + \"vhds/\" + $OSDiskName + \".vhd\"\r\n",
|
||||
"#$VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -Name $OSDiskName -VhdUri $OSDiskUri -Caching ReadOnly -CreateOption FromImage\r\n",
|
||||
"$VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine -PublisherName $PublisherName -Offer $OfferName -Skus $Sku -Version $Version"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "d0a4da84-d591-436e-8b6c-d4cb2787a6e2"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"# Create the VM in Azure\r\n",
|
||||
"New-AzVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $VirtualMachine\r\n",
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "70967b75-1ef7-4d69-aad9-0184cfb44aa9"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"# Add the SQL IaaS Extension, and choose the license type\r\n",
|
||||
"New-AzSqlVM -ResourceGroupName $ResourceGroupName -Name $VMName -Location $Location -LicenseType \"PAYG\""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "a8db01b1-a009-4367-bd39-77187482afc3"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"### Verify No Active Connections"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "81259d7e-62ac-4cdd-9e1b-2cb4ddb3d3b2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"\r\n",
|
||||
"$ServerName = \"sqltools2017-3\"\r\n",
|
||||
"$DatabaseName = \"Keep_WideWorldImporters\"\r\n",
|
||||
"\r\n",
|
||||
"Get-DbaProcess -SqlInstance $ServerName -Database $DatabaseName | \r\n",
|
||||
"Select Host, login, Program"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "28393e59-4ea1-4f0f-8f9f-8a504f15e723"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"### Create Target SQL Server VM"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "07d076d0-abf3-496c-8ecb-f85102c4104b"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "6f190c2d-7361-4db8-819d-29087eae8aaa"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"### Create temporary resources for data movement"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "cc18027e-4636-465d-abaf-f3de88fea406"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"$location = \"westus\"\r\n",
|
||||
"$resourceGroup = \"temp-sqlmigration\"\r\n",
|
||||
"$blobStorageAccount = \"temp-sqlmigration\"\r\n",
|
||||
"$containerName = \"backups\"\r\n",
|
||||
"\r\n",
|
||||
"\r\n",
|
||||
"\r\n",
|
||||
"New-AzResourceGroup"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "f7d53cb1-a55d-4634-95f7-d3e8cf9fab52"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"$targetLogin = Get-Credential -Message \"Login to target SQL Server instance as:\""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "c3dbd1a7-5514-4fdc-9430-736c92e875a4"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"$myGwIp = Get-AzPublicIpAddress -Name $GwIP1 -ResourceGroup $RG1\r\n",
|
||||
"$myGwIp.IpAddress"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "bc6e8330-95bb-44a5-a117-020f657cad2b"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "a61ffe69-0929-4246-8ad0-846f540f4e0c"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
{
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"name": "powershell",
|
||||
"display_name": "PowerShell"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "powershell",
|
||||
"codemirror_mode": "shell",
|
||||
"mimetype": "text/x-sh",
|
||||
"file_extension": ".ps1"
|
||||
}
|
||||
},
|
||||
"nbformat_minor": 2,
|
||||
"nbformat": 4,
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"Migrate SQL Server Database to Azure SQL Server VM\n",
|
||||
"================================"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "f706da59-22c3-4317-bf41-c00dde794097"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Source SQL Instance\r\n",
|
||||
"The following code is used to specify the source SQL Server instance. Data and Server objects will be copied from this server to the target SQL Server instance. In the following code cell set the following parameters:\r\n",
|
||||
"\r\n",
|
||||
"*Note: the notebook currently is setup for SQL Authentication. Future updates will add support for multiple authentication types.*\r\n",
|
||||
"\r\n",
|
||||
"|Parameter|Description|\r\n",
|
||||
"|---|---|\r\n",
|
||||
"|sourceServerName| The name or IP address of the source instance|\r\n",
|
||||
"|sourceLogin| sql login to connect to source instance with |\r\n",
|
||||
"\r\n",
|
||||
"*Note: source password should be set in the environment variable SQLMIG_SourcePassword. This is to avoid persisting the environment variable in the notebook file.*\r\n",
|
||||
"\r\n",
|
||||
"Edit the code below to specify the above parameters to test connectivity to the source instance.\r\n",
|
||||
"\r\n",
|
||||
"\r\n",
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "2ac081f4-853a-4381-a303-e6ca557503fb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"$sourceServerName = 'sqltools2016-3'\r\n",
|
||||
"$sourceLogin = 'migtest'\r\n",
|
||||
"\r\n",
|
||||
"## TEMP - REMOVE BEFORE PUSHING CHANGES\r\n",
|
||||
"$env:SQLMIG_SourcePassword = 'Yukon900'\r\n",
|
||||
"\r\n",
|
||||
"## PowerShell Environment \r\n",
|
||||
"$sourceLoginPassword = ConvertTo-SecureString $env:SQLMIG_SourcePassword -AsPlaintext -Force\r\n",
|
||||
"$sourceCredential = New-Object System.Management.Automation.PSCredential ('migtest', $sourceLoginPassword)\r\n",
|
||||
"$sourceTest = Test-DbaConnection -SqlInstance $sourceServerName -SqlCredential $sourceCredential\r\n",
|
||||
"$sourceTest\r\n",
|
||||
"$sourceConnection = Connect-DbaInstance -SqlInstance $sourceServerName -SqlCredential $sourceCredential"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "76a50416-b804-46ae-a49c-99baaeb31f7d"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Target SQL Instance\r\n",
|
||||
"The following code is used to specify the target SQL Server instance. This is the SQL Server instance that Data and Server objects will be copied to. In the following code cell set the following parameters:\r\n",
|
||||
"\r\n",
|
||||
"*Note: the notebook currently is setup for SQL Authentication. Future updates will add support for multiple authentication types.*\r\n",
|
||||
"\r\n",
|
||||
"|Parameter|Description|\r\n",
|
||||
"|---|---|\r\n",
|
||||
"|targetServerName| The name or IP address of the target instance|\r\n",
|
||||
"|targetLogin| sql login to connect to target instance with |\r\n",
|
||||
"\r\n",
|
||||
"*Note: the target login password should be set in the environment variable SQLMIG_TargetPassword. Thisis to avoid persisting the environment variable in the notebook file.*\r\n",
|
||||
"\r\n",
|
||||
"Edit the code below to specify the above parameters to test connectivity to the target instance."
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "43751f97-d545-4e84-ac99-109c719a048d"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"$targetServerName = 'sqlmig.westus2.cloudapp.azure.com'\r\n",
|
||||
"$targetLogin = 'cloudsa'\r\n",
|
||||
"\r\n",
|
||||
"## TEMP - REMOVE BEFORE PUSHING CHANGES\r\n",
|
||||
"$env:SQLMIG_TargetPassword = 'Yukon900Yukon900'\r\n",
|
||||
"\r\n",
|
||||
"## PowerShell Environment \r\n",
|
||||
"$targetLoginPassword = ConvertTo-SecureString $env:SQLMIG_TargetPassword -AsPlaintext -Force\r\n",
|
||||
"$targetCredential = New-Object System.Management.Automation.PSCredential ('migtest', $targetLoginPassword)\r\n",
|
||||
"$targetTest = Test-DbaConnection -SqlInstance $targetServerName -SqlCredential $targetCredential\r\n",
|
||||
"$targetTest\r\n",
|
||||
"$targetConnection = Connect-DbaInstance -SqlInstance $targetServerName -SqlCredential $targetCredential"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "4f74315c-1147-4fe3-8959-13eb24cb0957"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Login to Microsoft Azure\r\n",
|
||||
"To configure and provision resources you must log into your Azure account and set the current subscription that is being used for the target SQL Server instance. The following code will help you connect your account and choose the correct subscription. When presented with the list of subscriptions, click on the desired subscription and press OK."
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "2ffbcba3-934e-4498-87ed-7030124d3af2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"#Connect-AzAccount\r\n",
|
||||
"$migrationSubscription = Get-AzSubscription | Select-Object -Property Name, Id | Out-GridView -PassThru\r\n",
|
||||
"Set-AzContext -SubscriptionId $migrationSubscription.Id"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "8b23dcba-8d28-44eb-abbb-c7a54ef6b003",
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Verify No Active Connections"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "81259d7e-62ac-4cdd-9e1b-2cb4ddb3d3b2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"#TODO - filter connected proceesses for user connections\r\n",
|
||||
"\r\n",
|
||||
"\r\n",
|
||||
"Get-DbaProcess -SqlInstance $SourceServerName -SqlCredential $sourceLogin | \r\n",
|
||||
"Select Host, login, Program"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "28393e59-4ea1-4f0f-8f9f-8a504f15e723",
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Temporary Storage for Data Movement\r\n",
|
||||
"\r\n",
|
||||
"Offline data migration attempts to use backup to URL and restore from URL as the mechanism for moving data from the source instance to the target instance. This code will check existance of the specified storage account and container to use for data migration. If the resources do not exist they will be created."
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "cc18027e-4636-465d-abaf-f3de88fea406"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"$resourceGroup = \"sqlmig\"\r\n",
|
||||
"$blobStorageAccount = \"tempsqlmigstorage\"\r\n",
|
||||
"$containerName = \"backups\"\r\n",
|
||||
"$location = \"West US 2\"\r\n",
|
||||
"\r\n",
|
||||
"# Storage Account\r\n",
|
||||
"$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroup -Name $blobStorageAccount\r\n",
|
||||
"if ($storageAccount -eq $null)\r\n",
|
||||
"{\r\n",
|
||||
" # specified storage account does not yet exist, attempt to create it\r\n",
|
||||
" $storageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroup -Name $blobStorageAccount -Location $location -SkuName Standard_LRS -Kind StorageV2\r\n",
|
||||
"}\r\n",
|
||||
"$storageAccount\r\n",
|
||||
"\r\n",
|
||||
"# Container\r\n",
|
||||
"$storageContext = $storageAccount.Context\r\n",
|
||||
"$storageContainer = Get-AzStorageContainer -Name $containerName -Context $storageContext\r\n",
|
||||
"if ($storageContainer -eq $null)\r\n",
|
||||
"{\r\n",
|
||||
" #specified storage container does not yet exist, attempt to create it\r\n",
|
||||
" $storageContainer = New-AzStorageContainer -Name $containerName -Context $storageContext -Permission Container\r\n",
|
||||
"}\r\n",
|
||||
"$storageContainer\r\n",
|
||||
"\r\n",
|
||||
"# Provide source instance with SAS token for blob access\r\n",
|
||||
"$sourceSAS = (New-AzStorageAccountSASToken -Service Blob -ResourceType Object -Permission \"rw\" -Context $storageContext).TrimStart('?')\r\n",
|
||||
"$sourceCred = New-DbaCredential -SqlInstance $sourceConnection -Name \"https://$blobStorageAccount.blob.core.windows.net/$containerName\" -Identity \"SHARED ACCESS SIGNATURE\" -SecurePassword (ConvertTo-SecureString $sourceSAS -AsPlainText -Force) -Force\r\n",
|
||||
"$sourceCred\r\n",
|
||||
"\r\n",
|
||||
"$targetSAS = (New-AzStorageAccountSASToken -Service Blob -ResourceType Object -Permission \"rw\" -Context $storageContext).TrimStart('?') # -ResourceType Container,Object\r\n",
|
||||
"$targetCred = New-DbaCredential -SqlInstance $targetConnection -Name \"https://$blobStorageAccount.blob.core.windows.net/$containerName\" -Identity \"SHARED ACCESS SIGNATURE\" -SecurePassword (ConvertTo-SecureString $targetSAS -AsPlainText -Force) -Force\r\n",
|
||||
"$targetCred\r\n",
|
||||
"\r\n",
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "f7d53cb1-a55d-4634-95f7-d3e8cf9fab52"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Copy Databases to Target Server\r\n",
|
||||
"\r\n",
|
||||
"The following code will present a list of the databases from the source SQL Server instance. Select the list of databases to copy and press OK. The Copy-DbaDatabase CMDLET will take a backup of each database using the azure storage account information above. Each database backup will then be restored from the blob storage account. The database restore will use server defaults for database file location and structure.\r\n",
|
||||
"\r\n",
|
||||
"If the database being restored already exists on the target instance, the *Force* parameter determines the behavior of the notebook:\r\n",
|
||||
"\r\n",
|
||||
"|Force|Description|\r\n",
|
||||
"|---|---|\r\n",
|
||||
"|$true| Overwrite the existing database on the target instance|\r\n",
|
||||
"|$false| Do not restore the database if it already exists on the target instance|\r\n",
|
||||
"\r\n",
|
||||
"*Note: This can be a very long running process based on the size of the databases being copied. The notebook should be allowed to run until the CMDLET completes.*\r\n",
|
||||
"\r\n",
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "a82b0092-53a1-4dc3-8d73-16fae8c59ff7"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"$databasesToCopy = Get-DbaDatabase -SqlInstance $sourceConnection | Select-Object -Property Name | Out-GridView -PassThru\r\n",
|
||||
"$databaseList = New-Object System.Collections.ArrayList\r\n",
|
||||
"foreach ($db in $databasesToCopy)\r\n",
|
||||
"{\r\n",
|
||||
" $databaseList.Add($db.Name) \r\n",
|
||||
"}\r\n",
|
||||
"\r\n",
|
||||
"$copyDatabaseParams = @{\r\n",
|
||||
" Database = $databaseList\r\n",
|
||||
" Source = $sourceConnection\r\n",
|
||||
" Destination = $targetConnection\r\n",
|
||||
" BackupRestore = $true\r\n",
|
||||
" SharedPath = \"https://$blobStorageAccount.blob.core.windows.net/$containerName\"\r\n",
|
||||
" Force = $true\r\n",
|
||||
" Verbose = $false \r\n",
|
||||
"}\r\n",
|
||||
"\r\n",
|
||||
"Copy-DbaDatabase @copyDatabaseParams"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "5614e073-0a94-45af-8432-e7a6bf9121ea"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"name": "powershell",
|
||||
"display_name": "PowerShell"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "powershell",
|
||||
"codemirror_mode": "shell",
|
||||
"mimetype": "text/x-sh",
|
||||
"file_extension": ".ps1"
|
||||
}
|
||||
},
|
||||
"nbformat_minor": 2,
|
||||
"nbformat": 4,
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"Migrate SQL Server Instance to Azure SQL Managed Instance\n",
|
||||
"=============================================\n",
|
||||
"\n",
|
||||
"Description\n",
|
||||
"-----\n",
|
||||
"\n",
|
||||
"clone the configuration and data of a sql instance into a managed instance\n",
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "43600853-57b3-4e60-a2a9-a28fb82af386"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
{
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"name": "powershell",
|
||||
"display_name": "PowerShell"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "powershell",
|
||||
"codemirror_mode": "shell",
|
||||
"mimetype": "text/x-sh",
|
||||
"file_extension": ".ps1"
|
||||
}
|
||||
},
|
||||
"nbformat_minor": 2,
|
||||
"nbformat": 4,
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"Migrate SQL Server Instance to Azure SQL Server VM\n",
|
||||
"================================"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "f706da59-22c3-4317-bf41-c00dde794097"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Source SQL Instance\r\n",
|
||||
"The following code is used to specify the source SQL Server instance. Data and Server objects will be copied from this server to the target SQL Server instance. The code below will first prompt for the name of the source SQL Server instance. Secondarily, the code will use a secure credential prompt for the login credentials for the source instance. \r\n",
|
||||
"\r\n",
|
||||
"*Note: the notebook currently is setup for SQL Authentication. Future updates will add support for multiple authentication types.*\r\n",
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "2ac081f4-853a-4381-a303-e6ca557503fb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"# set the name or IP address of the source SQL Server instance\n",
|
||||
"Add-Type -Assemblyname PresentationFramework\n",
|
||||
"$sourceInfoBox = New-Object AnyBox.AnyBox\n",
|
||||
"\n",
|
||||
"$sourceInfoBox.Prompts = New-AnyBoxPrompt -Name \"serverName\" -Message \"Source SQL Instance name or IP address:\" -ValidateNotEmpty\n",
|
||||
"$sourceInfoBox.Buttons = New-AnyBoxButton -Name 'submit' -Text \"OK\" -IsDefault\n",
|
||||
"\n",
|
||||
"$sourceInfoBox.Topmost = $true\n",
|
||||
"$sourceInfoBox.WindowStyle = 'None'\n",
|
||||
"\n",
|
||||
"$sourceInfoResponse = $sourceInfoBox | Show-AnyBox\n",
|
||||
"$sourceServerName = $sourceInfoResponse['serverName']\n",
|
||||
"\n",
|
||||
"# prompt for username and pw for authentication - supports SQL Authentication currently\n",
|
||||
"$sourceCredential = Get-Credential -Message \"Enter Source Login Credentials\"\n",
|
||||
"\n",
|
||||
"# test the connectivity and display instance information\n",
|
||||
"$sourceTest = Test-DbaConnection -SqlInstance $sourceServerName -SqlCredential $sourceCredential\n",
|
||||
"$sourceTest\n",
|
||||
"\n",
|
||||
"# sourceConnection is used in the SQL migration cell below\n",
|
||||
"$sourceConnection = Connect-DbaInstance -SqlInstance $sourceServerName -SqlCredential $sourceCredential"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "76a50416-b804-46ae-a49c-99baaeb31f7d",
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Target SQL Instance\r\n",
|
||||
"The following code is used to specify the target SQL Server instance. Data and Server objects will be copied to this server from the source SQL Server instance. The code below will first prompt for the name of the target SQL Server instance. Secondarily, the code will use a secure credential prompt for the login credentials for the target instance. \r\n",
|
||||
"\r\n",
|
||||
"*Note: the notebook currently is setup for SQL Authentication. Future updates will add support for multiple authentication types.*\r\n",
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "43751f97-d545-4e84-ac99-109c719a048d"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"# set the name or IP address of the source SQL Server instance\r\n",
|
||||
"Add-Type -Assemblyname PresentationFramework\r\n",
|
||||
"$targetInfoBox = New-Object AnyBox.AnyBox\r\n",
|
||||
"\r\n",
|
||||
"$targetInfoBox.Prompts = New-AnyBoxPrompt -Name \"serverName\" -Message \"Target SQL Instance name or IP address:\" -ValidateNotEmpty\r\n",
|
||||
"$targetInfoBox.Buttons = New-AnyBoxButton -Name 'submit' -Text \"OK\" -IsDefault\r\n",
|
||||
"\r\n",
|
||||
"$targetInfoBox.Topmost = $true\r\n",
|
||||
"$targetInfoBox.WindowStyle = 'None'\r\n",
|
||||
"\r\n",
|
||||
"$targetInfoResponse = $targetInfoBox | Show-AnyBox\r\n",
|
||||
"$targetServerName = $targetInfoResponse['serverName']\r\n",
|
||||
"\r\n",
|
||||
"# prompt for username and pw for authentication - supports SQL Authentication currently\r\n",
|
||||
"$targetCredential = Get-Credential -Message \"Enter Target Login Credentials\"\r\n",
|
||||
"\r\n",
|
||||
"## PowerShell Environment \r\n",
|
||||
"$targetTest = Test-DbaConnection -SqlInstance $targetServerName -SqlCredential $targetCredential\r\n",
|
||||
"$targetTest\r\n",
|
||||
"$targetConnection = Connect-DbaInstance -SqlInstance $targetServerName -SqlCredential $targetCredential"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "4f74315c-1147-4fe3-8959-13eb24cb0957"
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Login to Microsoft Azure\r\n",
|
||||
"To configure and provision resources you must log into your Azure account and set the current subscription that is being used for the target SQL Server instance. The following code will help you connect your account and choose the correct subscription. When presented with the list of subscriptions, click on the desired subscription and press OK."
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "2ffbcba3-934e-4498-87ed-7030124d3af2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"Connect-AzAccount\r\n",
|
||||
"$migrationSubscription = Get-AzSubscription | Select-Object -Property Name, Id | Out-GridView -PassThru\r\n",
|
||||
"Set-AzContext -SubscriptionId $migrationSubscription.Id"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "8b23dcba-8d28-44eb-abbb-c7a54ef6b003",
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Verify No Active Connections"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "81259d7e-62ac-4cdd-9e1b-2cb4ddb3d3b2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"#TODO - filter connected proceesses for user connections\r\n",
|
||||
"\r\n",
|
||||
"\r\n",
|
||||
"Get-DbaProcess -SqlInstance $SourceServerName -SqlCredential $sourceLogin | \r\n",
|
||||
"Select Host, login, Program"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "28393e59-4ea1-4f0f-8f9f-8a504f15e723",
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Temporary Storage for Data Movement\r\n",
|
||||
"\r\n",
|
||||
"Offline data migration attempts to use backup to URL and restore from URL as the mechanism for moving data from the source instance to the target instance. This code will check existance of the specified storage account and container to use for data migration. If the resources do not exist they will be created."
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "cc18027e-4636-465d-abaf-f3de88fea406"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"# TODO - add interactive support for these values\r\n",
|
||||
"$resourceGroup = \"sqlmig\"\r\n",
|
||||
"$blobStorageAccount = \"tempsqlmigstorage\"\r\n",
|
||||
"$containerName = \"backups\"\r\n",
|
||||
"$location = \"West US 2\"\r\n",
|
||||
"\r\n",
|
||||
"# Storage Account\r\n",
|
||||
"$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroup -Name $blobStorageAccount\r\n",
|
||||
"if ($storageAccount -eq $null)\r\n",
|
||||
"{\r\n",
|
||||
" # specified storage account does not yet exist, attempt to create it\r\n",
|
||||
" $storageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroup -Name $blobStorageAccount -Location $location -SkuName Standard_LRS -Kind StorageV2\r\n",
|
||||
"}\r\n",
|
||||
"$storageAccount\r\n",
|
||||
"\r\n",
|
||||
"# Container\r\n",
|
||||
"$storageContext = $storageAccount.Context\r\n",
|
||||
"$storageContainer = Get-AzStorageContainer -Name $containerName -Context $storageContext\r\n",
|
||||
"if ($storageContainer -eq $null)\r\n",
|
||||
"{\r\n",
|
||||
" #specified storage container does not yet exist, attempt to create it\r\n",
|
||||
" $storageContainer = New-AzStorageContainer -Name $containerName -Context $storageContext -Permission Container\r\n",
|
||||
"}\r\n",
|
||||
"$storageContainer\r\n",
|
||||
"\r\n",
|
||||
"# Provide source instance with SAS token for blob access\r\n",
|
||||
"$sourceSAS = (New-AzStorageAccountSASToken -Service Blob -ResourceType Object -Permission \"rw\" -Context $storageContext).TrimStart('?')\r\n",
|
||||
"$sourceCred = New-DbaCredential -SqlInstance $sourceConnection -Name \"https://$blobStorageAccount.blob.core.windows.net/$containerName\" -Identity \"SHARED ACCESS SIGNATURE\" -SecurePassword (ConvertTo-SecureString $sourceSAS -AsPlainText -Force) -Force\r\n",
|
||||
"$sourceCred\r\n",
|
||||
"\r\n",
|
||||
"$targetSAS = (New-AzStorageAccountSASToken -Service Blob -ResourceType Object -Permission \"rw\" -Context $storageContext).TrimStart('?') # -ResourceType Container,Object\r\n",
|
||||
"$targetCred = New-DbaCredential -SqlInstance $targetConnection -Name \"https://$blobStorageAccount.blob.core.windows.net/$containerName\" -Identity \"SHARED ACCESS SIGNATURE\" -SecurePassword (ConvertTo-SecureString $targetSAS -AsPlainText -Force) -Force\r\n",
|
||||
"$targetCred\r\n",
|
||||
"\r\n",
|
||||
""
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "f7d53cb1-a55d-4634-95f7-d3e8cf9fab52",
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Start the Server Migration\r\n",
|
||||
"\r\n",
|
||||
"The follow code executes the migration of objects from the source SQL Server instance to the target SQL Server instance. There are a couple of options of interest:\r\n",
|
||||
"\r\n",
|
||||
"|Parameter|Description|\r\n",
|
||||
"|---|---|\r\n",
|
||||
"|Verbose|Include detailed logging information during the migration process|\r\n",
|
||||
"|WhatIf|Display what the migration process is going to do but do **not** actually perform the migration|\r\n",
|
||||
"\r\n",
|
||||
"The above parameters can be turned off by changing the $true value following the parameter to $false in the code cell below. "
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "518662fe-3ccf-4ead-80a7-3b890a394975"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"$migrationParams = @{\r\n",
|
||||
" Verbose = $true\r\n",
|
||||
" WhatIf = $true\r\n",
|
||||
" Source = $sourceConnection\r\n",
|
||||
" Destination = $targetConnection\r\n",
|
||||
" BackupRestore = $true\r\n",
|
||||
" SharedPath = \"https://$blobStorageAccount.blob.core.windows.net/$containerName\" \r\n",
|
||||
"}\r\n",
|
||||
"\r\n",
|
||||
"Start-DbaMigration @migrationParams"
|
||||
],
|
||||
"metadata": {
|
||||
"azdata_cell_guid": "b3a291f0-d9c4-438d-8b34-2c42a1a3b373",
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
# Offline Migration
|
||||
[Home](../readme.md)
|
||||
|
||||
This chapter contains a set of notebooks useful for doing offline migration of databases and SQL instances to Azure. For instance migration, these notebooks assume the Azure SQL Virtual Machine, Azure SQL Managed Instance, or Azure SQL DB Server have already been created.
|
||||
|
||||
## Notebooks in this Chapter
|
||||
- [Migrate Instance to Azure SQL VM](instance-to-VM.ipynb)
|
||||
|
||||
- [Migrate Database to Azure SQL VM](db-to-VM.ipynb)
|
||||
|
||||
- [Migrate Instance to Azure SQL MI](instance-to-MI.ipynb)
|
||||
|
||||
- [Migrate Database to Azure SQL MI](db-to-MI.ipynb)
|
||||
|
||||
- [Migrate Database to Azure SQL DB](db-to-SQLDB.ipynb)
|
||||
Reference in New Issue
Block a user