Skip to content
Rishan Solutions
Rishan Solutions
  • PowerApps
  • SharePoint online
    • Uncategorized
    • Uncategorized
  • PowerAutomate
Rishan Solutions
Latest Posts
  • Agentic AI: The Dawn of Autonomous Intelligence Revolutionizing 2025 June 24, 2025
  • Recursive Queries in T-SQL May 7, 2025
  • Generating Test Data with CROSS JOIN May 7, 2025
  • Working with Hierarchical Data May 7, 2025
  • Using TRY_CAST vs CAST May 7, 2025
  • Dynamic SQL Execution with sp_executesql May 7, 2025

Creating a SharePoint Online Backup Strategy using PnP PowerShell

Posted on March 21, 2025March 21, 2025 by Rishan Solutions

Loading

Backing up SharePoint Online is critical to prevent data loss due to accidental deletions, cyberattacks, or misconfigurations. While Microsoft 365 provides retention policies and versioning, having an external backup strategy using PnP PowerShell ensures additional security.

This guide will help you create a comprehensive SharePoint Online backup strategy using PnP PowerShell, covering:

✔ Backing up site collections
✔ Exporting document libraries
✔ Saving lists and metadata
✔ Automating backups


Step 1: Install and Connect to SharePoint Online

Ensure you have PnP PowerShell installed:

Install-Module -Name PnP.PowerShell -Force -AllowClobber
Update-Module -Name PnP.PowerShell

Connect to SharePoint Online:

Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/YourSite" -Interactive

Step 2: Backup SharePoint Site Collections

You can export site collection structure using:

$backupPath = "C:\Backups\SiteBackup.xml"

Get-PnPSiteTemplate -Out $backupPath
Write-Host "Site collection structure exported to $backupPath"

✔ Saves site structure, lists, libraries, and settings.

To restore the site structure:

Invoke-PnPSiteTemplate -Path $backupPath
Write-Host "Site structure restored from backup."

Step 3: Backup Document Libraries

To download all files from a library:

$libraryName = "Documents"
$backupFolder = "C:\Backups\Documents"

# Create backup folder if not exists
If (!(Test-Path -Path $backupFolder)) { New-Item -ItemType Directory -Path $backupFolder }

# Retrieve files and download
$files = Get-PnPListItem -List $libraryName
foreach ($file in $files) {
$fileUrl = $file["FileRef"]
$localFilePath = "$backupFolder\$($file["FileLeafRef"])"

Get-PnPFile -Url $fileUrl -Path $backupFolder -FileName $file["FileLeafRef"] -AsFile
Write-Host "Downloaded: $fileUrl"
}

Write-Host "Document library backup completed."

✔ Saves all files locally for external storage.


Step 4: Backup Lists and Metadata

To export list items:

$backupFile = "C:\Backups\ListBackup.csv"
$listName = "Tasks"

Get-PnPListItem -List $listName | Export-Csv -Path $backupFile -NoTypeInformation
Write-Host "List items exported to $backupFile"

To restore the list data:

$importData = Import-Csv -Path $backupFile
foreach ($item in $importData) {
Add-PnPListItem -List $listName -Values @{
"Title" = $item.Title;
"Description" = $item.Description
}
}
Write-Host "List data restored."

✔ Retains metadata and list structure.


Step 5: Automate Backups with Task Scheduler

To schedule daily backups:

  1. Save the script as SharePointBackup.ps1.
  2. Open Task Scheduler → Create Basic Task.
  3. Set Trigger → Daily at 2:00 AM.
  4. Set Action → Start a Program.
  5. Use this PowerShell execution command: -ExecutionPolicy Bypass -File "C:\Scripts\SharePointBackup.ps1"

✔ Ensures automatic backups without manual intervention.


Step 6: Verify Backup Integrity

To check if all backups are successful:

Get-ChildItem -Path "C:\Backups" | Select Name, Length, LastWriteTime

✔ Confirms files were saved correctly.

Posted Under PNP PowerShellAutomation backup strategy Data Protection Document Libraries List Metadata PNP PowerShell SharePoint online Site Collection Backup Task Scheduler

Post navigation

Migrating File Shares to SharePoint Online using PnP PowerShell
Java Secure REST API Development Best Practices

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Agentic AI: The Dawn of Autonomous Intelligence Revolutionizing 2025
  • Recursive Queries in T-SQL
  • Generating Test Data with CROSS JOIN
  • Working with Hierarchical Data
  • Using TRY_CAST vs CAST

Recent Comments

  1. Michael Francis on Search , Filter and Lookup in power apps
  2. A WordPress Commenter on Hello world!

Archives

  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • March 2024
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • January 2022

Categories

  • Active Directory
  • AI
  • AngularJS
  • Blockchain
  • Button
  • Buttons
  • Choice Column
  • Cloud
  • Cloud Computing
  • Data Science
  • Distribution List
  • DotNet
  • Dynamics365
  • Excel Desktop
  • Extended Reality (XR) – AR, VR, MR
  • Gallery
  • Icons
  • IoT
  • Java
  • Java Script
  • jQuery
  • Microsoft Teams
  • ML
  • MS Excel
  • MS Office 365
  • MS Word
  • Office 365
  • Outlook
  • PDF File
  • PNP PowerShell
  • Power BI
  • Power Pages
  • Power Platform
  • Power Virtual Agent
  • PowerApps
  • PowerAutomate
  • PowerPoint Desktop
  • PVA
  • Python
  • Quantum Computing
  • Radio button
  • ReactJS
  • Security Groups
  • SharePoint Document library
  • SharePoint online
  • SharePoint onpremise
  • SQL
  • SQL Server
  • Template
  • Uncategorized
  • Variable
  • Visio
  • Visual Studio code
  • Windows
© Rishan Solutions 2025 | Designed by PixaHive.com.
  • Rishan Solutions