【问题标题】:SSAS programmatically back up metadata onlySSAS 仅以编程方式备份​​元数据
【发布时间】:2011-03-04 21:48:14
【问题描述】:

我们有一组由不同员工维护的 SSAS 2005 数据库。元数据/模式(包括格式字符串等)已经演变为代表大量工作,并且它们会定期更改。我们已经尝试将商业智能项目置于源代码控制之下,但如果没有数据本身,对所有 SSAS 元数据进行夜间备份也会很好。 (数据当然庞大且可重复,而架构很小。)

我可以使用 Microsoft.AnalysisServices.Server.Databases 集合以编程方式 (C#) 轻松循环所有 SSAS 数据库,但我还没有找到一种简单的方法来备份没有数据的架构。使用 SSMS,我可以右键单击 db 并选择 [Script Database as]-->[CREATE To]-->[File ...] 例如并获取表示整个数据库元数据的 XMLA。这在这里被引用:http://msdn.microsoft.com/en-us/library/ms174589.aspx,我相信这有我们想要备份的所有信息......但是我没有在 Microsoft.AnalysisServices 程序集中找到提供类似功能的方法,我不确定还有什么地方可以看。

【问题讨论】:

    标签: ssas xmla


    【解决方案1】:

    我知道我可能有点晚了,但是就这样吧..

    这是 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 发布了它。

    【讨论】:

    • 以上适用于多维立方体。对于表格模型,您应该使用 Microsoft.AnalysisServices.Tabular.JsonScripter
    【解决方案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();
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多