The goals of this lab is to get you familiar with the Azure environment, portal and command line. Everything you can do in the Azure Portal can also be done through a command line and scripting. We will expose you to both methods of creating resources in Azure. In this lab you will:
- Experience Creating a Virtual Machine
- Use the Azure Cloud Shell to create resources
- Migrate a Linux Mongo DB to Azure Cosmos DB
- Migrate a SQL Server 2017 DB to Azure SQL Database
You will need a few things in your environment setup for this lab.
-
A SQL Server VM that will act as our on-premise SQL instance that we will migrate to Azure SQL DB
- You will create this as part of the lab exercise
-
An Azure SQL Database Instance. This is the SQL PaaS service you will migrate the on-premise server to.
- You will create this as part of the lab
-
A Mongo DB that you will migrate data from to Cosmos DB
- A public Mongo DB will be made available to you to access remotely.
-
An Azure Cosmos DB instance
- You will create this as part of the lab
-
The Microsoft Data Migration Assistant
- You will install this as part of the SQL VM creation
-
An Azure Database Migration Service
- You will create this as part of the setup
In many cases you need to create a resource that has a unique name. The easiest way to do this is to create a prefix that you can append to the front of the standard resource names. As an exmple, Bill Smith needs a unique prefix so he decided to use his name and the first three digits of his phone number. So, his prefix is 'BS336'. Any resources that need to be unique he can now put this in front of the standard name and it should be unique.
One thing to consider is that some resources have a limit to how many characters are in a name. So, keeping your prefix to under 6 characters. Come up with a prefix you can use for all the labs.
IMPORTANT: Whenever you see (prefix) in the labs, replace that with the prefix you come up with.
-
Login to the Azure Portal http://portal.azure.com
-
Press the create new resource button in the upper left toolbar
-
Type 'SQL Server in the search box' - Press Enter
-
Pick 'SQL Server 2017 on Windows Server 2016'
-
Press Create
-
Set the following Basic Parameters
- Resource Group: Use the Resource Group you were assigned
- VM Name: '(prefix)OnPremSQL'
- Region: Use the default region if it is in the US. If not, change to any US region.
- Change Size to: D2 v3
- Username: 'migrateadmin'
- Password: 'AzureMigrateTraining2019#'
- Inbound Port Rules
- Allows Selected Ports
- RDP
-
Press the 'SQL Server settings' on the top toolbar
- SQL Connectivity: Pubilc
- SQL Authentication: Enable
-
Press 'Review and Create'
- If you get a validation failed, press 'previous' then 'Review and Create' again. This should clear the error.
-
Press Create
Your SQL VM is now provisioning. It will take a few minutes to provision, so we will provision some other resources while that is going on.
In this exercise we will create an instance of the Azure Database Migration Service. This service allows you to automate the migration of data from on premise environments to Azure.
- In the Azure Portal click the add new resource button
- Type 'Azure Database Migration' in the search bar
- Select the 'Azure Database Migration Service'
- Press 'Create'
- Enter Parameters
- Service Name: '(prefix)MigrationService'
- Resource Group: Your assigned Resource Group
- Location: Use the default region if it is in the US. If not, change to any US region.
- Virtual Network -> -vnet/default
- Pricing Tier: Standard 1v core
- Press Create
The Database Migration Service is now being deployed to your resource group. While this is provisioning we will continue to the next resources we will need.
Up until now we have used the Azure Web Portal to create needed resources in our environment. In this exercise we will show how to create a new Azure Cosmos DB account using the Azure Command Line Interface (CLI) and the Cloud Shell.
The Azure Cloud Shell is a shell environment that runs right in your browser. It will spin up compute in the back end for you and create a storage account. You can run either a PowerShell or Bash environment. For these excerizes we will use Bash
Follow these steps:
- Open up the Azure portal
- Click on the
>_
button in the toolbar - Pick Bash on the Welcome Screen
- Press Show advanced settings
- Create a new storage account and file share in your resource group. Use your (prefix) in the names.
- Click Create Storage
- Wait for the shell to start.
- Make sure you are in
bash
from the dropdown of the Cloud Shell window. - First off create 3 Bash variables by typing the following in the shell and press enter:
- Resource Group Name - Make sure to set this to YOUR resource group 1 name.
- Region to host the Azure Cosmos DB instance
- The account name - This MUST be unique. Create a prefix that would be unique to your. Possibly your initials and a few digits.
RESOURCE_GROUP_COSMOS='<Your resoruce group name>'
LOCATION_COSMOS='<use same region as you have for other resources>'
ACCOUNT_NAME_COSMOS='(prefix)migrationcosmos'
- Copy the below command and execute it (you can paste in command window with a right click). This will create the Azure Cosmos DB Account and place it into the resource group you just created.
az cosmosdb create --resource-group $RESOURCE_GROUP_COSMOS --name $ACCOUNT_NAME_COSMOS --kind MongoDB --locations regionName=$LOCATION_COSMOS
This will take several minutes to spin up. When it is finished (you'll see a bunch of JSON indicating it's done) you can go into the portal and click on Resource Groups
from the left hand side. Click on your resource group and look for your Cosmos DB account.
While you wait for your Cosmos DB instance to spin up you can move on to the creation of the SQL Instance.
We will now create a PaaS instance of SQL server to migrate our on-premises database to.
-
Click the create resource button in the Azure portal
-
Type 'SQL Database' in the search box and press enter
-
Select SQL Database
-
Press Create
-
Basics
- Resource Group: Set to your assigned resource group
- Database Name: (prefix)SQLDB
- Server - Create New
- Server Name: (prefix)sqlserver
- Server Admin: 'migrateadmin'
- Password: 'AzureMigrateTraining2019#'
- Location: -- Use the same region as the other resources created --
- Check - Allow Azure services to access server
- Press 'Review and Create'
- Press 'Create'
The inventory service is hosted on a SQL server and served by an ASP.NET core website. The Inventory service determines the quantity of a unit that's currently in stock. In this lab we will migrate the on premises SQL Server to an instance of SQL Azure DB.
We will be using the Database Migration Tool
By now the SQL Server VM you created should be finished provisioning. We need to do a couple of extra steps to get it ready to migrate.
-
On the left hand side of the Azure portal click on the resource group icon
-
Click on your Resource Group
- You should now see all the resources we created in the exercises above
-
Click on your SQL On Prem Virtual Machine you created
-
Click on Connect->download the RDP file and open that to RDP to the VM, login with the migrateadmin user we created in Setup 1.
-
Update IE Security - The local server manager should launch on first login.
-
Download and restore the database. The inventory database is stored in the repository as a SQL .bacpac file needs to be restored.
- Download the TailwindInventory.bacpac backup file from the setupfiles folder in the Student Files area in Teams.
- Click the Windows start menu and type 'SQL Server Management'
- Launch the SQL Server Management Studio and connect to the local SQL instance.
- Right click on the Database folder and select 'Import Data-tier Application'
-
Follow the wizard to import the backup file you downloaded.
-
When complete - Right click on the database folder and select 'refresh'
-
You should now see the TailwindInventory DB installed.
-
Open IE and either search for 'Microsoft Database Migration Assistant' or download from:
-
Install the Data Migration Assistant
We are now all set to migrate our SQL Database. We have a restored copy of the data on this local server and we have the migration assistant ready to help us migrate the data to an Azure SQL Instance.
First we need to do an assessment. The tool will check the local db for compatibility issues.
- Open the Data Migration Assistant from the desktop icon
- Create a new project
- Project Type:
Assessment
- Project Name:
tailwind
- Source server type:
SQL server
- Target server type:
Azure SQL Database
- Click
Create
- Check
Check database compatibility
- Check
Check feature parity
- Click
Next
- Enter the 'localhost' for server name and Windows authentication
- UN-Check the Encrypt Connection Box
- Select the
TailwindInventory
database, clickAdd
- Click
Start Assessment
- You will see a report on compatibility issues. There should only be one for this DB because Service Broker is turned on. In a real situation you would mitigate the issues. For this lab we do not have to worry about as we know service broker is not actually used. In your real situation you would now have a list of possible incompatibilities that would have to be addressed.
Now that we know our database can be migrated we will use the Migration tool to migrate JUST the schema information. We will use the more robust Azure Database Migration Service for the data.
- In the Data Migration Assistant create a new project
- Project Type:
Migration
- Project Name:
tailwind
- Source server type:
SQL server
- Target server type:
Azure SQL Database
- Migration Scope:
Schema Only
- Click
Create
- Source Server: localhost
- Authentication type: Windows
- UN-Check the Encrypt Connection box
- Click Connect
- Select the
TailwindInventory
database, clickNext
- Target Server: This will be the Azure SQL Server Instance we created.
- In the Azure Portal click on the resource group icon and select your resource group.
- Find the SQL Server Instance you created. It will be resource type of SQL Server
- Copy the server name on the right hand side of the overview page
- Paste that full name into the target server name of the wizard
- Choose SQL Server Authentication
- User: migrateadmin
- Password: 'AzureMigrateTraining2019#'
- Press Connect
- Choose your database and press next
- Select all tables and press 'Generate SQL script'
- Once the script is generated, you may review it
- Press 'Deploy Schema'
- You now have your schema successfully migrated to Azure SQL DB.
Now that we have the schema migrated, we now need to move the data. We will use the Azure Data Migration Service for this as it is much more robust option and can migrate the data with very minimal downtime.
- In the Azure Portal click on the resource group icon and select your resource group.
- Find the resource of type 'Azure Database Migration Service' and click it.
- Click on
Create new migration project
- Project name:
tailwind
- Source server type:
SQL Server
- Target server type:
Azure SQL Database
- Type of activity:
Offline data migration
- Click
Create and run activity
- Source Detail
- Source SQL Server Instance Name: The IP Address of your SQL Server VM(you can open the portal in a new tab, click on your VM and get the IP )
- Authentication type:
SQL Authentication
- User: migrateadmin
- Password: 'AzureMigrateTraining2019#'
- Uncheck the encrypt connection box
- Select Target
- Full name of the Azure SQL instance
- Authentication type: `SQL Authentication'
- User: migrateadmin
- Password: 'AzureMigrateTraining2019#'
- Click save
- Select
TailwindInventory
database from the source - Select your database as the Target Database -> Save
- Select all tables and click Save.
- Give a name to the migration activity and select "Don't Validate the Database" in the database validation options.
- Run the migration
Congratulations! You have successfully migrated from the VM instance of SQL to Azure SQL DB! You can check to see the data is there by using the portal based query tool.
By default Azure SQL Databases reject all traffic to them. We were able to run the Azure Database Migration tool because we checked the box to allow other Azure services to connect to it. I in order to connect to it via other tools we need to open an exception for our IP address through the firewall.
- Click on your resource group
- Click on your Azure SQL Server Instance
- Click on Firewalls and virtual networks in the left hand pane
- You will see your client IP address listed. You need to create a new rule allowing that IP like this
- Press Save
- Click on your resource group
- Click on your Azure SQL DB database
- Click Query Editor on the left toolbar
- Login as migrateadmin
- Expand tables - you should see all your tables.
- Run - 'select * from inventory' and you should see all your inventory data.
The next step is to get the product database migrated to Azure. Here we are moving an on-premises MongoDB (as represented in this session by an Azure Linux VM running MongoDB) to Azure Cosmos DB using native MongoDB commands.
We have a shared Linux VM that is simulating the production MongoDB product database. We will connect remotely to this server in order to get a dump of data to put into the Cosmos DB. The great thing about this is that Cosmos DB can use standard MongoDB tools.
We can do all this from the Azure Bash Shell
-
Launch a new Azure Command Shell. You can either:
- Press the shell icon in the Azure Portal, as in the setup for the Cosmos DB
- Open a new browser tab to: http://shell.azure.com for a full screen experience
-
Download the MongoDB client tools (you can paste into the shell with a right click)
wget https://repo.mongodb.org/apt/ubuntu/dists/xenial/mongodb-org/4.0/multiverse/binary-amd64/mongodb-org-tools_4.0.11_amd64.deb
-
Unpack the downloaded zip file
dpkg-deb -R mongodb-org-tools_4.0.11_amd64.deb ~/mongotools
-
Set the path to include the tools
export PATH=$PATH:~/mongotools/usr/bin
-
You now have the MongoDB client tools available to you.
-
Dump the data from the remote MongoDB with the following Command
-
mongodump --host 40.70.205.251 --username=labuser --password=AzureMigrateTraining2019# --db=tailwind --authenticationDatabase=tailwind
-
-
Check to see that you successfully dumped the data
Now that we have a copy of the data locally, we can use the mongorestore command to load that data into our Cosmos DB instance we created.
First check to make sure the Cosmos DB instance was created successfully.
- In the Azure portal click on the resource groups on the left toolbar
- Click on your Resource Group.
- You should see a resource of type 'Azure Cosmos DB account' - Click that
- Click on 'Data Explorer' on the left navigation. You should see something the following:
- Notice the collections is empty. This is OK. It shows we have a Cosmos Instance and after we restore we should have our product data
-
We will create a few environment variables to store Cosmos DB information for our restore command.
-
You will need the Cosmos DB username and password.
- Navigate to the Cosmos DB account in the Azure portal.
- Click on the Connection String option on the left navigation
- The username and password for you Cosmos DB instance can be copied from here.
-
Go back to the Azure shell
-
Create the following environment variables in that shell
COSMOS_DB_NAME=<Host name from connection string properties> COSMOS_USER=<username from connection string properties> COSMOS_PWD=<primary password from connection string properties>
-
Make sure you are still in the /dump/tailwind directory still
-
Copy and paste this command to run a mongo restore:
mongorestore \
--host $COSMOS_DB_NAME:10255 \
-u $COSMOS_USER \
-p $COSMOS_PWD \
--ssl \
--sslAllowInvalidCertificates \
inventory.bson \
--db tailwind \
--collection inventory
- Go into your Azure Cosmos DB account and click on
Data Explorer
. - Press the refresh button next to Collections if you don't see the tailwind collection
- Select the
tailwind
database. - Expand the
tailwind
node, expand theinventory
node, and selectDocuments
- You should see the inventory item documents are now in Cosmos DB
Congratulations! You have now successfully moved both a SQL Server Database and a Mongo DB database to the Azure cloud!