[英]how can I create job for make Back Up From SSAS Database?
I use SQL Server 2008 R2
and SSAS. 我使用
SQL Server 2008 R2
和SSAS。
I have some dimensional DataBase in SSAS. 我在SSAS中有一些维数据库。
I need create a job for make back up from all DataBase of SSAS in each days. 我需要创建一份工作,以便每天从SSAS的所有DataBase备份。
How i can do it? 我怎么能这样做?
So there are a few ways: 所以有几种方法:
1/ Create a SQL Job using Analysis Services Commands as steps, one for each DB using code similar to this: 1 /使用Analysis Services命令创建SQL作业作为步骤,每个数据库使用与此类似的代码:
<Backup xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Object>
<DatabaseID>DBName</DatabaseID>
</Object>
<File>\\server\share\folder\backupFile.abf</File>
<AllowOverwrite>true</AllowOverwrite>
</Backup>
This is nice and easy and if you only have a few SSAS databases that you don't delete or add more to on a regular basis, relatively painless to maintain 这很简单,如果您只有一些SSAS数据库,您不会定期删除或添加更多数据库,维护起来相对轻松
2/ Create an SSAS linked server and then use a regular SQL statement in a job step to pass in your command (gives you a bit more flexibility as you can use variables to modify things like the filename etc): 2 /创建一个SSAS链接服务器,然后在作业步骤中使用常规SQL语句来传递命令(由于您可以使用变量来修改文件名等内容,因此可以提供更多灵活性):
Create SSAS Linked Server 创建SSAS链接服务器
DECLARE @XMLA NVARCHAR(1000) ,
@timeStamp NVARCHAR(35);
SET @timeStamp = CONVERT(NVARCHAR, GETDATE(), 112) + '_'
+ REPLACE(CONVERT(VARCHAR(8), GETDATE(), 108), ':', '');
SET @XMLA = N'<Backup xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Object>
<DatabaseID>dbName</DatabaseID>
</Object>
<File>\\server\share\folder\dbName_'
+ @timeStamp + '.abf</File>
<AllowOverwrite>true</AllowOverwrite>
<ApplyCompression>false</ApplyCompression>
</Backup>';
EXEC (@XMLA) AT [SSAS_LinkedServer]
EDIT: What you can also do with this method is easily get a list of SSAS databases from the Analysis Server using the following: 编辑:使用此方法您还可以使用以下方法从Analysis Server轻松获取SSAS数据库列表:
SELECT [catalog_name] FROM OPENQUERY([SSAS_LinkedServer],'select [catalog_name] from $system.dbschema_catalogs')
You can then just cursor through this list, executing the SSAS command through the linked server for each DB in the list therefore meaning that you don't need to maintain the job manually if you add a new SSAS database. 然后,您可以只浏览此列表,通过列表中每个数据库的链接服务器执行SSAS命令,这意味着如果添加新的SSAS数据库,则无需手动维护作业。
3/ Use powershell, this method below won't work on 2008 R2, but could be modified to use SMO directly rather than the nice provider that they provide in SQL Server 2012 (this is the method that we use and the below is a sample from my script): 3 /使用powershell,下面的方法在2008 R2上不起作用,但可以修改为直接使用SMO而不是它们在SQL Server 2012中提供的好提供程序(这是我们使用的方法,下面是一个示例从我的脚本):
import-module sqlps -disablenamechecking
$server = "SERVER\INSTANCE"
$backupPath = "\\backup-server\share\SSAS\$server\"
#Get a list of the SSAS databases on the server
$ssasDBs = dir SQLSERVER:\SQLAS\$server\databases
#Backup each SSAS database on the server
foreach ($db in $ssasDBs)
{
$extension = Get-Date -UFormat "_%Y_%m_%d_%A_%H%M%S.abf"
$backupFile = $backupPath+$db+$extension
try
{
$db.Backup($backupFile)
}
catch
{
Write-Warning "Backup of $db Failed!!!"
}
}
This method has the advantage that you don't have to change the job if you add a new SSAS database, it will get backed up automatically by the script with no changes. 此方法的优点是,如果添加新的SSAS数据库,则无需更改作业,脚本将自动备份,无需更改。
I'm sure there are other ways to achieve this, but these are 3 ways that I have used to manage SSAS backups, I generally find the management side of SSAS rather painful as it seems to be a bit lacking, but maybe that's just me. 我确定还有其他方法可以实现这一点,但这些是我用来管理SSAS备份的3种方法,我一般认为SSAS的管理方面相当痛苦,因为它似乎有点缺乏,但也许这只是我。 The new powershell bits in SQL 2012 make it much easier though.
SQL 2012中新的PowerShell位使它变得更容易。
Hope this helps with at least some ideas of what you can do. 希望这有助于至少有一些关于你能做什么的想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.