欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

程序员文章站 2022-07-10 17:18:19
...

Often as consultants, we don’t get to work onsite alongside our clients instead we are given copies of clients’ production environment and work on proposed solutions back at our offices. Once development has been completed, we then deploy and integrate our solution back to the client’s production environment. I’ve recently had to adopt a similar offsite development approach whilst working on a project that included development and configuration of master data services. In this article, I will demonstrate how a SQL Server 2017 Master Data Services (MDS) model can be exported from one environment (i.e. MDS Dev) and deployed into another environment (i.e. MDS Prod).

通常,作为顾问,我们不需要与客户一起在现场工作,而是获得客户生产环境的副本,并在我们的办公室工作以提出建议的解决方案。 一旦开发完成,我们便将解决方案部署并集成回客户的生产环境。 我最近在从事一个包含主数据服务的开发和配置的项目时,不得不采用类似的异地开发方法。 在本文中,我将演示如何从一个环境(即MDS Dev)导出SQL Server 2017主数据服务(MDS)模型并将其部署到另一个环境(即MDS Prod)中。

背景 (Background)

For the purposes of this demonstration, I have setup two MDS environments within a single server. As per the list of sites shown in my IIS server in Figure 1, the MDS web application simulates my development environment whilst MDSPROD is a production application.

为了演示的目的,我在单个服务器上设置了两个MDS环境。 根据图1中 IIS服务器中显示的站点列表, MDS Web应用程序模拟了我的开发环境,而MDSPROD是生产应用程序。

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

The MDS development application contains a single model which in turn contains a single entity called Free Products Entity. A preview of the data stored in Free Products Entity is shown in Figure 2.

MDS开发应用程序包含一个模型,该模型又包含一个称为“ 免费产品实体”的实体。 *产品实体中存储的数据预览如图2所示。

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

At this point, the MDS production environment has no existing models as shown in Figure 3.

此时,MDS生产环境没有如图3所示的现有模型。

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

使用GUI的MDS模型部署 (MDS Model Deployment using GUI)

Migration of MDS models can be done using either a GUI-like interface or through the windows command prompt application. We start off by looking at the GUI option.

MDS模型的迁移可以使用类似于GUI的界面或通过Windows命令提示符应用程序来完成。 我们首先查看GUI选项。

Step 1: Export MDS Model into a Package file

步骤1:将MDS模型导出到包文件中

The deployment using the GUI is browser-based and relies on the MDS web application. We begin by navigating to the System Administration option as indicated in Figure 4.

使用GUI进行的部署是基于浏览器的,并且依赖于MDS Web应用程序。 首先,导航到“ 系统管理”选项, 如图4所示

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

Clicking on System Administration will redirect you to the Manage Models page. We next navigate and click to the Deployment sub-menu as shown in Figure 5.

单击系统管理会将您重定向到“ 管理模型”页面。 接下来,我们导航并单击Deployment子菜单, 如图5所示。

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

This will bring up a Model Deployment Wizard, click on the Create option as indicated in Figure 6.

这将弹出一个模型部署向导 ,单击Create选项, 如图6所示

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

You will next be redirected to the Create Package section wherein you will be expected to specify the MDS model you want to export – in my case, that will be ApexSQL Products.

接下来,您将被重定向到Create Package部分,在其中您将需要指定要导出的MDS模型-在我的情况下,将是ApexSQL Products

Click the Next button to export and create an MDS model package file.

单击下一步按钮以导出并创建MDS模型包文件。

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

Clicking the Finish button will conclude the package file creation process. All you need to do next is to click the Download button so to download and save a copy of the package file you’ve just created.

单击完成按钮将结束软件包文件的创建过程。 接下来要做的就是单击“ 下载”按钮,以便下载并保存刚创建的软件包文件的副本。

Step 2: Import MDS Package into an MDS instance

步骤2:将MDS包导入到MDS实例

Having successfully exported our MDS model into a package file, we next navigate to our MDS production web application and import the package file. We do this by firstly navigating and clicking to the System Administration option as per Figure 4.

