copying blobs and table data from one storage account to another

Recently I needed to get a production copy of our blobs and tables to run locally to do some testing, and I tried several ways to achieve this but the the easiest way by far is using AZCopy.

Requirments:

  1. Install Azcopy
  2. Get the script
  3. Get your storage account names and access keys. Use them to update the script
  4. (Set-executionpolicy)
  5. run script
  6. Time…

First you need to install azcopy. Download latest version here

Then head over to this github page and get the script.

Login to the azure portal and locate your storage account(s). Once the blade for your storage account is open go to Access Keys. On this blade we want to copy the storage account name and its access key

storage acount details

Once you have the account names and keys open the script in your favourite editor and replace the storage account names and keys, the scripts assumes that there is a dev, staging and prod environment but feel free to tweak this to suit your needs.

 if ($environment.ToUpperInvariant() -eq "DEV") {
     $Return.Key="ACCOUNT KEY GOES HERE"
     $Return.Context=New-AzureStorageContext –StorageAccountName "yourdev" -StorageAccountKey $Return.Key        
 }   
 elseif ($environment.ToUpperInvariant() -eq "STAGING") {
     $Return.Key="ACCOUNT KEY GOES HERE"
     $Return.Context=New-AzureStorageContext –StorageAccountName "yourstaging" -StorageAccountKey $Return.Key      
 }     
 elseif ($environment.ToUpperInvariant() -eq "PROD") {
     $Return.Key="ACCOUNT KEY GOES HERE"
     $Return.Context= New-AzureStorageContext –StorageAccountName "yourprod" -StorageAccountKey $Return.Key        
 }     

Before you run the script you may have to set your execution policy to run the script, details can be found here

> set-executionpolicy -executionpolicy unrestricted

Now you can execute the script. I prefer to use powershell ISE as I can set breakpoint in the script.

or execute the script like this > powershell.exe -executionpolicy unrestricted -command copyazurestorage-v1.ps1

copying blobs and tables is a rather slow process if you have thousands of records in your containers and tables so you need to be patient.


The End

Pin It on Pinterest

Share This

Share This

Share this post with your friends!