我们有一套由各种员工维护的SSAS 2005数据库。包括格式字符串等的元数据/模式已经发展为代表大量工作并且它们周期性地改变。我们已经尝试将商业智能项目置于源代码管理之下,但是如果没有数据本身,那么每晚备份所有SSAS元数据也会很不错。 (数据当然是巨大且可重复的,而模式很小。)
我可以使用Microsoft.AnalysisServices.Server.Databases集合以编程方式(C#)轻松遍历所有SSAS dbs,但我还没有找到一种简单的方法来备份没有数据的架构。使用SSMS,我可以右键单击数据库,然后选择[脚本数据库为] - > [创建到] - > [文件...],例如,获取表示整个数据库元数据的XMLA。这里引用了这个:http://msdn.microsoft.com/en-us/library/ms174589.aspx,我相信这有我们要备份的所有信息......但是我还没有找到在Microsoft.AnalysisServices程序集中提供类似功能的方法。我不确定在哪里可以看。
答案 0 :(得分:2)
我知道我可能有点迟到了,但是这里就是......
这是PowerShell,但转换为C#非常简单:
$svrName = "localhost\sql08"
$sourceDB = "Adventure Works DW 2008"
$sourceCube = "Adventure Works"
# load the AMO library (redirect to null to 'eat' the output from assembly loading process)
[System.Reflection.Assembly]::LoadwithpartialName("Microsoft.AnalysisServices") > $null
# connect to the AS Server
$svr = New-Object Microsoft.AnalysisServices.Server
$svr.Connect($svrName)
# get a reference to the database
$db= $svr.Databases.Item($sourceDB)
# get a reference to the cube
$cub = $db.Cubes.FindByName($sourceCube)
# setup the scripter object
$sb = new-Object System.Text.StringBuilder
$sw = new-Object System.IO.StringWriter($sb)
$xmlOut = New-Object System.Xml.XmlTextWriter($sw)
$xmlOut.Formatting = [System.Xml.Formatting]::Indented
$scr = New-Object Microsoft.AnalysisServices.Scripter
# create an array of MajorObjects to pass to the scripter
$x = [Microsoft.AnalysisServices.MajorObject[]] @($cub)
$scr.ScriptCreate($x,$xmlOut,$false)
$sb.ToString() > c:\data\tmpCube2.xmla
# clean up any disposeable objects
$sw.Close()
$svr.Disconnect()
$svr.Dispose()
这不是我的,我发现here张贴了Darren Gosbell。
答案 1 :(得分:2)
我找到了解决方案:
void ScriptDb(string svrName, string dbName, string outFolderPath)
{
using (var svr = new Server())
{
svr.Connect(svrName);
// get a reference to the database
var db = svr.Databases[dbName];
// setup the scripter object
var sw = new StringWriter();
var xmlOut = new XmlTextWriter(sw);
xmlOut.Formatting = Formatting.Indented;
var scr = new Scripter();
// create an array of MajorObjects to pass to the scripter
var x = new MajorObject[] { db };
scr.ScriptCreate(x, xmlOut, true);
// todo: would be wise to replace illegal filesystem chars in dbName
var outPath = Path.Combine(outFolderPath, dbName + ".xmla");
File.WriteAllText(outPath, sw.ToString());
// clean up any disposeable objects
sw.Close();
svr.Disconnect();
svr.Dispose();
}
}