AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 43493
Accepted
dev_etter
dev_etter
Asked: 2013-05-31 20:49:33 +0800 CST2013-05-31 20:49:33 +0800 CST 2013-05-31 20:49:33 +0800 CST

如何动态备份给定实例上的所有 SSAS 数据库?

  • 772

我想使用 SQL 代理作业(这很可能涉及执行 SSIS 包)动态备份给定 SSAS 实例上的所有数据库。这是一个动态过程非常重要——如果用户添加数据库或多维数据集,我想设置一个可以自动检测所有现有 SSAS 元数据的作业。

不幸的是,我没有看到任何可以告诉我如何以干净的方式自动动态备份 SSAS 实例上的所有数据库的信息。“干净”是指:

  • DatabaseId在备份命令中使用,而不是DatabaseName. DatabaseName有时 a和 a之间可能存在差异DatabaseId,如果存在差异DatabaseName,如果使用 代替,则备份将失败DatabaseId。仅查询 Catalogs 架构不会给我DatabaseId.
  • 避免每次遇到要备份的新实例时都需要创建链接服务器。
backup ssis
  • 3 3 个回答
  • 9294 Views

3 个回答

  • Voted
  1. Best Answer
    dev_etter
    2013-05-31T20:49:33+08:002013-05-31T20:49:33+08:00

    这实际上是可以做到的。可能有几种方法可以做到这一点,这里有一个相当简单的例子。对于此解决方案,您将使用以下组合:

    1. 一个 SQL 代理作业,每个需要备份的实例都有一个步骤(即开发服务器、qa 服务器和生产服务器的一个步骤)。
    2. 在作业的每个步骤中调用的一个动态 SSIS 包。
    3. 使用分析管理Execute Script Task对象(AMO)的 。

    创建 SSIS 包

    变量

    变量名|范围|类型

    • 备份目录 | 包级别或 Foreach 级别 | 细绳

    • 数据库ID | 包级别或 Foreach 级别 | 细绳

    • 数据库名称 | 包级别或 Foreach 级别 | 细绳

    • InstanceForDatasource | 包装等级 | 细绳

      • 如果要备份多个实例,则用于 SQL 代理作业的“设置值”选项卡。此变量将用于构建 ConnectionString。
    • 连接字符串 | 包装等级 | 细绳

      • 将 EvaluateAsExpression 属性设置为 true。

      • 如下设置表达式属性:Data Source="+ @[User::InstanceForDatasource] +";Provider=MSOLAP.4;Integrated Security=SSPI;

      • 请注意,此方法可以扩展为使整个 ConnectionString 是动态的,并在必要时由调用 SQL 代理作业步骤指示。

    • XMLAScript | 包或 Foreach 级别 | 细绳

    连接管理器

    在设计时使用真正的连接,以便元数据播放得很好。

    现在不需要创建连接管理器,但它使以后更容易。对于流程中的每个任务,您将在下拉列表中获得适当的连接管理器,而无需即时创建任何内容。

    网络

    1. 创建一个使用 Microsoft OLE DB Provider for Analysis Service 的新 ADO.NET 连接管理器
    2. 使用属性表达式编辑器,如下设置 ConnectionString 属性:[User::ConnectionString]

    OLEDB

    1. 创建一个使用 Microsoft OLE DB Provider for Analysis Service 的新 OLEDB 连接管理器
    2. 使用属性表达式编辑器,如下设置 ConnectionString 属性:[User::ConnectionString] + "Format=Tabular;"

    分析服务

    1. 创建新的 Analysis Services 连接
    2. 使用属性表达式编辑器,如下设置 ConnectionString 属性:[User::ConnectionString] = "Impersonation Level=Impersonate;"

    创建 Foreach 容器

    在这里,您将基于 Catalogs 架构行集创建一个 Foreach。这将为我们获取DatabaseName实例中每个数据库的 ,DatabaseName并将 放入其相应的变量中。

    Foreach 容器配置 Foreach 容器变量映射

    创建执行脚本任务

    将脚本设置为使用 Visual Basic。

    如下设置 ReadOnlyVariables 和 ReadWriteVariables:

    • 只读变量:User::ConnectionString,User::DatabaseName,User::InstanceForDatasource
    • 读写变量:User::BackupDir,User::DatabaseId,User::XMLAScript

    编辑脚本

    • 添加对分析管理对象 (AMO) 程序集的引用。

      • 右键单击项目名称(应该是单击编辑脚本时打开的 Visual Studio 窗口中项目资源管理器中最顶部的项目),然后选择添加引用。

      • 添加对 Analysis Services 对象组件的引用。AMO 的 dll 应位于 <SQL Server InstallationDrive>:\Program Files\Microsoft SQL Server\<SQL Server Version>\SDK\Assemblies.

    • 在脚本头中,添加 Imports 语句以使用 AMO:Imports Microsoft.AnalysisServices

    • 将 Public Sub Main() 的内容替换为以下脚本:

      Public Sub Main()
          '
          Dim ASServer As New Microsoft.AnalysisServices.Server()
          Dim AsDatabase As New Microsoft.AnalysisServices.Database
          Dim ASConn As String = ""
          Dim ASDatabaseName As String = ""
          Dim ASDatabaseId As String = ""
      
          'Create a variable that uses the dynamic ConnectionString variable
          ASConn = Dts.Variables("ConnectionString").Value
      
          'What database are we working with in this iteration of the Foreach?
          ASDatabaseName = Dts.Variables("DatabaseName").Value
      
          'Use the Analysis Services AMO to get the DatabaseId for this DatabaseName.
          '   It is necessary to get the DatabaseId because the XMLA backup command requires the DatabaseId,
          '   and if at any point the database is renamed, the DatabaseId will differ from the DatabaseName.
          Try
              'Establish the connection to SSAS.
              ASServer.Connect(ASConn)
      
              'Get the database.
              AsDatabase = ASServer.Databases.FindByName(ASDatabaseName)
      
              '***ONLY IF the EstimatedSize > 0***. 
              ' --> If it is 0, it could be a corrupted database which causes the backup process to stop.
              ' --> In that case, we will leave the DatabaseId variable blank to be a visiblie indicator that the db is corrupt.
              '***ONLY IF the number of cubes > 0***.
              ' --> The databse could be corrupt or backup could hang if there are no cubes.
              If AsDatabase.EstimatedSize > 0 And AsDatabase.Cubes.Count > 0 Then
                  'Get the DatabaseId
                  'Retrieve the DatabaseId from the Databases collection.
                  ASDatabaseId = ASServer.Databases.FindByName(ASDatabaseName).ID
              Else
                  Dts.Events.FireWarning(0, "Verifying database", "The estimated size and/or number of cubes in the database does not meet the requirements. Estimated Size= " & AsDatabase.EstimatedSize & "; " & "Number of cubes= " & AsDatabase.Cubes.Count, String.Empty, 0)
              End If
          Catch ex As Exception
              'Couldn't connect. Do not error out because maybe the next iteration will succeed.
              Dts.Events.FireWarning(0, "Establishing SSAS Connection", "Unable to connect to the SSAS Server with ConnectionString= '" & ASConn & "'. Error: " & ex.ToString, String.Empty, 0)
          End Try
      
          'Print info for output while testing/debugging.
          Dts.Events.FireInformation(0, "Establishing SSAS Connection", "Connection established. ConnectionString= '" & ASConn & "'.", String.Empty, 0, True)
      
          'Put the DatabaseId into the SSIS variable. 
          Dts.Variables("DatabaseId").Value = ASDatabaseId
      
          'If we were able to retrieve the DatabaseId, then generate the backup directory and filename and the XMLA script.
          If ASDatabaseId <> "" Then
      
              'Print info for output while testing/debugging.
              Dts.Events.FireInformation(0, "Retrieving DatabaseId", "DatabaseId retrieved for " & ASDatabaseName & ". DatabaseId= '" & ASDatabaseId & "'.", String.Empty, 0, True)
      
              'Get timestamp for the backup file
              Dim timeStamp As String = Now.Year & _
                                          Right("0" & Now.Month, 2) & _
                                          Right("0" & Now.Day, 2) & _
                                          Right("0" & Now.Hour, 2) & _
                                          Right("0" & Now.Minute, 2) & _
                                          Right("0" & Now.Second, 2)
      
              'Get the filename and location for the backupfile
              Dim filePath As String = "\\<servershare>\" & Dts.Variables("ServerForDatasource").Value & "\" & ASDatabaseName
              Dim fileName As String = ASDatabaseName & "_" & timeStamp & ".abf"
      
              'Put the filepath into the SSIS variable
              Dts.Variables("BackupDir").Value = filePath
      
              'Print info for output while testing/debugging
              Dts.Events.FireInformation(0, "Retrieving full backup path", "BackupPath= '" & filePath & "\" & fileName & "'.", String.Empty, 0, True)
      
              'Build XMLA script
              Dim xmlaScript As String = ""
              xmlaScript = "<Backup xmlns=""http://schemas.microsoft.com/analysisservices/2003/engine"">" & _
                                  "<Object><DatabaseID>" & ASDatabaseId & "</DatabaseID></Object>" & _
                                  "<File>" & filePath & "\" & fileName & "</File>" & _
                              "</Backup>"
      
              'Put the XMLA script into the SSIS variable
              Dts.Variables("XMLAScript").Value = xmlaScript
      
              'Print info for output while testing/debugging.
              Dts.Events.FireInformation(0, "Generate XMLAScript", "XMLAScript= '" & xmlaScript & "'.", String.Empty, 0, True)
          Else
              'Print info for output while testing/debugging.
              'If DatabaseId is empty, we will not perform the rest of the tasks in the Foreach container.
              Dts.Events.FireWarning(0, "Retrieving DatabaseId", "Unable to retrieve the DatabaseId for Database= '" & ASDatabaseName & "'.", String.Empty, 0)
          End If
      
          ' Return success
          Dts.TaskResult = ScriptResults.Success
      End Sub
      

    创建文件系统任务(创建备份目录)

    UseDirectoryIfExists如果备份目录已经存在,设置为true避免错误很重要。

    文件系统任务编辑器

    编辑执行脚本任务和文件系统任务之间的优先约束

    此优先约束将处理缺少的 DatabaseId。如果无法在 vbscript 中建立与 SSAS 服务器的连接,或者数据库已损坏,则 DatabaseId 将丢失。您不想备份损坏的数据库。它将使备份停止。

    优先约束编辑器

    表达式示例:`@[User::DatabaseId] !=""

    创建 Analysis Services 执行 DDL 任务

    分析服务 DDL 任务

    您的最终控制流应如下所示:

    最终控制流程


    创建 SQL 代理作业

    1. 为要备份的每个 SSAS 实例添加一个步骤。
    2. 每个步骤都应配置为执行 SSIS 包。
    3. 对于每个步骤,单击设置值选项卡并将值设置InstanceForDatasource为步骤的实例名称。
      • 的示例语法Property Path:\Package.Variables[User::InstanceForDatasource].Properties[Value]
      • (有关使用“设置值”选项卡的更多信息)

    笔记:

    • 要使整个备份目录动态化,您只需为此添加另一个变量并在 vbscript 中说明它。

    • 同样,如有必要,整个连接字符串变量可以由 SQL 代理作业设置,而不仅仅是实例名称。

    • 9
  2. Kin Shah
    2013-06-01T12:11:02+08:002013-06-01T12:11:02+08:00

    另一种选择是 Powershell SQL Server Analysis Services Backup in Powershell

    • 1
  3. Marcello Miorelli
    2014-12-02T04:44:46+08:002014-12-02T04:44:46+08:00

    我在没有任何 SSIS 的情况下实现了这一点。我改用链接服务器。我花了一些时间,但我仍然相信这是备份 SSAS 数据库的最佳方式。

    你可以在这个链接上看到我是如何做到的。

    我还删除了旧的备份文件,你可以在这个链接上看到。

    • 0

相关问题

  • SQL Server 备份策略的优缺点及其合适的使用场景

  • 更改了 max_allowed_pa​​cket 并仍然收到“数据包太大”错误

  • SQL Server Express 的任务计划程序

  • 我可以在使用数据库后激活 PITR 吗?

  • Oracle 中的数据库备份 - 导出数据库还是使用其他工具?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    授予用户对所有表的访问权限

    • 5 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    pedrosanta 使用 psql 列出数据库权限 2011-08-04 11:01:21 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve