Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.WindowsAzure.StorageClient;
- using System.IO;
- using System.Net;
- namespace benjguinAzureStorageTool
- {
- class Program
- {
- private static Context context = new Context();
- static void Main(string[] args)
- {
- try
- {
- string usage = string.Format("Possible Usages:n"
- + "benjguinAzureStorageTool CopyContainer account1SourceContainer account2SourceContainer account1Name account1Key account2Name account2Keyn"
- );
- if (args.Length < 1)
- throw new ApplicationException(usage);
- int p = 1;
- switch (args[0])
- {
- case "CopyContainer":
- if (args.Length != 7) throw new ApplicationException(usage);
- context.Storage1Container = args[p++];
- context.Storage2Container = args[p++];
- context.Storage1Name = args[p++];
- context.Storage1Key = args[p++];
- context.Storage2Name = args[p++];
- context.Storage2Key = args[p++];
- CopyContainer();
- break;
- default:
- throw new ApplicationException(usage);
- }
- Console.BackgroundColor = ConsoleColor.Black;
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine("OK");
- Console.ResetColor();
- }
- catch (Exception ex)
- {
- Console.WriteLine();
- Console.BackgroundColor = ConsoleColor.Black;
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine("Exception: {0}", ex.Message);
- Console.ResetColor();
- Console.WriteLine("Details: {0}", ex);
- }
- }
- private static void CopyContainer()
- {
- CloudBlobContainer container1Reference = context.CloudBlobClient1.GetContainerReference(context.Storage1Container);
- CloudBlobContainer container2Reference = context.CloudBlobClient2.GetContainerReference(context.Storage2Container);
- if (container2Reference.CreateIfNotExist())
- {
- Console.WriteLine("Created destination container {0}. Permissions will also be copied.", context.Storage2Container);
- container2Reference.SetPermissions(container1Reference.GetPermissions());
- }
- else
- {
- Console.WriteLine("destination container {0} already exists. Permissions won't be changed.", context.Storage2Container);
- }
- foreach (var b in container1Reference.ListBlobs(
- new BlobRequestOptions(context.DefaultBlobRequestOptions)
- { UseFlatBlobListing = true, BlobListingDetails = BlobListingDetails.All }))
- {
- var sourceBlobReference = context.CloudBlobClient1.GetBlobReference(b.Uri.AbsoluteUri);
- var targetBlobReference = container2Reference.GetBlobReference(sourceBlobReference.Name);
- Console.WriteLine("Copying {0}n ton{1}",
- sourceBlobReference.Uri.AbsoluteUri,
- targetBlobReference.Uri.AbsoluteUri);
- using (Stream targetStream = targetBlobReference.OpenWrite(context.DefaultBlobRequestOptions))
- {
- sourceBlobReference.DownloadToStream(targetStream, context.DefaultBlobRequestOptions);
- }
- }
- }
- }
- }
- AzCopy /Source:https://myaccount.blob.core.windows.net/mycontainer1 /Dest:https://myaccount.blob.core.windows.net/mycontainer2 /SourceKey:key /DestKey:key /Pattern:abc.txt
- AzCopy /Source:https://sourceaccount.blob.core.windows.net/mycontainer1 /Dest:https://destaccount.blob.core.windows.net/mycontainer2 /SourceKey:key1 /DestKey:key2 /Pattern:abc.txt
- AzCopy /Source:https://myaccount1-secondary.blob.core.windows.net/mynewcontainer1 /Dest:https://myaccount2.blob.core.windows.net/mynewcontainer2 /SourceKey:key1 /DestKey:key2 /Pattern:abc.txt
Add Comment
Please, Sign In to add comment