如何使用PSDatabaseClone设置基于图像SQL Server数据库配置

This article will provide information about requirements and step-by-step instructions on how to set up automated image based database provisioning including configuring the host environment to fulfilling basic requirements.

本文将提供有关要求的信息,以及有关如何设置基于映像的自动数据库设置的逐步说明,包括配置主机环境以满足基本要求。

To begin, here is the list of items that would be required on premise:

首先,这是前提条件所需的项目清单:

  • Hyper-V PowerShell module to allow virtual disk creation, detection and mounting functionality

    Hyper-V PowerShell模块,允许创建,检测和安装虚拟磁盘功能
  • PSDatabaseClone PowerShell module with accompanying dependent modules PSFramework and dbatools PSDatabaseClone PowerShell模块以及随附的从属模块PSFramework和dbatools
  • Dedicated local folder with share enabled to assign network path for the folder where database images will be created and stored

    启用共享的专用本地文件夹可为将在其中创建和存储数据库映像的文件夹分配网络路径
  • Local folder to store database clones

    用于存储数据库克隆的本地文件夹

安装Hyper-V PowerShell模块 (Installing the Hyper-V PowerShell module)

Installation of the Windows Hyper-V PowerShell module is very straightforward. Open the Windows Control Panel and from the listed items open Programs and Features item. Select Turn Windows features on or off option and from the Windows Features window check the Hyper-V module for Windows PowerShell item and confirm with OK.

Windows Hyper-V PowerShell模块的安装非常简单。 打开Windows 控制面板,然后从列出的项目中打开“ 程序和功能”项目。 选择“ 打开或关闭Windows功能”选项,然后从“ Windows功能”窗口中检查Windows PowerShellHyper-V模块项,然后单击“确定”进行确认

Hyper-V Module for Windows PowerShell

安装PSDatabaseClone PowerShell模块 (Installing the PSDatabaseClone PowerShell module)

The PSDatabaseClone utility is available in Microsoft PowerShell gallery and it can be installed directly from it.

PSDatabaseClone实用程序在Microsoft PowerShell画廊中可用,可以直接从中安装。

To start the installation, open the PowerShell console with administrative privileges and use the following command:

要开始安装,请使用管理特权打开PowerShell控制台,然后使用以下命令:

Install-Module PSDatabaseClone

Depending on local PowerShell configuration, after the command execution, it is possible to receive a message that PowerShell gallery was not set as trusted installation repository. To proceed with installation, confirm with “Y” end press enter.

根据本地PowerShell配置,在执行命令后,可能会收到一条消息,提示PowerShell画廊未设置为受信任的安装存储库。 要继续安装,请以“ Y”端确认并按Enter。

PSDatabaseClone module installation

Along with the PSDatabaseClone module, a couple of dependent modules will be automatically installed so the utility could work properly. The modules in question are PSFramework and dbatools. To verify the installation, use the command:

与PSDatabaseClone模块一起,将自动安装几个依赖的模块,以便实用程序可以正常工作。 有问题的模块是PSFramework和dbatools。 要验证安装,请使用以下命令:

Get-InstalledModule

The console should list all required modules with their version numbers and descriptions:

控制台应列出所有必需的模块及其版本号和说明:

PowerShell required modules

Also, the list of available PSDatabaseClone cmdlets can be obtained with the command:

另外,可用PSDatabaseClone cmdlet的列表可通过以下命令获取:

Get-Command -Module PSDatabaseClone

PSDatabaseClone installed cmdlets

After installation, PSDatabaseClone will require some additional configuration. This utility will require an information repository where information about database images, image hosts, and database clones are going to be stored.

安装后,PSDatabaseClone将需要一些其他配置。 该实用程序将需要一个信息存储库,用于存储有关数据库映像,映像主机和数据库克隆的信息。

To start configuration, use the following command:

要开始配置,请使用以下命令:

Set-PSDCConfiguration

The execution of this command will prompt to choose the type of repository that will be used for collected data about images.

该命令的执行将提示您选择用于收集有关图像数据的存储库类型。

PSDatabaseClone configuration

This can be a dedicated database or a set of JSON files. Choose preferred option but note that it is not recommended for the data to be stored in JSON files as they could be prone to accidental corruption (for example removing, renaming or deleting the parenting folder).

这可以是专用数据库或一组JSON文件。 选择首选选项,但请注意,不建议将数据存储在JSON文件中,因为它们可能会意外损坏(例如,删除,重命名或删除育儿文件夹)。

设置JSON配置 (Setting up the JSON configuration)

Choose the JSON type data by entering “J” in the prompted line. Next prompt will ask for location for JSON files. Enter full path to the folder where JSON files will be stored and make sure that this is an existing folder.

在提示的行中输入“ J”,选择JSON类型数据。 下一个提示将询问JSON文件的位置。 输入将存储JSON文件的文件夹的完整路径,并确保该文件夹是现有文件夹。

PSDatabaseClone JSON configuration

With path confirmation the prompt will ask for login credentials. These will be required in case location folder requires authorized access for the user in the current Windows session (e.g. network share). Enter credentials or omit them if not needed and PowerShell will prompt messages about successful configuration.

使用路径确认,提示将询问登录凭据。 如果位置文件夹在当前Windows会话中需要对用户的授权访问(例如,网络共享),则需要使用这些文件。 输入凭据或在不需要时忽略它们,PowerShell将提示有关成功配置的消息。

