daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Sep 25th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.WindowsAzure.StorageClient;
  6. using System.IO;
  7. using System.Net;
  8.  
  9. namespace benjguinAzureStorageTool
  10. {
  11.     class Program
  12.     {
  13.         private static Context context = new Context();
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             try
  18.             {
  19.                 string usage = string.Format("Possible Usages:n"
  20.                 + "benjguinAzureStorageTool CopyContainer account1SourceContainer account2SourceContainer account1Name account1Key account2Name account2Keyn"
  21.                 );
  22.  
  23.  
  24.                 if (args.Length < 1)
  25.                     throw new ApplicationException(usage);
  26.  
  27.                 int p = 1;
  28.  
  29.                 switch (args[0])
  30.                 {
  31.                     case "CopyContainer":
  32.                         if (args.Length != 7) throw new ApplicationException(usage);
  33.                         context.Storage1Container = args[p++];
  34.                         context.Storage2Container = args[p++];
  35.                         context.Storage1Name = args[p++];
  36.                         context.Storage1Key = args[p++];
  37.                         context.Storage2Name = args[p++];
  38.                         context.Storage2Key = args[p++];
  39.  
  40.                         CopyContainer();
  41.                         break;
  42.  
  43.  
  44.                     default:
  45.                         throw new ApplicationException(usage);
  46.                 }
  47.  
  48.                 Console.BackgroundColor = ConsoleColor.Black;
  49.                 Console.ForegroundColor = ConsoleColor.Yellow;
  50.                 Console.WriteLine("OK");
  51.                 Console.ResetColor();
  52.             }
  53.             catch (Exception ex)
  54.             {
  55.                 Console.WriteLine();
  56.                 Console.BackgroundColor = ConsoleColor.Black;
  57.                 Console.ForegroundColor = ConsoleColor.Yellow;
  58.                 Console.WriteLine("Exception: {0}", ex.Message);
  59.                 Console.ResetColor();
  60.                 Console.WriteLine("Details: {0}", ex);
  61.             }
  62.         }
  63.  
  64.  
  65.         private static void CopyContainer()
  66.         {
  67.             CloudBlobContainer container1Reference = context.CloudBlobClient1.GetContainerReference(context.Storage1Container);
  68.             CloudBlobContainer container2Reference = context.CloudBlobClient2.GetContainerReference(context.Storage2Container);
  69.             if (container2Reference.CreateIfNotExist())
  70.             {
  71.                 Console.WriteLine("Created destination container {0}. Permissions will also be copied.", context.Storage2Container);
  72.                 container2Reference.SetPermissions(container1Reference.GetPermissions());
  73.             }
  74.             else
  75.             {
  76.                 Console.WriteLine("destination container {0} already exists. Permissions won't be changed.", context.Storage2Container);
  77.             }
  78.  
  79.  
  80.             foreach (var b in container1Reference.ListBlobs(
  81.                 new BlobRequestOptions(context.DefaultBlobRequestOptions)
  82.                 { UseFlatBlobListing = true, BlobListingDetails = BlobListingDetails.All }))
  83.             {
  84.                 var sourceBlobReference = context.CloudBlobClient1.GetBlobReference(b.Uri.AbsoluteUri);
  85.                 var targetBlobReference = container2Reference.GetBlobReference(sourceBlobReference.Name);
  86.  
  87.                 Console.WriteLine("Copying {0}n ton{1}",
  88.                     sourceBlobReference.Uri.AbsoluteUri,
  89.                     targetBlobReference.Uri.AbsoluteUri);
  90.  
  91.                 using (Stream targetStream = targetBlobReference.OpenWrite(context.DefaultBlobRequestOptions))
  92.                 {
  93.                     sourceBlobReference.DownloadToStream(targetStream, context.DefaultBlobRequestOptions);
  94.                 }
  95.             }
  96.         }
  97.     }
  98. }
  99.    
  100. AzCopy /Source:https://myaccount.blob.core.windows.net/mycontainer1 /Dest:https://myaccount.blob.core.windows.net/mycontainer2 /SourceKey:key /DestKey:key /Pattern:abc.txt
  101.    
  102. AzCopy /Source:https://sourceaccount.blob.core.windows.net/mycontainer1 /Dest:https://destaccount.blob.core.windows.net/mycontainer2 /SourceKey:key1 /DestKey:key2 /Pattern:abc.txt
  103.    
  104. 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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top