Skip to content

Instantly share code, notes, and snippets.

@esell
Created December 19, 2017 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esell/bb755f75e12c21378ec2d9a4d66892cb to your computer and use it in GitHub Desktop.
Save esell/bb755f75e12c21378ec2d9a4d66892cb to your computer and use it in GitHub Desktop.
#r "Microsoft.WindowsAzure.Storage"
using System;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Blob.Protocol;
using Microsoft.WindowsAzure.Storage.Auth;
using System.IO;
using System.Threading.Tasks;
public static void Run(TimerInfo myTimer, ICollector<BlobBackup> outputTable, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
// Source blob stuff
string blobName = "testSQL-data1.vhd";
log.Info(GetEnvironmentVariable("sourceStorageconnectionstring"));
CloudStorageAccount sourceStorageAccount = new CloudStorageAccount(new StorageCredentials("stgAcctName", "stgAcctKey"), true);
log.Info($"creating blob client");
CloudBlobClient sourceCloudBlobClient = sourceStorageAccount.CreateCloudBlobClient();
log.Info($"creating blob container");
CloudBlobContainer sourceContainer = sourceCloudBlobClient.GetContainerReference("vhds");
log.Info($"creating block blob");
CloudPageBlob sourceBlob = (CloudPageBlob)sourceContainer.GetBlobReferenceFromServer(blobName);
// Destination blob stuff
CloudStorageAccount destStorageAccount = new CloudStorageAccount(new StorageCredentials("dstStgAcctName", "dstStgAcctKey"), true);
log.Info($"creating blob client2");
CloudBlobClient destCloudBlobClient = destStorageAccount.CreateCloudBlobClient();
log.Info($"creating blob container2");
CloudBlobContainer destContainer = destCloudBlobClient.GetContainerReference("sqlcopy");
destContainer.CreateIfNotExists();
log.Info($"creating block blob2");
//CloudPageBlob destBlob = (CloudPageBlob)destContainer.GetBlobReferenceFromServer(blobName);
CloudPageBlob destBlob = (CloudPageBlob)destContainer.GetPageBlobReference(blobName);
// Copy blob
destBlob.StartCopy(sourceBlob);
log.Info($"Adding BlobBackup entity");
outputTable.Add(
new BlobBackup() {
PartitionKey = "Test",
// set to date + blobname
RowKey = blobName,
Name = "Name" + blobName }
);
log.Info($"C# Timer trigger function completed at: {DateTime.Now}");
}
public static string GetEnvironmentVariable(string name)
{
return name + ": " +
System.Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);
}
public class BlobBackup
{
public string PartitionKey { get; set; }
public string RowKey { get; set; }
public string Name { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment