【问题标题】:Azure storage account backup (tables and blobs)Azure 存储帐户备份(表和 Blob)
【发布时间】:2014-07-25 02:55:53
【问题描述】:

我需要定期备份 Azure 存储帐户中的所有 Blob 和表,以便我们在以后由于任何原因损坏数据时可以恢复所有数据。

虽然我相信我们存储在 Azure 中的数据是持久的并且可以在数据中心出现故障时恢复,但我们仍然需要备份存储帐户中的数据,以防止意外覆盖和删除(人为错误因素)。

我们为此实施了一个解决方案,它会定期列出所有 blob 并将它们复制到备份存储帐户。当 blob 被修改或删除时,我们只需在备份帐户中创建旧版本的快照。

这种方法对我们来说效果很好。但它只处理 blob,而不是表实体。我们现在也需要支持备份表实体。

现在面对这个任务,我想其他人可能以前也有过这个要求,并想出了一个聪明的解决方案。或者也许有商业产品可以做到这一点?

备份目标不需要是另一个 Azure 存储帐户。我们所需要的只是一种方法来恢复我们运行备份时的所有 blob 和表。

感谢任何帮助!

【问题讨论】:

    标签: azure backup azure-storage


    【解决方案1】:

    有多种方法可以处理此问题。

    如果您想自己执行此操作,您可以使用存储库并编写代码来运行表并提取数据。

    还有一些服务也可以为您做到这一点(完全披露:我为一家提供此服务的公司工作)。这是 Troy Hunt 的一篇文章,谈论我们的选择:http://www.troyhunt.com/2014/01/azure-will-save-you-from-unexpected_28.html。我们还有 PowerShell Cmdlet 可以为您提取表数据 (cerebrata.com)。公平地说,我们并不是这个领域的唯一参与者,还有其他人提供类似的服务。

    最后,在 Tech Ed 上,他们宣布 AZCopy 工具将在今年晚些时候更新,以便它可以拉下整个表格,这只是自动读取表格并将其拉下。目前无法“快照”表,因此上述所有方法都会在复制数据时生成副本,在复制完成时源表中的数据可能已更改。

    【讨论】:

    • 谢谢!不幸的是,我们的数据位于北欧数据中心,因此您的服务会产生过多的出口带宽成本。你能给我指点其他玩家吗?
    • Blue Syntax 与 Enzo Backup 有类似的服务,我相信 Elastacloud 也有。同样,您也可以使用 Cerebrata PowerShell cmdlet(也来自我的公司)自动执行此操作。
    • 另一种可能性是 Red Gate 的云服务,它是一种付费选项,但您可以将其自动化,并且即使对该书店也有很大的灵活性 ;-) cloudservices.red-gate.com/Home/Features ,正如 Mike 提到的那样 bluesyntax 有一个好的解决方案,也可以使用 azure stack 中的一些自动化工具(例如 Azure 自动化或 webjobs,但那些暗示编码)
    • @MikeWo:这些 cmdlet 看起来很有前途!您是否有机会或计划添加对增量备份的支持?
    • 已经讨论过,但目前还没有开始开发。
    【解决方案2】:

    我最近整理了一个用于备份表存储的简单解决方案。它使用 AzCopy 工具和 Storage Rest Api 来下拉所有表的列表并备份到 JSON。

    希望有用!

    param(
    [parameter(Mandatory=$true)]
    [string]$Account,
    [parameter(Mandatory=$true)]
    [string]$SASToken,
    [parameter(Mandatory=$true)]
    [string]$OutputDir
    )
    $ErrorActionPreference = "Stop"
    
    ##Example Usage
    #.\Backup-TableStorage.ps1 -OutputDir "d:\tablebackup" -Account "examplestorageaccount" -SASToken "?sv=2015-04-05&ss=t&srt=sco&sp=rl&st=2016-04-08T07%3A44%3A00Z&se=2016-04-09T07%3A55%3A00Z&sig=CNotAREALSIGNITUREBUTYOURESWOUDLGOHERE3D"
    
    if (-not (Test-Path "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\AzCopy\AzCopy.exe"))
    {
        throw "Azcopy not installed - get it from here: https://azure.microsoft.com/en-gb/documentation/articles/storage-use-azcopy/"
    }
    
    Write-host ""
    Write-Host "Starting backup for account" -ForegroundColor Yellow 
    Write-host "--------------------------" -ForegroundColor Yellow
    Write-Host " -Account: $Account"
    Write-Host " -Token: $SASToken"
    
    $response = Invoke-WebRequest -Uri "https://$Account.table.core.windows.net/Tables/$SASToken"
    [xml]$tables = $response.Content
    $tableNames = $tables.feed.entry.content.properties.TableName
    
    Write-host ""
    Write-host "Found Tables to backup" -ForegroundColor Yellow
    Write-host "--------------------------" -ForegroundColor Yellow
    foreach ($tableName in $tableNames)
    {
        Write-Host " -Table: $tableName"
    }
    
    
    foreach ($tableName in $tableNames)
    {
        $url = "https://$Account.table.core.windows.net/$tableName"
    
        Write-host ""
        Write-Host "Backing up Table: $url"-ForegroundColor Yellow
        Write-host "--------------------------" -ForegroundColor Yellow
        Write-host ""
    
        & "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\AzCopy\AzCopy.exe" /Source:$url /Dest:$OutputDir\$account\ /SourceSAS:$SASToken /Z:"$env:temp\$([guid]::NewGuid()).azcopyJournal"   
    
        Write-host ""
        Write-host "Backup completed" -ForegroundColor Green
        Write-host ""
        Write-host ""
    
    }
    

    有关使用的更多详细信息,请查看此处:

    https://gripdev.wordpress.com/2016/04/08/backup-azure-table-storage-quick-powershell-script/

    【讨论】:

      【解决方案3】:

      您可以使用 Slazure Light 等免费软件备份任何 Azure 表存储表(但不是 blob)。以下 C# 代码将所有 Azure 表备份到 json 文件:

      先下载 NuGet 包:

      安装包 Azure.Storage.Slazure.Light

      在 Visual Studio 中创建一个控制台应用程序并添加以下代码:

      using System;
      using System.Linq;
      using Microsoft.WindowsAzure.Storage.Table;
      using Newtonsoft.Json;
      using SysSurge.Slazure.AzureTableStorage;
      
      namespace BackupAzureTableStore
      {
          class Program
          {
              /// <summary>
              /// Usage: BackupAzureTableStore.exe "UseDevelopmentStorage=true"
              /// </summary>
              /// <param name="args"></param>
              static void Main(string[] args)
              {
                  var storage = new DynStorage(args.Length == 0 ? "UseDevelopmentStorage=true" : args[0]);
      
                  foreach (var cloudTable in storage.Tables)
                  {
                      var tableName = cloudTable.Name;
                      var fileName = $"{tableName}.json";
      
                      using (var file = new System.IO.StreamWriter(fileName))
                      {
                          var dynTable = new DynTable(storage.StorageAccount, tableName);
      
                          TableContinuationToken token = null; // Continuation token required if > 1,000 rows per table
                          do
                          {
                              var queryResult =
                                  dynTable.TableClient.GetTableReference(tableName)
                                      .ExecuteQuerySegmented(new TableQuery(), token);
                              file.WriteLine("{{{0} : [", JsonConvert.SerializeObject(tableName));
                              var cntr = 0;
                              foreach (var entity in queryResult.Results)
                              {
                                  var dynEntity = dynTable.Entity(entity.PartitionKey, entity.RowKey);
                                  dynEntity.LoadAll().ToList(); // Force pre-downloading of all properties
      
                                  file.WriteLine("{0}{1}", cntr++ > 0 ? "," : string.Empty,
                                      JsonConvert.SerializeObject(dynEntity));
                              }
      
                              file.WriteLine("]}");
      
                              token = queryResult.ContinuationToken;
                          } while (token != null);
                      }
      
                  }
      
                  Console.WriteLine("Done. Press a key...");
                  Console.ReadKey();
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-10-22
        • 2021-06-10
        • 2023-03-07
        • 2016-12-10
        • 2017-04-11
        • 2013-06-30
        • 2022-11-11
        • 2015-01-08
        相关资源
        最近更新 更多