“It’s great to have a backup, but what about building another Power Automate flow that’ll restore the flow from this backup?”
Last week I wrote an article on creating backups of your Power Automate flows in form of JSON files. The article ended with the possibility of looking into the JSON code to find the changes. Why not take it one step further, to take the backup and actually use it to restore a flow? To build another flow that’ll rewrite the current flow from the backup?
Triggering the flow
Since you’ll have a lot of backup files, I’d start from the trigger ‘For selected file’ (unless you’re building a PowerApp for the solution). Keep in mind that for the context menu to work it must be in the Default environment, otherwise use a different approach.
Connect the trigger to the library with flow backups and get their content.
There’re a few pieces of information in the JSON file you’ll need and which you can extract using expressions.
Extracting the backup data
Firstly, there’s the flow id, a unique identifier of the flow. Since you want to update the existing flow to previous version, you’ll have to get this id.
body('Get_file_content')?['name']
Secondly, you’ll need also the flow name to tell the updating action what should the flow be called. Since it’s the same flow, extract it from the JSON.
body('Get_file_content')?['properties']?['displayName']
Next, the whole flow definition, all the actions and their configuration inside the ‘definition’ property.
body('Get_file_content')?['properties']?['definition']
And finally, the connection references – what connections the actions use.
body('Get_file_content')?['properties']?['connectionReferences']
Restoring the flow
But before you get to the actual flow restore, there’s one middle step to take. The connection references as seen above have too much information, sometimes causing problems during the update. Reduce the properties only to connectionName and id with the ‘Select’ action.
Now, knowing all the inputs, you can add the ‘Update Flow’ action from the ‘Power Automate Management’ section. Reference all the inputs and decide whether the flow should be On or Off after the update.
Here it’s connected only to a single environment ‘Pipeline_DEV’, but it’s also available in the JSON export in the id property. You can extract it from there with an expression.
split(body('Get_file_content')?['id'],'/')[4]
Summary
As you can see in this article, it doesn’t end with creating a backup of the flow, you can use Power Automate also to restore it. The exported JSON file contains all the information you need, just extract it with a few expressions, adjust the connection references with the ‘Select’ action, and update the flow.
Yet I have to mention here that I encountered a few flows that I wasn’t able to restore using this process. Most flows were working fine, but in a few it had some problem with the ‘HTTP request to SharePoint’ action in the flow definition… But even knowing this I think it’s such a simple and useful solution that it’s worth a try.