我们有一套由不同员工维护的SSAS 2005数据库。包括格式字符串等的元数据/模式已经发展为表示大量的工作,并且它们周期性地改变。我们已经尝试过将商业智能项目置于源代码控制之下,但如果每晚都备份所有SSAS元数据,而不备份数据本身,那也会很好。(数据当然是巨大且可重现的,而模式是微小的。)
我可以使用Microsoft.AnalysisServices.Server.Databases集合以编程方式(C#)轻松地遍历所有SSAS,但是我还没有找到一种在没有数据的情况下备份模式的简单方法。使用SSMS,我可以右键单击数据库,然后选择Script Database as-->CREATE To-->File...例如,获取表示整个数据库元数据的XMLA。这里引用的是:http://msdn.microsoft.com/en-us/library/ms174589.aspx,我相信它包含了我们想要备份的所有信息……但是,我还没有在Microsoft.AnalysisServices程序集中找到提供类似功能的方法,也不确定还可以在哪里查找。
发布于 2011-08-08 15:19:25
我知道我可能来晚了,但我还是要说..
这是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()不是我的,我在Darren Gosbell发布的地方找到的。
发布于 2012-01-07 01:31:06
我找到了一个解决方案:
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();
}
}https://stackoverflow.com/questions/5199666
复制相似问题