成功将MDS模型导出到打包文件后,接下来我们导航到MDS生产Web应用程序并导入打包文件。 为此,我们首先按照图4导航并单击“ 系统管理”选项。

We then click on Deployment sub-menu as per Figure 5. This will result in the Model Deployment Wizard coming up but this time we click on Deploy as shown in Figure 8.

然后,根据图5单击Deployment子菜单。 这将导致出现Model Deployment Wizard ,但是这次我们单击Deploy如图8所示。

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

We are then redirected to Deploy Package window wherein we click the Browse button and specify the path to our package file.

然后,我们将重定向到“ 部署软件包”窗口,在其中单击“ 浏览”按钮并指定软件包文件的路径。

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

After clicking Next and Finish buttons, the Model Deployment Wizard will be closed and a subsequent page refresh of the MDS production web application should bring up the newly imported MDS model as shown in Figure 10.

单击“ 下一步”和“ 完成”按钮后,将关闭“ 模型部署向导” ,随后MDS生产Web应用程序的页面刷新将调出新导入的MDS模型, 如图10所示。

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

Limitation of the GUI Deployment Option

GUI部署选项的限制

Most administrators of SQL Server-based applications such as MDS prefer administration of such applications through a GUI-like interface. Whilst such a practice could be sufficient in carrying out most of the administration related tasks, the migration of an MDS model from one server to another using a GUI doesn’t migrate all required objects, lets alone data. Figure 11 gives us a production preview of the Free Products Entity which was migrated using the steps above. You will notice that unlike the development copy (shown in Figure 2), the migrated version in a production environment is missing all the data. Furthermore, the subscription views that were created in development environment are missing in the production version.

大多数基于SQL Server的应用程序(例如MDS)的管理员都喜欢通过类似于GUI的界面来管理此类应用程序。 尽管这种做法足以执行大多数与管理相关的任务,但是使用GUI将MDS模型从一台服务器迁移到另一台服务器并不能迁移所有必需的对象,更不用说数据了。 图11为我们提供了使用上述步骤迁移的免费产品实体的生产预览。 您会注意到,与开发副本(如图2所示)不同,生产环境中的迁移版本会丢失所有数据。 此外,生产版本中缺少在开发环境中创建的订阅视图。

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

使用Windows命令行进行MDS部署 (MDS Deployment using Windows Command Line)

We can get around the issue of missing data and subscription views prevalent in the GUI approach by turning to scripting using a windows command prompt to perform MDS Model migration. Similarly, to the GUI approach, command line approach is a two-step process that involves exporting of a given MDS model into a package file and then later importing that package file into another MDS server.

通过使用Windows命令提示符执行脚本来执行MDS模型迁移,我们可以解决GUI方法中普遍存在的数据丢失和订阅视图丢失的问题。 类似地,对于GUI方法,命令行方法是一个两步过程,涉及将给定的MDS模型导出到程序包文件中,然后将该程序包文件导入另一个MDS服务器中。

Step 1: Generate MDS Package containing Entity Data

步骤1:生成包含实体数据的MDS包

To get started, we first need to launch windows command prompt program in administrator mode. We then change the working directory to wherever the MDSModelDeploy.exe application is stored – in my case, the location is: C:\Program Files\Microsoft SQL Server\140\Master Data Services\Configuration as shown in Figure 12.

首先,我们首先需要在管理员模式下启动Windows命令提示符程序。 然后,将工作目录更改为MDSModelDeploy.exe应用程序存储的位置–在我的情况下,位置为: C:\ Program Files \ Microsoft SQL Server \ 140 \ Master Data Services \ Configuration如图12所示。

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

