headerpic
« Hem

Periodic backup and restore in Service Fabric standalone (Preview)

Skrivet av: Andreas Andersson
April 30, 2018

In this blog I’m going to go through how to set up backup and restore for Service Fabric standalone (on premise) to a file share.

First we need to use the Service Fabric runtime version 6.2.262.9494. So first upgrade your cluster, to do that first we need to connect to the cluster. In this example I will be using Windows as ClusterCredentialType instead of a certificate but this will work either way.

 

Check the available versions:

Connect-ServiceFabricCluster -ConnectionEndpoint ‘localhost:19000’ -WindowsCredential

 

Check the available versions:

Get-ServiceFabricRuntimeSupportedVersion -Latest and note the version number.

 

Start the upgrade:

Start-ServiceFabricClusterUpgrade -Code -CodePackageVersion ‘Version’ -UnmonitoredAuto

 

Monitor your upgrade with Get-ServiceFabricClusterUpgrade It should say

UpgradeState: RollingForwardCompleted when done

 

After the cluster is upgraded to at least version 6.2 we need to change some things in the cluster configuration.

Open up your current cluster configuration if you have it saved (you should) or you can get it from the cluster itself by executing this command:

Get-ServiceFabricClusterConfiguration

 

Enabling Backup and Restore service

Open the cluster configuration in your favorite editing software and check that the apiversion is

10-2017, if not update it and also remember to update the clusterConfigurationVersion otherwise we can’t update the cluster configuration as it does not allow the same version as before.

It should look something like this:
{

“apiVersion”: “10-2017”,

“name”: “CLUSTERNAME”,

“clusterConfigurationVersion”: “1.0.0”,

}

We then need to add the backup and restore service and we do that by adding the addonFeatures from the snippet below.

“properties”: {

“addonFeatures”: [“BackupRestoreService”],

“fabricSettings”: [ … ]

}

If you plan or is using a X.509 certificate you also need to add the certificate thumbprint, you can see an example in this snippet.

“properties”: {

“addonFeatures”: [“BackupRestoreService”],

“fabricSettings”: [{

“name”: “BackupRestoreService”,

“parameters”:  [{

“name”: “SecretEncryptionCertThumbprint”,

“value”: “[Thumbprint]”

}]

}

}

 

When you have done this save the document and update your cluster configuration, connect to the cluster if you are not connected.

Connect-ServiceFabricCluster -ConnectionEndpoint ‘localhost:19000’ -WindowsCredential

After you make sure you are connected start the upgrade.

Start-ServiceFabricClusterConfigurationUpgrade -ClusterConfigPath ‘Path to config file’

 

Monitor the upgrade progress with this cmdlet:

Get-ServiceFabricClusterConfigurationUpgradeStatus it should say RollingForwardCompleted when done.

 

You can now check you cluster to see if the BackupRestoreService now is under system.

Http://localhost: 19080/Explorer/index.html

Create a backup policy

Now we need to create a backup policy for our application:

$ScheduleInfo = @{

Interval = ‘PT15M’

ScheduleKind = ‘FrequencyBased’

}

$StorageInfo = @{

Path = ‘ \\172.21.3.182\BackupRestoreService’

StorageKind = ‘FileShare’

}

$BackupPolicy = @{

Name = ‘GettingStartedApplication’

MaxIncrementalBackups = 20

Schedule = $ScheduleInfo

Storage = $StorageInfo

}

$body = (ConvertTo-Json $BackupPolicy)

$url = “http://localhost:19080/BackupRestore/BackupPolicies/$/Create?api-version=6.2-preview”

Invoke-WebRequest -Uri $url -Method Post -Body $body -ContentType ‘application/json’ -Credential (Get-Credential)

 

This policy will backup every 15 minutes for a maximum of 20 incremental backups.

In the invoke-WebReqeust I have -Credential (Get-Credential) since the cluster is using windows as a credential type but you can replace the -Credential (Get-Credential) with  -CertificateThumbprint ‘Thumbprint’.

 

Enable the backup policy

Now we need to enable the backup policy for our application and the application I’m using is called fabric:/GettingStartedApplication

So the name in the url we will be using is only GettingStartedApplication (we will be using the applicationname in the url from this point forward) and then use the name of the policy we created earlier.

$BackupPolicyReference = @{

BackupPolicyName = ‘GettingStartedApplication’

}

$body = (ConvertTo-Json $BackupPolicyReference)

$url = “http://localhost:19080/Applications/GettingStartedApplication/$/EnableBackup?api-version=6.2-preview”

Invoke-WebRequest -Uri $url -Method Post -Body $body -ContentType ‘application/json’ -Credential (Get-Credential) or use -CertificateThumbprint ‘Thumbprint’

The policy will now be triggered after 15 minutes and you should be able to see it in the file share we specified earlier:

List the backups

You can now list the backups with PowerShell.

$url = “http://localhost:19080/Applications/GettingStartedApplication/$/GetBackups?api-version=6.2-preview”

$response = Invoke-WebRequest -Uri $url -Method Get -Credential (Get-Credential)

or use -CertificateThumbprint ‘Thumbprint’

$BackupPoints = (ConvertFrom-Json $response.Content)

$BackupPoints.Items

Restore Partition

To restore a partition we need to get some information from the previous snippet when we listed the backups. What we need is BackupID and BackupLocation. In the BackupLocation we will see what service and what partition ID we can backup.

In my example I will use StatefulBackendService from the application GettingStartedApplication.

$StorageInfo = @{

Path = ‘\\172.21.3.182\BackupRestoreService’

StorageKind = ‘FileShare’

}

$BackupInfo = @{

BackupId = ‘f5367d0f-58f1-45d3-bf3b-b3cb7a7cfae8’

BackupLocation = ‘GettingStartedApplication\StatefulBackendService\fd9a836b-6218-44c6-b612-3d90fb484dc0\2018-04-27 13.42.42.zip’

BackupStorage = $StorageInfo

}

$body = (ConvertTo-Json $BackupInfo)

$url = “http://localhost:19080/Partitions/fd9a836b-6218-44c6-b612-3d90fb484dc0/$/Restore?api-version=6.2-preview”

Invoke-WebRequest -Uri $url -Method Post -Body $body -ContentType ‘application/json’ -Credential (Get-Credential)

or use -CertificateThumbprint ‘Thumbprint’

 

Monitor restore progress

To monitor the progress you can send a GET against the partition id we restored and get back Accepted, Succeeded or Failure.

$url = “http://localhost:19080/Partitions/fd9a836b-6218-44c6-b612-3d90fb484dc0/$/GetRestoreProgress?api-version=6.2-preview”

$response = Invoke-WebRequest -Uri $url -Method Get -Credential (Get-Credential)

or use -CertificateThumbprint ‘Thumbprint’

$RestoreProgress = (ConvertFrom-Json $response.Content)

$RestoreProgress.RestoreState

Postad i: Service Fabric |

Lämna en kommentar