Azure Data Services: See how to share a file using Azure File Storage (Part 6)


Hello and welcome to this tutorial series of Azure Data Services. Through the course of this tutorial, I will take you through what Azure has to offer in Data Services. I will start with the basics of relational databases, dig into the goodness of non-relational offerings and end with what is new and what is exciting in Azure Data Services

Part 1: An Introduction to Azure Data Services

Azure Data Services: SQL in the Cloud (Part 2)
Azure Data Services: Blobbing did you say.. What is that? (Part 3)
Azure Data Services: NoSQL Table Storage (Part 4)

Azure Data Services: Designing a communication strategy using Storage Queues (Part 5)

Till now we have covered a wide array of topics and offerings from Azure Data Services. Today we add one more to the list (amongst many more to come). Consider the following scenarios:

  • Lift and Shift: You have a lot of on-prem data and you want to move to the cloud. How would you make sure that all your data gets on the cloud and can be accessed from all the VMs consistently?
  • Shared Application: You have a shared application. Why not centralize your configuration files, such that the shared application across VMs can access the common, consistent configuration files.
  • Diagnostic Share: Similar to the previous situation, but think from the VM side. How about centralizing the storage of logs, diagnostic files from VMs on one shared location
  • Dev/Test/Debug: Centralize the common set of diagnostic/dev/test tools which can be accessed from all VMs through file share

Based on the description above, you would have guessed that Azure File Storage is essentially a centralized location which can be shared across VMs. It is an additional component of Azure Storage Accounts. as you can see in the diagram below, the hierarchy is as follows: a storage account can have one or more shares. A share can have directories and a directory can have one or more files. The URL of the file share can be accessed using .file.core.windows.net///https://<storage-account>.file.core.windows.net/<share>/<optional-directories>/<file>

image

Now that we understand the functionality, lets get started and see how it is done:

Prerequisites:

  • Sign up for Azure Services
  • Have a VM (or farm of VMs) created from where you want to access the shared data

Step 1: Create Storage Account in Azure

1. Login to Azure portal (portal.azure.com). New-> Everything-> Storage –> Create Storage Account (fill in the required details)

image 2. Make a note of the name and the primary access key:

image

 

Step 2: Create the File Share

1. Create the context for the storage account

   1: # create a context for account and key
   2: $ctx=New-AzureStorageContext <account name> <account key>

image

2. Create the new share

(Note: you will have to get your Storage Account activated with File Share before you can use File Share. This can be activated here )

   1: #Create a New Share
   2: $FS = New-AzureStorageShare sampleshare -Context $ctx

image

3. Create a directory in the share

   1: #Create a directory in the share that was created in the previous step
   2: New-AzureStorageDirectory -Share $FS -Path sampleshare

image

4. Now that the file share has been created, let us upload a file on the file share.

   1: #Uploading a file on the File Share
   2: Set-AzureStorageFileContent -Share $FS -Source C:\Users\addatta\Desktop\storage-concepts.png -Path sampleshare

image

Check and see if the file is uploaded successfully on the FileShare:

image

Step 3: Mount the File Share on the VM and access the file loaded:

1. Login to the VM. Let us first make sure that the File Share is a persistent drive on the VM. This is done by using the cmdkey command in the power shell of the VM.

   1: #Add the drive as a persistent drive across reboots
   2: PS C:\Users\adarsha> cmdkey /add:<Storage Account Name>.file.core.windows.net /user:<Storage Account Name> /pass:<Primary Access Key>

image

2. Use the ‘net use’ command to add the FileShare as a network drive.

   1: #Add the FileShare as a network drive
   2: PS C:\Users\adarsha> net use z: \\<storage account name>.file.core.windows.net\sampleshare /u:<storage account name> <primary access key>

image

3. That's it, now you can access the file share:

image

 

Summary

The above steps clearly show how easy it is to share a file across VMs by using Azure File Storage. This feature can be quite useful as shown in the above use cases. What we have shown above is one way of accessing the FileShare. You can also access FileShare programmatically using REST APIs. You can explore the Storage client Reference Library and File Service REST API. I will be talking about few more additional data services in this series, so stay tuned!


Comments (1)

  1. mika says:

    Hi

    Why I get error

    System error 64 has occurred.

    The specified network name is no longer available.

    After last Net use command?

Skip to main content