Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

How to dynamically backup daily ssas tabular database files for the past 7 days?

is there any way to dynamically backup daily ssas tabular database files for the past 7 days?

Daily backup, only retaining backup files from the past 7 days, files more than past 7 days will be deleted.

for example, today is 0613, only backup 0606-0612 daily backup files, tomorrow, 0614, only backup 0607-0613, and 0606 file will be deleted.

I had tried powershell command to do it. but the script cannot dynamically delete files, only backup no drop files. I don't know why.

this is the script:

$server = "localhost"
$database = "TabularProject2"
$backupPath = "D:\Backup\"

# Connect to SSAS server
$conn = New-Object Microsoft.AnalysisServices.Server
$conn.connect($server)

# Get database object
$db = $conn.databases[$database]

# Check if database object is null
if ($db -eq $null) {
Write-Host "Could not connect to database $database on server $server"
} else {
# Create backup file name
$backupFileName = "awdb-" + (Get-Date).ToString("yyyyMMdd-HHmmss") + ".abf"

# Execute backup operation
$backupFile = $backupPath + $backupFileName
$backup = $db.Backup($backupFile)
Write-Host "Backup created at $backupFile"

# Delete backup files older than 7 days
$dateToKeep = (Get-Date).AddDays(-7)
Get-ChildItem -Path $backupPath -Include "awdb-*.abf" | Where-Object { $_.LastWriteTime -lt $dateToKeep } | Remove-Item -Force

# Disconnect from server
$conn.Disconnect()
}

 

looking forward to your answer, thanks a lot.

 

1 REPLY 1
d_gosbell
Super User
Super User

You are passing a file object to Remove-Item which expects a string parameter. That line should probably be something like the following:

 

Get-ChildItem -Path $backupPath -Include "awdb-*.abf" | Where-Object { $_.LastWriteTime -lt $dateToKeep } | % { Remove-Item $_.FullName -Force }

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.