本文共 11632 字,大约阅读时间需要 38 分钟。
This article discusses the concept of SQL Server backup and the various components required to use the Microsoft Azure Blob storage service as a target for the backup. As we all know, disk and tapes were the default destinations of choice until the evolution of the cloud platform. In addition to this, now we can expand the native functionality of SQL Server backup to cloud storage; the Windows Azure Blob storage. This functionality was added first in SQL Server 2012. In general, backup and restore functionality to and from the cloud are similar to using disk or tape, with very few differences.
本文讨论了SQL Server备份的概念以及使用Microsoft Azure Blob存储服务作为备份目标所需的各种组件。 众所周知,在云平台发展之前,磁盘和磁带是默认的选择目的地。 除此之外,现在我们可以将SQL Server备份的本机功能扩展到云存储。 Windows Azure Blob存储。 此功能是在SQL Server 2012中首先添加的。通常,与云之间的备份和还原功能与使用磁盘或磁带相似,差别很小。
SQL Server database Backup to Azure Blob Storage is a process designed to perform almost like a backup device, such as disk or tape. During the backup or restore process, a URL is selected as a “device type” which in turn triggers a VDI (Virtual Backup Device Interface) client process. The process acts as an intermediary agent to send the database backup to the Azure Blob Storage.
SQL Server数据库到Azure Blob存储的备份是一个旨在像磁盘或磁带之类的备份设备一样执行的过程。 在备份或还原过程中,将URL选择为“设备类型”,这又会触发VDI(虚拟备份设备接口)客户端过程。 该过程充当中介代理,以将数据库备份发送到Azure Blob存储。
In this article we touch base on the following topics:
在本文中,我们基于以下主题进行探讨:
Before we perform the database backup, it’s important to understand the Blob Storage Service and SQL Server key components, and their concepts. To start, let’s do a little prep work to setup Microsoft Azure Create an Azure Storage account. In the first step, we create a storage account at the Azure Portal. Using the Blob Storage Service, we configure the Azure Blob Storage Container.
在执行数据库备份之前,了解Blob存储服务和SQL Server关键组件及其概念非常重要。 首先,让我们做一些准备工作来设置Microsoft Azure创建Azure存储帐户。 第一步,我们在Azure门户上创建一个存储帐户。 使用Blob存储服务,我们配置Azure Blob存储容器。
Next, let’s review the SQL Server components.
接下来,让我们回顾一下SQL Server组件。
Now, we can go over to SQL Server and start working on creating the credentials that will be used to authenticate into the Azure account. In the New query window, use CREATE CREDENTIAL to create credential.
现在,我们可以转到SQL Server并开始着手创建将用于向Azure帐户进行身份验证的凭据。 在“新建查询”窗口中,使用CREATE CREDENTIAL创建凭据。
The Identity property is the name of the storage account. In this case, it is sqlshackdemo.
Identity属性是存储帐户的名称。 在这种情况下,它是sqlshackdemo 。
The Access key is the secret key of the storage account. To find the access key, click on Settings and select Access keys in the Storage account blade. To the right, you should fine key1, which is the access key, select the Copy to clipboard icon. Save this key information somewhere safe. The syntax to create to credential is as follows:
访问密钥是存储帐户的秘密密钥。 要找到访问密钥,请单击“ 设置” ,然后在存储帐户刀片中选择访问密钥 。 在右侧,您应该选择key1 (这是访问键),然后选择Copy to剪贴板图标。 将此密钥信息保存在安全的地方。 创建凭证的语法如下:
IF NOT EXISTS (SELECT * FROM sys.credentials WHERE name = '') CREATE CREDENTIAL ] WITH IDENTITY = ' ' ,SECRET = ' ';
IF NOT EXISTS (SELECT * FROM sys.credentials WHERE name = 'SQLShackDemoCredential')CREATE CREDENTIAL SQLShackDemoCredentialWITH IDENTITY='sqlshackdemo', SECRET='NEIb+nrJSaZOQ+e8XKX0R+obWdX85InXKtuS8yAQ/L4Osx2uht/UnQM6eqqO89Pu7JY8EyWePbP/lDy5UviXCg=='
Now, Prepare the T-SQL to backup the database to the URL using blob storage account service and the access key. The following example initiates a full database backup of the SQLShackDemoATC database to the blob storage (URL+Storage+Container+filename).
现在,准备T-SQL以使用blob存储帐户服务和访问密钥将数据库备份到URL。 以下示例将SQLShackDemoATC数据库的完整数据库备份启动到Blob存储(URL + Storage + Container +文件名)。
BACKUP DATABASE SQLShackDemoATC TO URL = 'https://sqlshackdemo.blob.core.windows.net/sqlshackbackupdemo/SQLShackDemoATC.bak' WITH CREDENTIAL = 'SQLShackDemoCredential' ,COMPRESSION ,STATS = 5;
Validate the output by browsing the blob storage. We can see that the SQLShackDemoATC.bak file exists at the storage. We can browse the URL of the file and this pointer is used in the upcoming section to restore the database.
通过浏览Blob存储来验证输出。 我们可以看到存储中存在SQLShackDemoATC.bak文件。 我们可以浏览文件的URL,在接下来的部分中将使用此指针来还原数据库。
For the demo, I will be restoring the SQLShackDemoATC with a different name SQLShackDemoATC_Clone to the same SQL instance.
对于该演示,我将使用不同名称SQLShackDemoATC_Clone还原SQLShackDemoATC到同一SQL实例。
RESTORE DATABASE SQLShackDemoATC_Clone FROM URL = 'https://sqlshackdemo.blob.core.windows.net/sqlshackbackupdemo/SQLShackDemoATC.bak' WITH MOVE 'SQLShackDemoATC' to 'f:\PowerSQL\SQLShackDemoATC_Clone.mdf' ,MOVE 'SQLShackDemoATC_log' to 'f:\PowerSQL\SQLShackDemoATC_CloneLog.ldf' ,NORECOVERY ,REPLACE ,STATS = 5; GO
The following output shows that the database was restored and with the same number of tables as the source database. This proves that the restoration of the database was successful.
以下输出显示该数据库已还原,并且具有与源数据库相同的表数。 这证明数据库还原成功。
Perform Database backup task using SSMS (SQL Server Management Studio)
使用SSMS执行数据库备份任务(SQL Server Management Studio)
In the Object Explorer, browse the Databases, right-click on the database, go to Tasks, and then click Back Up…
在对象资源管理器中,浏览数据库 ,右键单击数据库,转到“ 任务” ,然后单击“备份…”。
On the General page, go to the Destination section. At the Back up to: drop-down list, select URL, and then click Add. This will open the Select Backup Destination dialog box
在“ 常规”页面上,转到“ 目标”部分。 在“ 备份到:”下拉列表中,选择“ URL” ,然后单击“ 添加” 。 这将打开“ 选择备份目标位置”对话框
Click on New container. This will open a Connect to Microsoft Subscription page.
单击新容器 。 这将打开“ 连接到Microsoft订阅”页面。
At the Select Storage Account drop down, select the storage account. In this case, it’s sqlshackdemo.
在“ 选择存储帐户”下拉列表中,选择存储帐户。 在这种情况下,它是sqlshackdemo 。
In a similar way go to Select Blob Container, and choose sqlshackbackupdemo
以类似的方式转到Select Blob Container ,然后选择sqlshackbackupdemo
Click on OK.
单击确定。
The next screen shows the progress of the backup.
下一个屏幕显示备份进度。
The last screen displays a message stating that the backup was successful.
最后一个屏幕显示一条消息,指出备份已成功。
We can see that the backup file was written to the blob storage. This shows us that the backup can also be taken using SSMS.
我们可以看到备份文件已被写入Blob存储。 这表明我们也可以使用SSMS进行备份。
Next, this lets us demonstrate the steps to perform database backup to URL using PowerShell.
接下来,这使我们演示了使用PowerShell执行将数据库备份到URL的步骤。
This section provides the PowerShell scripts to automate the database backup using the available PowerShell cmdlets.
本节提供了PowerShell脚本,以使用可用的PowerShell cmdlet自动执行数据库备份。
#List the Credential detail$credentialName = "SQLShackDemoCredential" # define the backup file location URL+Storage+Container+filename$backupFile = "https://sqlshackdemo.blob.core.windows.net/sqlshackbackupdemo/ProdSQLShackDemo.bak" # Initiate Backup using backup-sqldatabase cmdlet to URLBackup-SqlDatabase -ServerInstance hqdbt01\sql2017 -Database "ProdSQLShackDemo" -backupFile $backupFile -SqlCredential $credentialName -CompressionOption ON
The three different ways to back-up the database to URL have been explained with examples using SSMS, T-SQL and PowerShell.
使用SSMS,T-SQL和PowerShell的示例已说明了将数据库备份到URL的三种不同方法。
SQL Server Database backup and restore operations using the Cloud |
使用CloudSQL Server数据库备份和还原操作 |
翻译自:
转载地址:http://dsiwd.baihongyu.com/