Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore Reliable Service state from existing backup?

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.

like image 820
Pavel S. Avatar asked Nov 09 '22 09:11

Pavel S.


1 Answers

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.

like image 81
masnider Avatar answered Nov 14 '22 21:11

masnider