Automate the Backup of your Flow and Power Apps Canvas Application

Introduction 
 
Microsoft Power Automate & Power Apps have become quite important & popular service now a days within Office 365, there are many users (developers & IT pro users) who are creating business applications leveraging these services very quickly, but if an app or a flow is deleted by mistake then it’s not an easy job to spin it back up without involving Microsoft support. In this blog post, am going to give you some ideas to back up a Flow & Power Apps automatically with the help of connectors available in Power automate. Once it is backed up, I will show you steps to restore from the back up.
 
Here I will show you steps to back up & restore your Flow & Power Apps:
  1. Backup & Restore your Flow
  2. Backup & Restore your Power Apps 

Backup & Restore your Flow

 
A flow could be backed up by copying the flow definition & connection references with the help of an action “Get Flow” under the flow connector “Flow Management”, so that it could be restored back a whenever needed. Thanks to John Liu for the tips & guidance on showing us a way to copy the flow definition. Before showing you steps to get the flow definition & connection references, I will show you some examples on the type of information it stores on these fields.
 

Flow Definition

 
It has details about the triggers & actions used within a flow in a JSON format.
 
Automate The Backup Of Your Flow And Power Apps Canvas Application
 
Automate The Backup Of Your Flow And Power Apps Canvas Application

Triggers

 
Information about the trigger used in the flow (Instant, Automatic, Scheduled)
 
Automate The Backup Of Your Flow And Power Apps Canvas Application Automate The Backup Of Your Flow And Power Apps Canvas Application
 

Actions

 
Information about all actions used in the flow
 
Automate The Backup Of Your Flow And Power Apps Canvas Application
 
Automate The Backup Of Your Flow And Power Apps Canvas Application

Connection References

 
It has details about all connections used against each action
 
Automate The Backup Of Your Flow And Power Apps Canvas Application Automate The Backup Of Your Flow And Power Apps Canvas Application
 
Add the action “Get Flow” under connector “Flow Management”, which has the fields flow definition & connection references. This action would be able to get only the flows to which you have access to. If you don’t see the flow under the drop down, enter the Flow ID by selecting custom value. 
 
Automate The Backup Of Your Flow And Power Apps Canvas Application Automate The Backup Of Your Flow And Power Apps Canvas Application
 
Now let’s store the Flow definition & connection references to a file in some location so that we would be able to retrieve the files for restoration. On this example I will use “One Drive for business connector” action “Create File” to store the content in two files but you can also get it stored on SharePoint Document Library, Azure Blob, GitHub etc. The extension of these files can also be .txt but I’ve used .json.
 
Automate The Backup Of Your Flow And Power Apps Canvas Application Automate The Backup Of Your Flow And Power Apps Canvas Application
 

Restore Flow

 
Flow action “Create Flow” helps us to restore the flow from the flow definition & the connection references stored in One drive. Only the file content should be passed for the flow definition & connection references.
 
Automate The Backup Of Your Flow And Power Apps Canvas Application Automate The Backup Of Your Flow And Power Apps Canvas Application
 

Backup & Restore your Power App

 
A Power App could be backed up by creating a MSAPP file for the PowerApp. The file with extension .msapp is just a ZIP file which has all the definitions of the app. There are open source tools (Review Tool, Theme editor, App merger, Phone to tablet converter) available in github which helps us to peek at definition of the .msapp file.
 
Automate The Backup Of Your Flow And Power Apps Canvas ApplicationAutomate The Backup Of Your Flow And Power Apps Canvas Application
 
PowerApps for App Makers connector has an action called “Get App” which helps us to get all the information related to the specified app. This action has a field called “readonlyValue”. It points to a link that stores the PowerApps msapp file. With the help of the premium connector HTTP, we will make a GET request to the readonlyValue link (Blob storage path). This step allows you to retrieve the contents of the msapp file which could be stored as a backup file in SharePoint, Onedrive, Github etc. Let’s now look at the data stored in the msapp file, change the extension of the .msapp file to .zip file and open it.
 
Automate The Backup Of Your Flow And Power Apps Canvas Application Automate The Backup Of Your Flow And Power Apps Canvas Application
<
Assets
All the media files (Images, Videos, Audio)
Controls
Information about all the controls (First Party, Custom components etc) used in the different screens of the app. Data is in JSON format.
References
Information about Datasources, Templates (Label, Gallery, Textbox etc), Resources (Images etc), Themes used in the app etc
Resources
Publish information, user locale etc
Properties.json
Information of the app like Author, PowerApp name, no of screens etc
 
Automate The Backup Of Your Flow And Power Apps Canvas ApplicationAutomate The Backup Of Your Flow And Power Apps Canvas Application
 
Add the action “Get App”, enter the App ID of the Power App
 
Automate The Backup Of Your Flow And Power Apps Canvas Application
 
This action retrieves all the information of the app including the “readonlyvalue” as explained above. Using this result we will make a GET request using the HTTP connector to retrieve the app data in this Flow.
 
Automate The Backup Of Your Flow And Power Apps Canvas ApplicationAutomate The Backup Of Your Flow And Power Apps Canvas Application
 
Add the action “Create file” in OneDrive for Business connector and set the body from HTTP connector. This allows you to save your app to OneDrive for Business. As said earlier you can instead store it to other storage like Azure Blob Storage, SharePoint document library, GitHub etc.
 
Automate The Backup Of Your Flow And Power Apps Canvas ApplicationAutomate The Backup Of Your Flow And Power Apps Canvas Application
 

Restore Power App

 
The msapp file is with us now, let’s now restore the PowerApp. Create a Blank app from the Power Apps studio then open the.MSApp file via the File > Open > Browse menu option. This enables you to select an .MSApp file from your local file system then save & publish the App. The app is now back. Let me know on the comment section if there is an automated way to restore the PowerApp from the MSApp file.
 

Summary

 
In this article, we have seen ways to backup & restore your app & flow using a Flow. If you are an Power App/Power Automate environment admin (Premium license), you could backup all the apps & flow available in the environment using the Apps for Admin connector. There are Power Shell cmdlets available for Admins & creators which could be used for this task. If you have a more complex business application including PowerApps Canvas, multiple flows, custom connector, Model driven apps, entity etc, solutions is recommended. Exporting a solution as a package is very easy by click of a button, restoring is also quite an easy task. Hope you find this article useful, let me know your feedback on the comments section.