Shiham Sham

Sitecore XP PaaS Backups with PowerShell



In this post, we’ll explore a PowerShell script that simplifies backing up Sitecore XP roles deployed on Azure PaaS. This script automates the process of downloading application backups from Azure App Services, making it easier to download full backups for ad-hoc purposes.

Script Overview

The sitecore-xp-paas-vanila-backup.ps1 script is designed to:

  1. Connect to Azure using service principal authentication
  2. Download backups for all Sitecore XP roles
  3. Save backups to a local directory

Prerequisites

Before running the script, you’ll need:

1. Install Azure PowerShell Module

You can refer to How to install Azure PowerShell for the instructions suitable for your OS/ device. I am on Windows with Powershell, so following script would install it for me.

Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -AllowClobber

2. Set Execution Policy

This is a safety feature on Powershell to prevent running scripts. You can refer to How to set execution policy for more details.

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

3. Obtain Service Principal Credentials :

Service Principal is an identity used by Sitecore’s management services to access resources within an Azure, I am using service principal to authenticate against Azure and download the backups. Service Principal credentials must be obtained from Sitecore by raising a service request.

  • Application ID
  • Tenant ID
  • Service Principal Password/API Key

Script Configuration

The script requires these main configuration parameters:

# Obtain following from the Azure portal resource group
$resourceGroupName = "your-resource-group-name"
# if your CM web name is mc2-12345-6789-1011-1213-1415-cm, only enter 'mc2-12345-6789-1011-1213-1415-' here
$webAppName = "your-web-app-name-without-the-role-postfix-"
# List of webapp postfixes - Sitecore PaaS environments follows the same convention. Ensure to check against your instace for confirmation
$webAppPostfixList = @('cm','cd','cortex-processing','cortex-reporting','ma-ops','ma-rep','prc','si','xc-collect','xc-refdata','xc-search')
# This is where your backups downloaded
$localPath = "C:\folder\where\you\want\to\save\backups\"
# Service Principal Credentials
$ClientSecret = "insert-with-in-quotes"
$ApplicationID = "insert-with-in-quotes"
$TenantID = "insert-with-in-quotes"

Supported Sitecore Roles

The script automatically handles backups for all Sitecore XP roles:

  • Content Management (CM)
  • Content Delivery (CD)
  • Sitecore Identity
  • Cortex Processing
  • Cortex Reporting
  • Marketing Automation Operations
  • Marketing Automation Reporting
  • Processing
  • XC Collect
  • XC RefData
  • XC Search

Running the Script

To execute the backup script:

  1. Ensure you have the required prerequisites installed
  2. Update the configuration parameters with your environment details
  3. Run the script:
.\sitecore-xp-paas-vanila-backup.ps1

It will take about 20 to 30 minutes to download based on your internet speed. You can prepare a coffee and come back to see if all the files have been downloaded.

Sitecore XP PaaS Backups with PowerShell

Once done, you will see something like this.

Sitecore XP PaaS Backups with PowerShell

Security Considerations

  1. Store service principal credentials securely
  2. Use least privilege principle for service principal permissions and rotate service principal passwords
  3. Keep backups in a secure location

Best Practices

  1. Use this script for ad-hoc backup download for example to download backup of vanilla instance, for regular backups use Azure Backup Service.
  2. Verify backup integrity after download

Conclusion

This PowerShell script provides an efficient way to manage Sitecore XP PaaS backups. By automating the backup process, you can ensure your Sitecore environment is protected and recoverable in case of issues that require comparison of backup files.

Here is the full script.



Similar Posts

Comments