PSDatabaseClone JSON configuration

It is expected that JSON configuration files will appear at the designated location.

预计JSON配置文件将出现在指定位置。

PSDatabaseClone JSON configuration files

设置数据库配置 (Setting up the database configuration)

Choose the database type data by typing “D” in the prompted line or just confirm with “Enter” as it is default choice. The setup will prompt for SQL Server name, this will be the name of the SQL Server instance where database containing collected image data will be attached on.

通过在提示行中键入“ D”来选择数据库类型数据,或者只需使用“ Enter”进行确认即可,因为这是默认选择。 安装程序将提示您输入SQL Server名称,这将是SQL Server实例的名称,包含收集到的图像数据的数据库将附加到该SQL Server实例上。

PSDatabaseClone SQL database  configuration

After the SQL Server name, the prompt will ask for the database name. Confirm with “Enter” to accept offered default name “PSDatabaseClone” or type in another name that will help easily identify the designated database.

在SQL Server名称之后,提示将要求输入数据库名称。 使用“ Enter”确认以接受提供的默认名称“ PSDatabaseClone”,或键入其他名称,这将有助于轻松识别指定的数据库。

PSDatabaseClone SQL database name

With the database name set the SQL Server connection credentials can be entered. Naturally, if Windows authentication method is used these credentials can be omitted, otherwise provide proper username and password for SQL Authentication method. Again, after these steps PowerShell will prompt messages about successful configuration.

设置数据库名称后,可以输入SQL Server连接凭据。 自然,如果使用Windows身份验证方法,则可以省略这些凭据,否则为SQL身份验证方法提供正确的用户名和密码。 同样,在执行完这些步骤后,PowerShell将提示有关成功配置的消息。

PSDatabaseClone SQL database  configuration

Verification that the PSDatabaseClone repo database is created can be simply done with SSMS where it should be listed in Object Explorer with its given name.

可以使用SSMS来简单地验证是否创建了PSDatabaseClone存储库,该数据库应以给定名称在Object Explorer中列出。

PSDatabaseClone SQL database

设置输出文件夹 (Setting the output folders)

PSDatabaseClone and inherently ApexSQL DevOps toolkit Provision step will require designated locations for database images and clones.

PSDatabaseClone和固有的ApexSQL DevOps工具包“设置”步骤将需要为数据库映像和克隆指定位置。

Location for database images will have to be a local shared folder as Provision step is designed to work with UNC paths to store created database images and it is valid assumption that database provisioning will be performed across a network infrastructure so images will have to be available through network share.

数据库映像的位置必须是本地共享文件夹,因为Provisioning步骤旨在与UNC路径一起使用来存储创建的数据库映像,并且可以合理地假设将在整个网络基础结构中执行数据库配置,因此必须通过网络共享。

The screenshot below shows the example for standard local folder that was provided with network path using simple file sharing:

下面的屏幕截图显示了使用简单文件共享通过网络路径提供的标准本地文件夹的示例:

Database images shared folder

When share of the designated folder is set and active it is necessary to set certain access permissions. The reason for that is the fact that SQL Server would have to write data in that folder and therefore will have to have writing permissions which does not have by default.

设置并激活指定文件夹的共享后,有必要设置某些访问权限。 这样做的原因是,SQL Server必须在该文件夹中写入数据,因此必须具有默认情况下没有的写入权限。

To set proper permission open the Properties window from the folder right-click context menu, open the Security tab and then click Edit.

要设置适当的权限,请从文件夹的右键单击上下文菜单中打开“ 属性”窗口,打开“ 安全性”选项卡,然后单击“ 编辑”

Database images shared folder security settings

The window for editing permissions for security objects will open from where the Add… button should be clicked to add new object and set permissions for it.

将打开安全对象编辑权限的窗口,应单击“ 添加...”按钮以添加新对象并为其设置权限。

Database images shared folder permissions settings

What is required now is to add a security principal that will allow writing to SQL Server. One option is to add “Authenticated Users” security principal which represents a scope of sessions authenticated by some account, like SQL Server active service session.

现在需要添加一个安全主体,该主体将允许写入SQL Server。 一种选择是添加“认证用户”安全主体,该主体代表由某个帐户认证的会话范围,例如SQL Server活动服务会话。

Authenticated Users added

If there is a need to limit access to the sherd folder, it would be enough just to add the same login account that was used for starting the SQL Server service.

如果需要限制对sherd文件夹的访问,仅添加用于启动SQL Server服务的登录帐户就足够了。

SQL Server service account added

Confirm the addition of new security object and make sure that it was granted full control of the shared folder.

确认添加了新的安全对象,并确保已授予该共享文件夹完全控制权。

Shared Folder Permissions

The final element for Provision step configuration is a location where database clones will be stored. This is a folder where virtual disks that hosts database clone will be created and from there attached to target SQL Server. There is no special requirement for this folder, this is simply one chosen local dedicated folder with an easily recognizable name.

Provisioning步骤配置的最后一个元素是将存储数据库克隆的位置。 这是一个文件夹,将在其中创建用于承载数据库克隆的虚拟磁盘,并从那里将其附加到目标SQL Server。 此文件夹没有特殊要求,这只是一个选定的本地专用文件夹,其名称易于识别。

翻译自: https://www.sqlshack.com/how-to-setup-image-based-sql-server-database-provisioning-with-psdatabaseclone/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值