A PowerShell script to automate the backup of all items from your Microsoft Fabric workspaces locally, maintaining the original folder structure.
This script uses the official ms-fabric-cli (fab) tool to list all workspaces within a Microsoft Fabric tenant and then exports each valid item (Reports, Semantic Models, Lakehouses, Notebooks, etc.) into a specified local directory.
It handles:
- Interactive prompts bypass (
fab export). - Error handling for items that do not support exporting.
- Workspace filtering based on custom text matching to avoid downloading development, trial, or temporary workspaces.
Before running this script, ensure you have the following installed and configured:
- Python 3.10+ (must be added to your system's PATH).
- Microsoft Fabric CLI: Install it using pip:
pip install ms-fabric-cli
- Authentication: You must log in to your tenant from the console to allow the script to access your workspaces:
fab auth login
Simply run the script from your PowerShell console:
.\backup_fabric.ps1By default, the script will create a FabricBackup folder in the current directory and download everything there.
The script supports the following optional parameters to customize the backup process:
-BackupDirectory <String>: Specifies the main local directory path where the backup will be stored. Default is.\FabricBackup.-ExcludeWorkspaces <String[]>: A list of text strings. Any workspace whose name contains one or more of these strings will be ignored and excluded from the extraction process (case-insensitive).
Exporting to a specific path:
.\backup_fabric.ps1 -BackupDirectory "C:\Backups\Fabric"Excluding specific workspaces:
.\backup_fabric.ps1 -ExcludeWorkspaces "TEMP", "PRUEBA", "DEV"Combining both parameters:
.\backup_fabric.ps1 -BackupDirectory ".\SmartDataSuite" -ExcludeWorkspaces "ZZZ"- Validates that the
fabcommand is available. - Lists all the accessible workspaces in the tenant using
fab ls /. - Filters out any workspace that matches the text in
-ExcludeWorkspaces. - Creates a local folder for each workspace inside the
-BackupDirectory. - Iterates through the items inside each workspace using
fab ls /<WorkspaceName>.Workspace. - Uses
fab exportto download the definitions, files, and metadata of each item into its corresponding local folder.