5

I have a Stateful Service with backup logic implemented according to the corresponding documentation

Just like so:

protected override async Task RunAsync(CancellationToken cancellationToken)
{
  // ...

  while (true)
  {
    cancellationToken.ThrowIfCancellationRequested();
    BackupDescription myBackupDescription = new BackupDescription(BackupOption.Full, this.BackupCallbackAsync);
    await this.BackupAsync(myBackupDescription);

    // ...

    await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
  }
}

private async Task<bool> BackupCallbackAsync(BackupInfo backupInfo, CancellationToken cancellationToken)
{
  var backupId = Guid.NewGuid();
  // backup files copied to external storage here ...
  return true;
}

Documentation suggests only one way to restore backups - with OnDataLossAsync method. But I cannot provoke an invocation of this mehtod.

So, the question is: how may I restore the service state from my backup in case of full data loss?

For example, all the service fabric cluster nodes have been destroyed. The only thing I have is my backup. What should I do after redeployment to restore my services' state?

I checked Data and Log directories of Service Fabric cluster manager, but data format seems to be different comparing to the backup.

Pavel S.
  • 1,267
  • 14
  • 19
  • Did you read the chapter 'Deleted or lost service'? https://msdn.microsoft.com/library/mt693569.aspx it seems to describe what you're after.. – LoekD Sep 12 '16 at 07:08
  • I did read about this method. As far as I can understand, it's intended for test purposes and should not be used in production environment: " It is not recommended to use FabricClient.ServiceManager.InvokeDataLossAsync on each partition to restore the entire service, since that may corrupt your cluster state." – Pavel S. Sep 12 '16 at 22:24
  • 2
    That's a different method from `FabricClient.TestManagementClient.StartPartitionDataLossAsync` (I do agree that it's unclear..) – LoekD Sep 13 '16 at 07:16
  • Probably it's the answer. Will try it. Thank you. – Pavel S. Sep 13 '16 at 13:57

1 Answers1

1

Dataloss can be triggered for a service with something like the following code:

Connect-ServiceFabricCluster
$s = "fabric:/WebReferenceApplication/InventoryService"
$p = Get-ServiceFabricApplication | Get-ServiceFabricService -ServiceName $s | Get-ServiceFabricPartition | Select -First 1
$p | Invoke-ServiceFabricPartitionDataLoss -DataLossMode FullDataLoss -ServiceName $s

There's an example that shows how backup and restore works in the web reference sample, and the specific code is here.

The full docs for backup and restore are here.

masnider
  • 2,609
  • 13
  • 20