This makes me laugh, because a couple of weeks ago a customer asked me if there was a way to understand the money consumption in azure while working from the management portal, and here we are:
If you ever worked with Windows Azure, you’ve probably stumbled in the bad practice to let the control panel create the storage for you, with an unreadable and forgettable name, and with the worst thing you can do, leaving the storage outside an affinity group, that guarantee low latency between services and storage that should communicate each other.
It is possible with the Windows Azure PowerShell module to copy a storage blob across storage accounts and regions… asynchronously!
For example, you would need to move a virtual machine disk between storage account:
Import-Module Azure Select-AzureSubscription "My Subscription Name" $destContext = New-AzureStorageContext –StorageAccountName "MyStorageAccountName" -StorageAccountKey "MyStorageAccountKey" $blob = Start-AzureStorageBlobCopy -SrcContainer vhds -SrcBlob "xxxx.vhd" -DestContainer vhds -DestBlob "xxxx.vhd" -DestContext $destContext
Then to check the status of the copying, you can execute this command:
$blob | Get-AzureStorageBlobCopyState
To start using Windows Azure PowerShell, you need to run just a couple of commands.
First import the windows azure powershell module:
Retrieve all your subscriptions (certificate method, you should prefer to use the Azure AD method instead, see below):
A browser window opens at https://windows.azure.com/download/publishprofile.aspx, where you can sign in to Windows Azure and download the publish settings file.
Then import the subscription publish settings file:
You should delete the publishing profile that you downloaded after you import those settings. The downloaded profile contains a management certificate that should not be accessed by unauthorized users.
There’s a new way to login azure on powershell, without using the certificate method:
Use the Azure AD method (newest and preferred way)
- Open the Azure PowerShell console, as instructed in How to: Install Azure PowerShell.
- Type the following command:
- In the window, type the email address and password associated with your account.
- Azure authenticates and saves the credential information, and then closes the window.
Now you can make a lot of operations against the azure fabric (a lot more than you can do from the web portal), like getting the list of containers and the the list of the blobs of a container.
First you select the subscription you want to use:
Select-AzureSubscription -SubscriptionName "My Subscription Name"
Then you set the storage account you want to query on:
Set-AzureSubscription -SubscriptionName "My Subscription Name" -CurrentStorageAccount "mystorageaccount"
(to get the storage account name, you can run Get-AzureStorageAccount)
And now you can get the list of the containers:
and the list of the blobs of a specified container:
Get-AzureStorageBlob -Container "containername"
The Windows Azure Managed Library provides classes for accessing the local storage resource from within code that is running in a role instance.
You will just need to retrieve the full path of a named local storage, and then you can store any file you want. To retrieve the full path, you simple need this line of code:
On a cloud service, you can create a small local storage where you can save temporary files, yes I said temporary, because a local storage would not be guaranteed to be durable, for durable storage in Azure you should consider Azure SQL Database or Azure Storage (blob and tables). This reserved space could be useful to store custom error log files (nlog, log4net, …), for those files that are dynamically created by the application and you would like to cache it somewhere, and also for structured data files like database(sql ce, sqlite, …), but remember, just for volatile data.
You can create a local storage manually configuring the Service Definition configuration file, or through the visual studio user interface:
Open the Properties of the Web Role under the Cloud Service Project, go to Local Storage section, and click on “Add Local Storage”, name the storage, give a size, and save.
For more information about Local Storage Resources visit http://msdn.microsoft.com/en-us/library/windowsazure/ee758708.aspx
To understand whether the role instance is running in the Windows Azure compute emulator, you simply need to check this static variable:
Assembly: Microsoft.WindowsAzure.ServiceRuntime (in Microsoft.WindowsAzure.ServiceRuntime.dll)