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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.