Putting files into Azure blob storage using AzCopy
One of my last blog posts was about copying data into Azure blob storage (specifically local SQL Server backups) and it turns ou that there's a command line app available that wraps up copying files to and from Azure bob storage, AzCopy. The "meat" of the code I wrote, that's responsible for copying the backup file up to Azure is:
$storageAccount = "<STORAGE_ACCOUNT_NAME>"; $storageKey = "<STORAGE_ACCOUNT_KEY>"; $storageContainer = "orchard"; <# Authenticate against Azure storage and then write the file to it#> $storageContext = New-AzureStorageContext -StorageAccountName $storageAccount -StorageAccountKey $storageKey Set-AzureStorageBlobContent -Container $storageContainer -Blob $backupFileName -File $backupFileNameAndPath -Context $storageContext -Force
With AzCopy, this can be distilled down to a single line:
AzCopy /Source:C:\myfolder /Dest:https://<STORAGE_ACCOUNT_NAME>.blob.core.windows.net/<CONTAINER_NAME>/DestKey:<STORAGE_ACCOUNT_KEY> /Pattern:"<FILENAME>"
One big advantage here is that the parameter that takes the filename is a pattern, so with one command you can specify "*.bak" and upload all the files with that extension to Azure at once, rather than having to write code to loop over them.
My skillset has matured somewhat since then, which you'll probably see from the posts here. You can read a bit more about me on the about page of the site, or check out some of the other posts on my areas of interest.