Backup (and restore) for SharePoint Online site pages

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..

As per usual, the people at the PnP community already thought about that, and Erwin van Hunen demoed it during the June 2019 call which you can view the recording of here.

Watch the recording of the PnP community

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
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
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.

About: Marijn

Marijn Somers (MVP) has over 14 years experience in the SharePoint world, starting out with SP2007. Over the years the focus has grown to Office 365, with a focus on collaboration and document management. He is a business consultant at Balestra and Principal Content Provider for "Mijn 365 Coach" that offers dutch employee video training. His main work tracks are around user adoption, training and coaching and governance. He is also not afraid to dig deeper in the technicalities with PowerShell, adaptive cards or custom formatting in lists and libraries. You can listen to him on the biweekly "Office 365 Distilled" podcast.

%d bloggers like this: