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!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
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.
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 }
User | Count |
---|---|
9 | |
5 | |
3 | |
3 | |
2 |