SSAS 仅以编程方式备份​​元数据

发布于 2024-10-20 09:26:36 字数 584 浏览 1 评论 0原文

我们有一组 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 程序集中找到提供类似功能的方法,并且不确定其他地方看看。

We have a set of SSAS 2005 databases that are maintained by various employees. The metadata/schema including format strings, etc. have evolved to represent a significant amount of work and they change periodically. We've tried having the business intelligence projects under source control, but it would also be nice to have a nightly backup of all SSAS metadata, without the data itself. (The data is of course huge and reproducible, whereas the schema is tiny.)

I can programmatically (C#) loop through all the SSAS dbs easily with the Microsoft.AnalysisServices.Server.Databases collection, but I haven't found a simple way to back up the schema without the data. Using SSMS, I can right-click the db and choose [Script Database as]-->[CREATE To]-->[File ...] for example and get XMLA representing the entire database metadata. This is referenced here: http://msdn.microsoft.com/en-us/library/ms174589.aspx, and I believe this has all the information we'd like to back up... however I haven't found methods providing similar functionality in the Microsoft.AnalysisServices assembly and am not sure where else to look.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

会傲 2024-10-27 09:26:36

我知道我可能有点晚了,但事情就这样了..

这是 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()

这不是我的,我发现了它 此处 其中 达伦·戈斯贝尔发布了它。

I know I may be kind of late, but here it goes..

This is PowerShell, but converting to C# is a breeze:

$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()

It's not mine, I found it here where Darren Gosbell posted it.

逆光飞翔i 2024-10-27 09:26:36

我找到了解决方案:

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();
  }
}

I've found a solution:

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();
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文