A customer had created a beautifully designed SharePoint site, complete with all kinds of informative pages containing lots of text and markup. The question now was how they could create a backup of these beautiful pages, in case something went wrong and they needed to restore them again.
I know, you shouldn’t have to do that in SharePoint Online, but sometimes peoples minds need to be listened to. And it does feel kind of safe to know it is in a backup somewhere so you can revert to it later. Or, what about, as a consultant, you have a number of clients where you always create the same help pages? Wouldn’t it be useful to write it once, save it and restore it on all the other tenants? This opens the door to so many content ideas..
It turns out to be really simple, only requiring a few lines of PowerShell magic to make this happen.
Open up a PowerShell command (make sure you have the PnP SharePoint library installed) and connect to the site that you want the pages to backup.
Connect-PnPOnline -Url https://yourtenant.sharepoint.com/sites/yoursite Get-PnPProvisioningTemplate -out pages.xml -Handlers PageContents -IncludeAllClientSidePages
This will create an xml file that stores all the text and artefacts of your site pages library.
If at some point you want to restore this pages goodness, simply use these lines of PowerShell:
Connect-PnPOnline -Url https://yourtenant.sharepoint.com/sites/yoursite Apply-PnPProvisioningTemplate .\pages.xml
Yes, it really is that simple. PowerShell really makes my life so much easier when managing a SharePoint environment. Every day I am grateful to that PnP community: I use their output almost daily! Once you start working with it, there is no turning back and you will be hooked! And before you know it, you will have your own little library full of code snippets that you want to use! Like this site collection script, or adding an external user to multiple sites.