Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Guy in a cube shows how to back up datasets as a .abf file to adls (Azure Data Lake Storage) using powershell. The short youtube video is here: https://www.youtube.com/watch?v=RbMFQNthlGM&ab_channel=GuyinaCube
I've done this but I am working to migrate everything to fabric and using Fabric notebooks. I have spent several days trying to translate this into Python but I can't figure it out. Can someone help me? I got it working with powershell but not Python. Thanks for the help.
Solved! Go to Solution.
Hi @nphadro07 ,
Thank you for sharing additional details.
Please follow the steps outlined below to resolve your issue.
For more detailed information, please refer to the following links:
Use Python experience on Notebook - Microsoft Fabric | Microsoft Learn.
Key deference:
NOTE: Make sure your workspace is in Premium or Premium Per User (PPU) capacity to support the XMLA endpoint. This is necessary to access the XMLA API.
Please let us know if you need further assistance!
If my response solved your query, please mark it as the Accepted solution to help others find it easily!
And if my answer was helpful, I'd really appreciate a 'Kudos'.
Hi @nphadro07,
Thanks for reaching out to the Microsoft Fabric Community Forum.
We’re having a bit of trouble pinpointing the exact issue you’re facing while backing up your semantic model using Python. Could you please provide more details about where you’re getting stuck in python ? Any specific error messages or relevant information would significantly help us understand the problem better.
If you can, please share screenshots or code snippets showing the issue. This will help us assist you more effectively and offer precise solutions.
We’re here to help, so please don't hesitate to share further details for a better understanding of your query.
Thank You.
Thanks for the response @V-yubandi-msft ,
Here is my Python code that I keep getting an error "Backup failed: 404 -". I'm relatively new to python so I appreciate thes upport. Also below the Python put in my powershell code that works. Any help is grately appreciated.
import requests
from datetime import datetime
import msal
# Configuration
APP_ID = "" # HCH_Compass_PBI_Automation app registration service principal account
APP_SECRET = ""
TENANT_ID = ""
POWERBI_BASE_URL = "https://api.powerbi.com/v1.0/myorg/"
WORKSPACE_ID = "HCH_Dataset COMPASS" # Replace with your workspace ID
# Authentication
def get_access_token(app_id, app_secret, tenant_id):
authority_url = f"https://login.microsoftonline.com/{tenant_id}"
client = msal.ConfidentialClientApplication(
app_id, authority=authority_url, client_credential=app_secret
)
token_response = client.acquire_token_for_client(scopes=["https://management.core.windows.net/.default"])
if "access_token" in token_response:
return token_response["access_token"]
else:
raise Exception("Failed to get access token")
# Backup Dataset
def backup_dataset(access_token, workspace_id, database_name, backup_filename):
url = f"{POWERBI_BASE_URL}{workspace_id}"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
body = {
"backup": {
"database": database_name,
"file": backup_filename,
"allowOverwrite": True,
"applyCompression": True
}
}
response = requests.post(url, headers=headers, json=body)
if response.status_code == 200:
print(f"Backup successful: {backup_filename}")
else:
print(f"Backup failed: {response.status_code} - {response.text}")
# Main Code
access_token = get_access_token(APP_ID, APP_SECRET, TENANT_ID)
# Define Parameters
database_name = "Invoice and Order HCH COMPASS"
workspace_id = "HCH_Dataset COMPASS" # Replace with actual Workspace ID
datestring = datetime.utcnow().strftime("%b %d, %Y")
backup_filename = f"{datestring}_{database_name}.abf"
# Execute the Backup
backup_dataset(access_token, workspace_id, database_name, backup_filename)
Powershell that does work but I really don't want to use powershell anymore:
#PARAMETERS NOT POPULATED
param
(
[Parameter()]
[String]$PowerBI = "powerbi://api.powerbi.com/v1.0/myorg/",
[Parameter()]
[String]$Workspace = "Videos",
[Parameter()]
[String]$DatabaseName = "TheDataModel",
[Parameter()]
[String]$AppId = "",
[Parameter()]
[String]$AppSecret = "",
[Parameter()]
[String]$TenantId = ""
)
$XMLAEndPoint = $PowerBI+$Workspace
$PWord = ConvertTo-SecureString -String $AppSecret -AsPlainText -Force
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $AppId, $PWord
$datestring = (Get-Date).ToString("s").Replace(":","-")
$Backupfilename = $DatabaseName+"_"+$datestring+".abf"
$Query =
@"
{
"backup": {
"database": "$DatabaseName",
"file": "$Backupfilename",
"allowOverwrite": true,
"applyCompression": true
}
}
"@
Invoke-ASCmd -Server $XMLAEndpoint -Query $Query -ApplicationId $AppId -TenantId $TenantId -Credential $Credential -ServicePrincipal
Hi @nphadro07 The scope used in the get_access_token function should be https://analysis.windows.net/powerbi/api/.default instead of https://management.core.windows.net/.default
Hi @nphadro07 ,
Thank you for sharing additional details.
Please follow the steps outlined below to resolve your issue.
For more detailed information, please refer to the following links:
Use Python experience on Notebook - Microsoft Fabric | Microsoft Learn.
Key deference:
NOTE: Make sure your workspace is in Premium or Premium Per User (PPU) capacity to support the XMLA endpoint. This is necessary to access the XMLA API.
Please let us know if you need further assistance!
If my response solved your query, please mark it as the Accepted solution to help others find it easily!
And if my answer was helpful, I'd really appreciate a 'Kudos'.
Hi @nphadro07 ,
We wanted to touch base as we haven't received a response from you yet. We hope the solution provided was useful. If you require further assistance or have any more questions, don't hesitate to reach out. Your feedback is invaluable, and we look forward to your response.
Thank You.
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!