Created
March 16, 2016 14:20
-
-
Save markusjohnsson/08fd4c049b59b4be6861 to your computer and use it in GitHub Desktop.
Backup (download) all blobs in a Azure blob storage container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.WindowsAzure.Storage; | |
using Microsoft.WindowsAzure.Storage.Blob; | |
using System; | |
using System.Linq; | |
using System.IO; | |
namespace DownloadAllBlobs | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var blobConectionString = "<connectionstring>"; | |
CloudStorageAccount backupStorageAccount = CloudStorageAccount.Parse(blobConectionString); | |
var containerName = "<my container name>"; | |
var backupBlobClient = backupStorageAccount.CreateCloudBlobClient(); | |
var backupContainer = backupBlobClient.GetContainerReference(containerName); | |
var basedir = @"C:\backup\" + containerName; | |
foreach (var blob in backupContainer.ListBlobs(useFlatBlobListing: true).OfType<CloudBlockBlob>()) | |
{ | |
var dir = Path.Combine(basedir, Path.GetDirectoryName(blob.Name)); | |
Directory.CreateDirectory(dir); | |
blob.DownloadToFile(Path.Combine(basedir, blob.Name), FileMode.Create); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment