HOW TO DYNAMICALLY BACK UP SSAS TABULAR DATABASE FOR THE LAST 7 DAYS DAILY WITH POWERSHELL

Copper Contributor

Daily backup ssas tabular database, dynamic backup for the last 7 days.

powershell or other way can do it?

this is a sample by powershell, but it not work.

can you help me? thanks a lot.

powershell script is this:

$server = "localhost"
$database = "ssasdbdemo"
$backupPath = "D:\"

# 连接到 SSAS 服务器
$conn = New-Object Microsoft.AnalysisServices.Server
$conn.connect($server)

# 获取数据库对象
$db = $conn.databases[$database]

# 创建备份文件名
$backupFileName = "awdb-" + (Get-Date).ToString("yyyyMMdd-HHmmss") + ".abf"

# 执行备份操作
$backupFile = $backupPath + $backupFileName
$backup = $db.BackupDatabase($backupFile)
Write-Host "Backup created at $backupFile"

# 删除7天前的备份文件
$dateToKeep = (Get-Date).AddDays(-7)
Get-ChildItem -Path $backupPath -Include "awdb-*.abf" | Where-Object { $_.LastWriteTime -lt $dateToKeep } | Remove-Item -Force

# 断开连接
$conn.Disconnect()

 

3 Replies
What do you mean with "for the last 7 days"?
IT means recent 7 days. for example, toady is 20230609, I will backup recent 7 days ssas tabular database for 20230602, 20230603, 20230604, 20230605, 20230606, 20230607, 20230608. tomorrow 20230610, I will backup 20230609, and dynamicly delete 20230602, only preserve recent 7 days daily ssas backup.
Sorry, your post is still more then unclear.
You can backup a SSAS as it is right now, you cannot backup a database/data state somewhere in the past.