Similar to SQL Server applications such as Reporting Services and Analysis Services, several instances of MDS can be configured and run at the same time on one machine. Thus, part of migrating MDS models using windows command prompt involves identifying a list of currently configured services linked to MDS instances. Consequently, in this demonstration, we next run the listservices method to retrieve a list of existing MDS services within a given server. The results of calling the listservices method is shown in Figure 13, and as it can be seen, my demo box has two instances of MDS currently installed; MDS1 for MDS Development website as well as MDS2 for the production instance.

与诸如Reporting Services和Analysis Services之类SQL Server应用程序类似,可以配置MDS的多个实例并在一台计算机上同时运行它们。 因此,使用Windows命令提示符迁移MDS模型的一部分涉及标识链接到MDS实例的当前配置服务的列表。 因此,在此演示中,我们接下来运行listservices方法以检索给定服务器内现有MDS服务的列表。 调用listservices方法的结果如图13所示,可以看到,我的演示框中有两个当前安装的MDS实例。 用于MDS开发网站的MDS1以及用于生产实例的MDS2

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

The last part in this section involves the actual creation of a package file by calling the createpacakge method. As shown in Figure 14. The createpackage method has several mandatory parameters that need to be supplied and provided you have supplied correct parameter values, package creation via command prompt should be successful.

本节的最后一部分涉及通过调用createpacakge方法实际创建一个包文件。 如图14所示。 createpackage方法有几个必需参数,需要提供这些参数,并且如果您提供了正确的参数值,则通过命令提示符创建软件包的操作应该成功。

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

Finally, Figure 15 shows two MDS packages that were created using the GUI and command prompt program, respectively. Not surprisingly, the size of the package created using windows command prompt is larger at 16KB compared to the other package. This is because as part of creating this package we opted to include data and its related objects.

最后, 图15显示了分别使用GUI和命令提示符程序创建的两个MDS包。 毫不奇怪,与其他软件包相比,使用Windows命令提示符创建的软件包的大小更大,为16KB 。 这是因为在创建此程序包的过程中,我们选择了包含数据及其相关对象。

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

Step 2: Import MDS Package into an MDS instance

步骤2:将MDS包导入到MDS实例

The MDSModelDeploy utility has three main methods for deploying an MDS package file into an MDS instance. The main methods are deployclone, deployupdate, and deploynew. For the purposes of this demo, I have opted for the deploynew method which will result in a new model being created into a target server. The complete command for deploying an MDS model is shown in Script 1.

MDSModelDeploy实用程序具有三种主要方法,可用于将MDS包文件部署到MDS实例中。 主要方法是deployclonedeployupdatedeploynew 。 在此演示中,我选择了deploynew方法,这将导致在目标服务器中创建一个新模型。 脚本1中显示了用于部署MDS模型的完整命令。

MDSModelDeploy deploynew -model "ApexSQL Products" -service MDS2 -package "C:\Users\Administrator\Downloads\ApexSQLProducts.pkg"

Once we have successfully executed Script 1, the newly deployed MDS model should appear in the target server as shown in Figure 16. Notice, however, that every data entry in Free Products Entity begins with a question mark. This is used to indicate that although the MDS model was successfully deployed with data, you still need to go through the data and validate it.

成功执行脚本1之后 ,新部署的MDS模型应出现在目标服务器中, 如图16所示。 但是请注意, 免费产品实体中的每个数据条目都以问号开头。 这用于表明尽管MDS模型已成功部署了数据,但是您仍然需要遍历数据并进行验证。

如何将SQL Server 2017主数据服务模型迁移到另一台服务器

摘要 (Summary)

In this article, we have gone through two main approaches for migrating an MDS model from one server to another. The GUI approach is convenient but has several limitations. On the other hand, the command line approach gives you full control and further enables you to include data as part of model deployments.

在本文中,我们经历了两种将MDS模型从一台服务器迁移到另一台服务器的主要方法。 GUI方法很方便,但是有一些限制。 另一方面,命令行方法使您可以完全控制,并进一步使您能够将数据包括在模型部署中。

参考资料 (References)

翻译自: https://www.sqlshack.com/how-to-migrate-sql-server-2017-master-data-services-models-into-another-server/