Skip to content

Instantly share code, notes, and snippets.

@chgeuer
Created August 30, 2012 08:12
Show Gist options
  • Save chgeuer/3524038 to your computer and use it in GitHub Desktop.
Save chgeuer/3524038 to your computer and use it in GitHub Desktop.
Simple backup skript for uploading to Azure
# Given as free as possible: MS-PL
$accountname = "azureaccountname";
$accountkey = [System.IO.File]::ReadAllText(".\accountkey.txt");
$backupcontainername = "backup";
$dllpath = [System.IO.Path]::Combine([System.Environment]::CurrentDirectory, "Microsoft.WindowsAzure.StorageClient.dll")
$loadresult = [Reflection.Assembly]::LoadFile($dllpath);
$creds = New-Object -TypeName Microsoft.WindowsAzure.StorageCredentialsAccountAndKey -ArgumentList ( $accountname, $accountkey );
$useHttps = $true;
$account = New-Object -TypeName Microsoft.WindowsAzure.CloudStorageAccount -ArgumentList ( $creds, $useHttps );
$client = [Microsoft.WindowsAzure.StorageClient.CloudStorageAccountStorageClientExtensions]::CreateCloudBlobClient($account);
$backupcontainer = $client.GetContainerReference($backupcontainername);
$backupcontainercreationresult = $backupcontainer.CreateIfNotExist();
$filename = "foo.zip";
$backupblob = $backupcontainer.GetBlobReference($filename);
Write-Host Start upload to $backupblob.Uri.AbsoluteUri;
$backupblob.UploadFile($filename);
Write-Host Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment