Azure Service Fabric 中的按需备份On-demand backup in Azure Service Fabric

可将可靠有状态服务和 Reliable Actors 的数据进行备份,以解决灾难或数据丢失的情况。You can back up data of Reliable Stateful services and Reliable Actors to address disaster or data loss scenarios.

Azure Service Fabric 提供定期备份数据和按需备份数据的功能。Azure Service Fabric has features for the periodic backup of data and the backup of data on a need basis. 按需备份很有用,因为它可防止由于在基础服务或其环境中的计划更改而导致的数据丢失/数据损坏。 On-demand backup is useful because it guards against data loss/data corruption because of planned changes in the underlying service or its environment.

在手动触发服务或服务环境操作之前,按需备份功能有助于捕获服务的状态。The on-demand backup features are helpful for capturing the state of the services before you manually trigger a service or service environment operation. 例如,如果你在升级或降级服务时对服务二进制文件做出了更改。For example, if you make a change in service binaries when upgrading or downgrading the service. 在这种情况下,按需备份可以帮助防止应用程序代码 bug 导致数据损坏。In such a case, on-demand backup can help guard the data against corruption by application code bugs.

先决条件Prerequisites

  • 安装 Microsoft.ServiceFabric.Powershell.Http模块 [在预览中] 进行配置调用。Install Microsoft.ServiceFabric.Powershell.Http Module [In Preview] for making configuration calls.
    Install-Module -Name Microsoft.ServiceFabric.Powershell.Http -AllowPrerelease
  • 请确保在使用 Microsoft.ServiceFabric.Powershell.Http 模块发出任何配置请求之前,先使用 Connect-SFCluster 命令连接群集。Make sure that Cluster is connected using the Connect-SFCluster command before making any configuration request using Microsoft.ServiceFabric.Powershell.Http Module.

    Connect-SFCluster -ConnectionEndpoint 'https://mysfcluster.chinaeast.cloudapp.chinacloudapi.cn:19080'   -X509Credential -FindType FindByThumbprint -FindValue '1b7ebe2174649c45474a4819dafae956712c31d3' -StoreLocation 'CurrentUser' -StoreName 'My' -ServerCertThumbprint '1b7ebe2174649c45474a4819dafae956712c31d3'  

触发按需备份Triggering on-demand backup

按需备份要求提供存储详细信息用于上传备份文件。On-demand backup requires storage details for uploading backup files. 可在定期备份策略或按需备份请求中指定按需备份位置。You specify the on-demand backup location, either in the periodic backup policy or in an on-demand backup request.

按需备份到定期备份策略指定的存储On-demand backup to storage specified by a periodic backup policy

可将定期备份策略配置为使用可靠有状态服务或 Reliable Actor 的某个分区,以便在存储中创建额外的按需备份。You can configure the periodic backup policy to use a partition of a Reliable Stateful service or Reliable Actor for extra on-demand backup to storage.

以下用例是为可靠有状态服务和 Reliable Actors 启用定期备份中的方案的延续。The following case is the continuation of the scenario in Enabling periodic backup for Reliable Stateful service and Reliable Actors. 在本例中,你启用了一个备份策略,以使用某个分区,并按设置的频率在 Azure 存储中创建备份。In this case, you enable a backup policy to use a partition and a backup occurs at a set frequency in Azure Storage.

使用Microsoft.ServiceFabric.Powershell.Http 模块的 PowerShellPowershell using Microsoft.ServiceFabric.Powershell.Http Module


Backup-SFPartition -PartitionId '974bd92a-b395-4631-8a7f-53bd4ae9cf22' 

使用 Powershell 进行 Rest 调用Rest Call using Powershell

使用 BackupPartition API 为分区 ID 974bd92a-b395-4631-8a7f-53bd4ae9cf22 的按需备份设置触发。Use the BackupPartition API to set up triggering for the on-demand backup for partition ID 974bd92a-b395-4631-8a7f-53bd4ae9cf22.

$url = "https://mysfcluster.chinaeast.cloudapp.chinacloudapi.cn:19080/Partitions/974bd92a-b395-4631-8a7f-53bd4ae9cf22/$/Backup?api-version=6.4"

Invoke-WebRequest -Uri $url -Method Post -ContentType 'application/json' -CertificateThumbprint '1b7ebe2174649c45474a4819dafae956712c31d3'

使用 GetBackupProgress API 启用按需备份进度跟踪。Use the GetBackupProgress API to enable tracking for the on-demand backup progress.

指定存储的按需备份On-demand backup to specified storage

可以请求可靠有状态服务或 Reliable Actor 的分区的按需备份。You can request on-demand backup for a partition of a Reliable Stateful service or Reliable Actor. 请在按需备份请求中提供存储信息。Provide the storage information as a part of the on-demand backup request.

使用Microsoft.ServiceFabric.Powershell.Http 模块的 PowerShellPowershell using Microsoft.ServiceFabric.Powershell.Http Module


Backup-SFPartition -PartitionId '974bd92a-b395-4631-8a7f-53bd4ae9cf22' -AzureBlobStore -ConnectionString  'DefaultEndpointsProtocol=https;AccountName=<account-name>;AccountKey=<account-key>;EndpointSuffix=core.chinacloudapi.cn' -ContainerName 'backup-container'

使用 Powershell 进行 Rest 调用Rest Call using Powershell

使用 BackupPartition API 为分区 ID 974bd92a-b395-4631-8a7f-53bd4ae9cf22 的按需备份设置触发。Use the BackupPartition API to set up triggering for the on-demand backup for partition ID 974bd92a-b395-4631-8a7f-53bd4ae9cf22. 包括以下 Azure 存储信息:Include the following Azure Storage information:

$StorageInfo = @{
    ConnectionString = 'DefaultEndpointsProtocol=https;AccountName=<account-name>;AccountKey=<account-key>;EndpointSuffix=core.chinacloudapi.cn'
    ContainerName = 'backup-container'
    StorageKind = 'AzureBlobStore'
}

$OnDemandBackupRequest = @{
    BackupStorage = $StorageInfo
}

$body = (ConvertTo-Json $OnDemandBackupRequest)
$url = "https://mysfcluster.chinaeast.cloudapp.chinacloudapi.cn:19080/Partitions/974bd92a-b395-4631-8a7f-53bd4ae9cf22/$/Backup?api-version=6.4"

Invoke-WebRequest -Uri $url -Method Post -Body $body -ContentType 'application/json' -CertificateThumbprint '1b7ebe2174649c45474a4819dafae956712c31d3'

可以使用 GetBackupProgress API 设置按需备份进度跟踪。You can use the GetBackupProgress API to set up tracking for the on-demand backup progress.

使用 Service Fabric ExplorerUsing Service Fabric Explorer

请确保已在 Service Fabric Explorer 设置中启用了“高级模式”。Make sure Advanced Mode has been enabled in Service Fabric Explorer settings.

  1. 选择所需分区,并单击“操作”。Select the desired partitions and click on Actions.

  2. 选择“触发分区备份”,并填写用于 Azure 的信息:Select Trigger Partition Backup, and fill in information for Azure:

    触发分区备份

    或用于文件共享的信息:or FileShare:

    触发分区备份文件共享

跟踪按需备份进度Tracking on-demand backup progress

可靠有状态服务或 Reliable Actor 的分区一次仅接受一个按需备份请求。A partition of a Reliable Stateful service or Reliable Actor accepts only one on-demand backup request at a time. 仅当已完成当前的按需备份请求后,才能接受另一个请求。Another request can be accepted only after the current on-demand backup request has completed.

不同的分区可以同时触发按需备份请求。Different partitions can trigger on-demand backup requests at a same time.

使用Microsoft.ServiceFabric.Powershell.Http 模块的 PowerShellPowershell using Microsoft.ServiceFabric.Powershell.Http Module


Get-SFPartitionBackupProgress -PartitionId '974bd92a-b395-4631-8a7f-53bd4ae9cf22'

使用 Powershell 进行 Rest 调用Rest Call using Powershell

$url = "https://mysfcluster-backup.chinaeast.cloudapp.chinacloudapi.cn:19080/Partitions/974bd92a-b395-4631-8a7f-53bd4ae9cf22/$/GetBackupProgress?api-version=6.4"

$response = Invoke-WebRequest -Uri $url -Method Get -CertificateThumbprint '1b7ebe2174649c45474a4819dafae956712c31d3' 
$backupResponse = (ConvertFrom-Json $response.Content) 
$backupResponse

按需备份请求可处于以下状态:On-demand backup requests can be in the following states:

  • Accepted:备份已针对分区启动,且正在进行。Accepted: The backup has started on the partition and is in progress.
    BackupState             : Accepted
    TimeStampUtc            : 0001-01-01T00:00:00Z
    BackupId                : 00000000-0000-0000-0000-000000000000
    BackupLocation          :
    EpochOfLastBackupRecord :
    LsnOfLastBackupRecord   : 0
    FailureError            :
    
  • SuccessFailureTimeout:请求的按需备份可能是在以下任一状态下完成的:Success, Failure, or Timeout: A requested on-demand backup can be completed in any of the following states:
    • 成功Success 备份状态表示已成功完成备份状态。Success: A Success backup state indicates that the partition state has backed up successfully. 响应将提供分区的 BackupEpochBackupLSN 以及 UTC 格式的时间。The response provides BackupEpoch and BackupLSN for the partition along with the time in UTC.
      BackupState             : Success
      TimeStampUtc            : 2018-11-21T20:00:01Z
      BackupId                : 5d64b697-6acd-45a4-adbd-3d75e0078081
      BackupLocation          : SampleApp\MyStatefulService\974bd92a-b395-4631-8a7f-53bd4ae9cf22\2018-11-21 20.00.01.zip
      EpochOfLastBackupRecord : @{DataLossNumber=131873018908156893; ConfigurationNumber=8589934592}
      LsnOfLastBackupRecord   : 36
      FailureError            :
      
    • 失败Failure 备份状态表示在备份分区状态期间发生失败。Failure: A Failure backup state indicates that a failure occurred during backup of the partition's state. 响应中会指明失败的原因。The cause of the failure is stated in response.
      BackupState             : Failure
      TimeStampUtc            : 0001-01-01T00:00:00Z
      BackupId                : 00000000-0000-0000-0000-000000000000
      BackupLocation          :
      EpochOfLastBackupRecord :
      LsnOfLastBackupRecord   : 0
      FailureError            : @{Code=FABRIC_E_BACKUPCOPIER_UNEXPECTED_ERROR; Message=An error occurred during this operation.  Please check the trace logs for more details.}
      
    • TimeoutTimeout 备份状态表示在给定的时间内无法创建分区状态备份。Timeout: A Timeout backup state indicates that the partition state backup couldn't be created in a given amount of time. 默认超时值为 10 分钟。The default timeout value is 10 minutes. 如果发生这种情况,请使用更大的 BackupTimeout 发起新的按需备份请求。Initiate a new on-demand backup request with greater BackupTimeout in this scenario.
      BackupState             : Timeout
      TimeStampUtc            : 0001-01-01T00:00:00Z
      BackupId                : 00000000-0000-0000-0000-000000000000
      BackupLocation          :
      EpochOfLastBackupRecord :
      LsnOfLastBackupRecord   : 0
      FailureError            : @{Code=FABRIC_E_TIMEOUT; Message=The request of backup has timed out.}
      

后续步骤Next steps