
The most frequently asked question to me is ‘How to restore (and create) a backup from a flow to restore earlier versions?’
Unfortunately, there is no simple standard solution, but I will show you some possibilities how to avoid this problem in the future. My inspiration for this Solution was Audrie Gordon and Pieter Veenstra. The code for the flows (copy & paste) is at the end of this article.
- How do I restore an earlier version of my flow (Power Automate) from John Liu
The first and easiest solution is the one I presented in this blogpost. It is not free, but it does exactly what we want it to do. - Backup and restore using solution and power automate ⑴
For this, we create a ‘backup’ solution where we add the specific flow (we could also backup multiple flows over it at the same time). It is important to say that the dataverse actions are NOT premium, and you can use them.
It is possible to have one flow in multiple solutions. This is what we use here. Significant to know is that in the end it is only one flow that is linked multiple times. i.e. if we change or restore it, it is changed in all locations.
In this solution, I have the flow saved with the solution as a ZIP-file on the OneDrive for business, but of course any location is possible.
Backup:
– Build your flow like above
– SolutionName = Name-Column in the solution (no spaces)
– File Content =
base64ToBinary(outputs(‘Perform_an_unbound_action’)?[‘body/ExportSolutionFile’])
Restore:
– Choose file on your data storage (here OneDrive for Business)
– take the file content “$content” to the CustomizationFile - Backup and restore using just power automate ⑵
Even if this solution looks the most complicated at first sight, I prefer this variant. Here we can either use a child flow or copy this directly into our flow.
I would only use this in the development/customization phase so that a backup is created at the end of a successful flow run. This way we always have a backup of the last successful flow.
In this solution, I have the flow saved as a JSON-file on the OneDrive for business, but of course any location is possible.
Backup:
Restore:
⑴ Backup Solution
{"id":"d6ad0518-4a44-45dd-8c0e-08125d42e8d5","brandColor":"#8C3900","connectionReferences":{"shared_commondataserviceforapps":{"connection":{"id":"/crce7_sharedcommondataserviceforapps_6ab0c"}},"shared_onedriveforbusiness":{"connection":{"id":"/new_sharedonedriveforbusiness_58eca"}}},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"Restore_Solution_from_Backup","operationDefinition":{"type":"Scope","actions":{"Restore_Solution":{"type":"Scope","actions":{"Create_file":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"CreateFile","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"folderPath":"/Backup PowerAutomate","name":"@{outputs('Internal_Name_Solution')}_@{utcNow()}.zip","body":"@base64ToBinary(outputs('Perform_an_unbound_action')?['body/ExportSolutionFile'])"},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{"Perform_an_unbound_action":["Succeeded"]},"runtimeConfiguration":{"contentTransfer":{"transferMode":"Chunked"}},"metadata":{"operationMetadataId":"00315691-0b73-4f68-bee9-23c81d12826d"}},"Perform_an_unbound_action":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_commondataserviceforapps","operationId":"PerformUnboundAction","apiId":"/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps"},"parameters":{"actionName":"ExportSolution","item/SolutionName":"@outputs('Internal_Name_Solution')","item/Managed":false,"item/ExportAutoNumberingSettings":false,"item/ExportCalendarSettings":false,"item/ExportCustomizationSettings":false,"item/ExportEmailTrackingSettings":false,"item/ExportGeneralSettings":false,"item/ExportMarketingSettings":false,"item/ExportOutlookSynchronizationSettings":false,"item/ExportRelationshipRoles":false,"item/ExportIsvConfig":false,"item/ExportSales":false,"item/ExportExternalApplications":false},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{},"metadata":{"operationMetadataId":"edad8a33-5ab0-4c3d-a680-50a83e69b75c"}}},"runAfter":{},"metadata":{"operationMetadataId":"c90a84c1-5f8f-47e6-85f4-6623ced4d4a5"}}},"runAfter":{"Internal_Name_Solution":["Succeeded"]},"metadata":{"operationMetadataId":"6c0733ea-b6b6-4001-a26c-ed0db7210b7c"}}}
⑴ Restore Solution
{"id":"964018a8-e7ef-492a-bfa9-2e7cce95b021","brandColor":"#8C3900","connectionReferences":{"shared_commondataserviceforapps":{"connection":{"id":"/crce7_sharedcommondataserviceforapps_6ab0c"}},"shared_onedriveforbusiness":{"connection":{"id":"/new_sharedonedriveforbusiness_58eca"}}},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"Restore_Solution_from_Backup","operationDefinition":{"type":"Scope","actions":{"Variable":{"type":"Scope","actions":{"Get_file_content":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"GetFileContent","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"id":"b!QXDMTJQWzUmH3MxDXM6y2k-CtYhPjl5HilY3d7yppydZpLeqflXvQ48pC25vRXdt.01CIDL2ECPUIU3O3JADJGLR2SXFASROBGM","inferContentType":true},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{},"metadata":{"b!QXDMTJQWzUmH3MxDXM6y2k-CtYhPjl5HilY3d7yppydZpLeqflXvQ48pC25vRXdt.01CIDL2EE4FZKSV3QPS5GYUFKFJOPVQ5AV":"/Backup PowerAutomate/BackUpFlows_2022-08-25T06_21_29.3169365Z.zip","operationMetadataId":"09bf45eb-aeac-4f1d-9377-070b3b12c08c","b!QXDMTJQWzUmH3MxDXM6y2k-CtYhPjl5HilY3d7yppydZpLeqflXvQ48pC25vRXdt.01CIDL2ECPUIU3O3JADJGLR2SXFASROBGM":"/Backup PowerAutomate/BackUpFlows_2022-08-25T08_03_00.9379160Z.zip"}}},"runAfter":{},"metadata":{"operationMetadataId":"8d687a2b-1291-4c58-95e6-fdf620002d9c"}},"Restore_Solution":{"type":"Scope","actions":{"Perform_an_unbound_action_2":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_commondataserviceforapps","operationId":"PerformUnboundAction","apiId":"/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps"},"parameters":{"actionName":"ImportSolution","item/OverwriteUnmanagedCustomizations":false,"item/PublishWorkflows":false,"item/CustomizationFile":"@body('Get_file_content')?['$content']","item/ImportJobId":"@guid()","item/ConvertToManaged":false,"item/SkipProductUpdateDependencies":false,"item/HoldingSolution":false,"item/SkipQueueRibbonJob":false,"item/AsyncRibbonProcessing":false,"item/IsTemplateMode":false},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{},"metadata":{"operationMetadataId":"f2828b0f-4f92-4760-92bc-afee9c2b2c24"}}},"runAfter":{"Variable":["Succeeded"]},"metadata":{"operationMetadataId":"c90a84c1-5f8f-47e6-85f4-6623ced4d4a5"}}},"runAfter":{},"metadata":{"operationMetadataId":"6c0733ea-b6b6-4001-a26c-ed0db7210b7c"}}}
⑵ Backup Flow
{"id":"2bd5f6d6-9716-41a7-be39-2997816c8d16","brandColor":"#8C3900","connectionReferences":{"shared_flowmanagement_1":{"connection":{"id":"/new_sharedflowmanagement_78283"}},"shared_onedriveforbusiness_1":{"connection":{"id":"/new_sharedonedriveforbusiness_58eca"}}},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"Export_Flow_to_OneDrive","operationDefinition":{"type":"Scope","actions":{"Variable":{"type":"Compose","inputs":{"FlowID":"@{triggerBody()['text']}","EnvironmentID":"@{triggerBody()['text_1']}"},"runAfter":{},"metadata":{"operationMetadataId":"bad376d5-dcd4-4d8d-84a5-a844b2609e42"}},"Export_Flow":{"type":"Scope","actions":{"Create_file":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness_1","operationId":"CreateFile","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"folderPath":"/Backup PowerAutomate","name":"@{outputs('Get_Flow')?['body/properties/displayName']}_@{utcNow()}.json","body":"@outputs('Get_Flow')?['body/properties/definition']"},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{"Get_Flow":["Succeeded"]},"runtimeConfiguration":{"contentTransfer":{"transferMode":"Chunked"}},"metadata":{"operationMetadataId":"7ff3d5a1-7d47-4c43-a070-339fa0a8d843"}},"Get_Flow":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_flowmanagement_1","operationId":"GetFlow","apiId":"/providers/Microsoft.PowerApps/apis/shared_flowmanagement"},"parameters":{"environmentName":"@outputs('Variable')?['EnvironmentID']","flowName":"@outputs('Variable')?['FlowID']"},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{},"metadata":{"operationMetadataId":"a77f80ac-0fbd-43b0-963b-61ce4147c4e7"}}},"runAfter":{"Variable":["Succeeded"]},"metadata":{"operationMetadataId":"09062054-0acf-44ec-9062-42c3f4941dae"}},"Respond_to_a_PowerApp_or_flow":{"type":"Response","kind":"PowerApp","inputs":{"statusCode":200,"body":{},"schema":{"type":"object","properties":{}}},"runAfter":{"Export_Flow":["Succeeded"]},"metadata":{"operationMetadataId":"39dc65eb-e56d-4705-98fc-7c4848c84250"}}},"runAfter":{},"metadata":{"operationMetadataId":"490611db-6ad2-42a9-8a94-907af94b8b02"}}}
⑵ Restore Flow
{"id":"e79a25a8-388d-4000-9393-75002528e62a","brandColor":"#8C3900","connectionReferences":{"shared_flowmanagement":{"connection":{"id":"/new_sharedflowmanagement_78283"}},"shared_onedriveforbusiness":{"connection":{"id":"/new_sharedonedriveforbusiness_58eca"}}},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"Restore_a_Flow","operationDefinition":{"type":"Scope","actions":{"Initial":{"type":"Scope","actions":{"Variable":{"type":"Compose","inputs":{"EnvironmentID":"@{triggerBody()['text']}","UpdateFlowID":"@{triggerBody()['text_1']}","UpdateFlowName":"@{triggerBody()['text_2']}"},"runAfter":{},"metadata":{"operationMetadataId":"c0607e6e-d7c1-488e-ac2e-1d12c4231ef2"}},"Get_file_content":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_onedriveforbusiness","operationId":"GetFileContentByPath","apiId":"/providers/Microsoft.PowerApps/apis/shared_onedriveforbusiness"},"parameters":{"path":"@triggerBody()['text_3']","inferContentType":true},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{"Variable":["Succeeded"]},"metadata":{"operationMetadataId":"9c52e3cf-14c7-418f-afd7-3d280de3cd27"}}},"runAfter":{},"metadata":{"operationMetadataId":"b9a56542-73f6-479b-98a2-135a3780610d"}},"Restore":{"type":"Scope","actions":{"Update_Flow_2":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_flowmanagement","operationId":"UpdateFlow","apiId":"/providers/Microsoft.PowerApps/apis/shared_flowmanagement"},"parameters":{"environmentName":"@outputs('Variable')?['EnvironmentID']","flowName":"@outputs('Variable')?['UpdateFlowID']","Flow/properties/displayName":"@outputs('Variable')?['UpdateFlowName']","Flow/properties/definition":"@json(base64ToString(base64(outputs('Get_file_content')?['body'])))","Flow/properties/state":"Started"},"authentication":{"type":"Raw","value":"@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"}},"runAfter":{},"metadata":{"operationMetadataId":"d2b0566a-39b9-4018-ad11-40f99a8d20e5"}}},"runAfter":{"Initial":["Succeeded"]},"metadata":{"operationMetadataId":"dc698232-d1b6-4dcc-9ef1-a7b1bf16190e"}},"Respond_to_a_PowerApp_or_flow":{"type":"Response","kind":"PowerApp","inputs":{"statusCode":200,"body":{},"schema":{"type":"object","properties":{}}},"runAfter":{"Restore":["Succeeded"]},"metadata":{"operationMetadataId":"a602c08b-2fb1-433f-9d7a-5dbb209633f2"}}},"runAfter":{},"metadata":{"operationMetadataId":"513126e8-94f3-4648-9c46-74d4373a773a"}}}
Leave a Reply