Showing posts with label Azure. Show all posts
Showing posts with label Azure. Show all posts

Friday, November 22, 2019

How to copy files from Azure Fileshare to Azure Blob Containers

Hello Readers !

Below is a small useful blog content on how do we copy file copy files between Azure Blob containers and Azure fileshares using Azcopy.

For dummies, Azcopy is a command-line utility tool to work with Azure storage which you can download it from here. This is supposed to work faster than your azure storage explorer. You may do a comparison check yourself to confirm that. At present, Azure storage explorer, doesn't support copy-paste between two different services, lets say files and blobs.
One you download it , you can copy it into a windows folder and access it from your CMD.

For running AzCopy commands, in Command prompt you should navigate to the directory/folder which is holding your Azcopy.exe.

For example, I have kept it in C:\Azcopy . 
To run Azcopy commands, in command prompt I should get to the localion by running the below.

CD C:\Azcopy

Command to copy file from Azure fileshare to an Azure blob container.


Azcopy copy "<Azure FileshareURL>?<SAS key of storage account which hosts this azureFileshare>" "<AzureBlob Container/folder URL >?<SAS key of storage account hosting this blob container >"
 --recursive 

To get the URLs of your fileshare and blob containers, you can navigate to that in your Storage explorer or in Azure Portal and right click and get the "properties" which will have it.

Sample is given below.

Azcopy copy "https://mystorageac1.file.core.windows.net/backups/Prod?sv=2019-02-02&ss=bfqt&srt=sco&sp=rwdlacup&se=2020-11-21T17:32:48Z&st=2019-11-21T09:32:48Z&spr=https,http&sig=5CPP5XJ4c%2jjbhbhbhbhbhcBjlZGeoNWFFtXNJMoI%3D" "https://mystorageac2.blob.core.windows.net/stagingbackups?sv=2019-02-02&ss=bfqt&srt=sco&sp=rwdlacup&se=2020-11-21T17:32:48Z&st=2019-11-21T09:32:48Z&spr=https,http&sig=5CPP5XihbhbhbObb90ocBjlZGeoNWFFtXNJMoI%3D" --recursive 

You will experience a magical speed over 6 GB/Sec while copying files between two azure locations as the data transfer happens with in the azure network itself and with Azcopy you are only triggering the transfer. 

Needless to say, the same tool can be used to move files between your local folders and Azure file shares/blob containers. Only difference is that you don't have to add a '?' sign, followed by the key to get access. Also make sure you give enough permissions when you are generating the SAS keys in your Azcopy commands. 

Hope that helps. Please write down your related questions  below in the comments section. I will get back to you at the earliest.



Saturday, October 26, 2019

Adding your Managed Instance Subnet in your storage Account's Network and Firewall settings

Hello Readers!

The below blog content is to highlight an azure limitation and a workaround to fix that till Azure came up with a direct solution for it. Its about enabling access for managed instance in the network and firewall settings of a storage account , if you are choosing the 'Public- Selected Networks ' configuration.

If you have noticed, when we add a particular VNet/Subnet to the settings, it will first enable service end points onto the subnet we are adding as the first step. This is not really possible for the dedicated subnet we create and maintain for Azure managed instances . As per design or existing configurations, managed instances' subnet can not have service end point enabled.

So how do we enable it?

There is a workaround for this limitation. 

We can find the managed endpoint IP address for the managed instances and whitelist that. It will be accepted in the network and firewall settings of the storage account , just like how we add a public IP to it. But the important part is having both your storage account and Managed instance in different Regions.

Below is how you do it.


Step1 : Finding the managed endpoint IP
Connect to Cloudshell (Powershell client embedded in the azure portal) or your own PowerShell client.

If you are logging in from your own Powershell client, make sure you have Az module installed by running the below commands and you are logged into your subscription.

Install-Module -Name Az #Installing Az module

connect-Azaccount #Logging into Azure subscription

resolve-dnsname 'xxxxx-mi1.xxxxx.database.windows.net' | select -first 1  | %{ resolve-dnsname $_.NameHost.Replace(".vnet","")}  #Finding the managed endpoint IP of your managed instance.

Please replace "xxxxx-mi1.xxxxx.database.windows.net" in the above script with the private endpoint URL of your managed instance which you get from the "Connection strings" of your managed instance in the Azure portal.

Managed endpoint address is common for all the instances in your MI subnet. 

Step2: Adding the IP into the firewall settings of the storage account.

This was covered in the bottom of my previous blog on storage account . Access it from here. 

May be in future, microsoft will come with a better solution which would support enabling service end point in MI Subnet. Let us all keep checking azure updates page 

Thats the end of this blog. Please follow if you are finding my blogs knowledgeable. If you do , you will receive notifications when I post something new here. Thanks for reading and Connecting ! 

Friday, October 25, 2019

Performing a Point In Time Restore of your Azure Managed instance database using Azure portal and Powershell

Hello Readers!


Welcome to my new blog on performing a point-in-time restore of a database in an azure managed instance. In this small blog, I will be documenting the  steps and screens for restoring a database in a managed instance using Azure Portal.

If you have not read about my blog on managed instance automated backups, please read it here.

Restoring automated backup with Azure portal

Step 1 : Navigate to your database in azure managed instance in the portal

Search for SQL managed Instance in the portal, Select the managed instance which has the database you are trying to restore. We would get to see the list of databases hosted in the instances, clicking on any of those can launch the database page in the Azure portal.

Click on restore in this page.



Step 2: Supplying the restore point details

In the popup that appear, you can mention the target database name . It has to be different from the database of which the backup was taken. If you keep the same name, the restore will fail with the error 'Database with the same name already exists on this Managed Instance.'

In the Restore point section against the data and time, you can choose a restore point which is within the short term retention plan period set for the instance. For directions, the portal also shows the earliest (most recent) restore point below.



 In this window , again we would not get to change the Target Server. (MI). You can see the lock symbol against it .

Once you have made the choice click on Ok, which will initiate the restoration activity to the same instance.

You can track the progress through the below T-SQL statement in SSMS

Select percent_complete from sys.dm_exec_requests where session_id=<Spid of the session you get from sp_who2 active>


Using Powershell

Both the Azure modules AZ and AzureRM has commands for Database restoration.

If you dont have them installed in your Powershell client, you can also use the 'Cloud shell', which is the powershell client you will get to see in the Azure portal itself. Cloud shell basically uses the latest powershell Module, which is Az. 

You can launch them using the button highlighted in the below snapshot.



Az Module powershell Script Sample 

Restore-AzSqlinstanceDatabase -Name "DBA" -InstanceName "<yourMIname>" -ResourceGroupName "<ResourceGroupName>" -PointInTime “2019-07-29T08:51:39.3882806Z” -TargetInstanceDatabaseName "DBA_PSrestored"

If you are new to powershell and trying to execute the above powershell script, follow the below steps before you attempt this.

1.Run your powershell client as Administrator
2.Install Az module by running    the below
Install-Module -Name Az
3. Login to your azure account with the below command
Connect-AzAccount


Thanks for reading ! Please comment below for any query you have related to this topic.

I will write my next blog on Geo-restore !