将 Azure 存储用于 SQL Server 备份和还原Use Azure Storage for SQL Server Backup and Restore

概述Overview

从 SQL Server 2012 SP1 CU2 开始,已可将 SQL Server 备份直接写入 Azure Blob 存储服务中。Starting with SQL Server 2012 SP1 CU2, you can now write SQL Server backups directly to the Azure Blob storage service. 可以使用此功能将数据从本地 SQL Server 数据库或 Azure 虚拟机中的 SQL Server 数据库备份到 Azure Blob 服务或从中进行还原。You can use this functionality to back up to and restore from the Azure Blob service with an on-premises SQL Server database or a SQL Server database in an Azure virtual machine. 备份到云具有以下优点,即,实现可用性、无地域复制场外存储限制,以及可以轻松将数据迁移到云和从云中迁移数据。Backup to cloud offers benefits of availability, limitless geo-replicated off-site storage, and ease of migration of data to and from the cloud. 可以使用 Transact-SQL 或 SMO 来发布 BACKUP 或 RESTORE 语句。You can issue BACKUP or RESTORE statements by using Transact-SQL or SMO.

SQL Server 2016 引入了新功能;可以使用文件快照备份来执行几乎实时的备份和极其快速的还原。SQL Server 2016 introduces new capabilities; you can use file-snapshot backup to perform nearly instantaneous backups and incredibly quick restores.

本主题说明为何可以选择使用 Azure 存储进行 SQL 备份,并介绍了相关的组件。This topic explains why you might choose to use Azure storage for SQL backups and then describes the components involved. 可以使用本文结尾所提供的资源来访问演练和其他信息,以开始搭配 SQL Server 备份来使用此服务。You can use the resources provided at the end of the article to access walkthroughs and additional information to start using this service with your SQL Server backups.

使用 Azure Blob 服务执行 SQL Server 备份的优点Benefits of Using the Azure Blob Service for SQL Server Backups

备份 SQL Server 时,会面临多项挑战。There are several challenges that you face when backing up SQL Server. 这些挑战包括存储管理、存储故障产生的风险、访问场外存储以及硬件配置。These challenges include storage management, risk of storage failure, access to off-site storage, and hardware configuration. 这些挑战当中许多都是通过使用 Azure Blob 存储服务进行 SQL Server 备份来解决的。Many of these challenges are addressed by using the Azure Blob store service for SQL Server backups. 请考虑以下好处:Consider the following benefits:

  • 易用性:在 Azure Blob 中存储备份非常方便、灵活且可轻松访问场外存储。Ease of use: Storing your backups in Azure blobs can be a convenient, flexible, and easy to access off-site option. 为 SQL Server 备份创建场外存储就像修改现有脚本/作业以使用 BACKUP TO URL 语法一样简单。Creating off-site storage for your SQL Server backups can be as easy as modifying your existing scripts/jobs to use the BACKUP TO URL syntax. 场外存储通常应当远离生产数据库位置,以防止某个灾难可能同时影响场外和生产数据库位置。Off-site storage should typically be far enough from the production database location to prevent a single disaster that might impact both the off-site and production database locations. 通过选择异地复制 Azure blob,可以在发生可能影响整个区域的灾难时进一步加强保护。By choosing to geo-replicate your Azure blobs, you have an extra layer of protection in the event of a disaster that could affect the whole region.
  • 备份存档:对备份进行存档时,Azure Blob 存储服务提供可替代常用磁带存储方式的更好方式。Backup archive: The Azure Blob Storage service offers a better alternative to the often used tape option to archive backups. 选择磁带存储时可能需要将数据实际运输到场外设施,并且需要采取一些介质保护措施。Tape storage might require physical transportation to an off-site facility and measures to protect the media. 在 Azure Blob 存储中存储备份可提供即时、具有高可用性且持久的存档方式。Storing your backups in Azure Blob Storage provides an instant, highly available, and a durable archiving option.
  • 受管理的硬件:使用 Azure 服务没有硬件管理开销。Managed hardware: There is no overhead of hardware management with Azure services. Azure 服务可管理硬件并提供地域异地复制和硬件故障防护。Azure services manage the hardware and provide geo-replication for redundancy and protection against hardware failures.
  • 无限制的存储:通过启用直接备份到 Azure Blob,可以访问几乎无限的存储。Unlimited storage: By enabling a direct backup to Azure blobs, you have access to virtually unlimited storage. 或者,还可以选择备份到 Azure 虚拟机磁盘,所受的限制取决于计算机的大小。Alternatively, backing up to an Azure virtual machine disk has limits based on machine size. 只能将有限数量的磁盘附加到用于备份的 Azure 虚拟机。There is a limit to the number of disks you can attach to an Azure virtual machine for backups. 对特大实例的限制为 16 个磁盘;对较小实例的磁盘限制数更少。This limit is 16 disks for an extra large instance and fewer for smaller instances.
  • 备份可用性:存储在 Azure Blob 中的备份可随时从任何位置使用,并可供轻松访问以还原到本地 SQL Server 或运行于 Azure 虚拟机中的其他 SQL Server,而无需进行数据库附加/分离或者下载和附加 VHD。Backup availability: Backups stored in Azure blobs are available from anywhere and at any time and can easily be accessed for restores to either an on-premises SQL Server or another SQL Server running in an Azure Virtual Machine, without the need for database attach/detach or downloading and attaching the VHD.
  • 成本:只需为所使用的服务付费。Cost: Pay only for the service that is used. 作为场外和备份存档方式可能更加划算。Can be cost-effective as an off-site and backup archive option. 有关详细信息,请参阅 Azure 定价计算器Azure 定价文章See the Azure pricing calculator, and the Azure Pricing article for more information.
  • 存储快照:如果数据库文件存储在 Azure Blob 中并且使用的是 SQL Server 2016,则可以使用文件快照备份来执行几乎实时的备份和极其快速的还原。Storage snapshots: When database files are stored in an Azure blob and you are using SQL Server 2016, you can use file-snapshot backup to perform nearly instantaneous backups and incredibly quick restores.

有关更多详细信息,请参阅使用 Azure Blob 存储服务执行 SQL Server 备份和还原For more details, see SQL Server Backup and Restore with Azure Blob Storage Service.

接下来两节介绍 Azure Blob 存储服务,包括必要的 SQL Server 组件。The following two sections introduce the Azure Blob storage service, including the required SQL Server components. 若要从 Azure Blob 存储服务成功进行备份和还原,一定要了解这些组件及其交互。It is important to understand the components and their interaction to successfully use backup and restore from the Azure Blob storage service.

Azure Blob 存储服务组件Azure Blob Storage Service Components

备份到 Azure Blob 存储服务时,会使用以下 Azure 组件。The following Azure components are used when backing up to the Azure Blob storage service.

组件Component 说明Description
存储帐户Storage Account 存储帐户是所有存储服务的起点。The storage account is the starting point for all storage services. 若要访问 Azure Blob 存储服务,请先创建一个 Azure 存储帐户。To access an Azure Blob Storage service, first create an Azure Storage account. 有关 Azure Blob 存储服务的详细信息,请参阅如何使用 Azure Blob 存储服务For more information about Azure Blob storage service, see How to use the Azure Blob Storage Service
容器Container 容器提供一组 Blob 集,并且可存储无限数量的 Blob。A container provides a grouping of a set of blobs, and can store an unlimited number of Blobs. 要将 SQL Server 备份写入到 Azure Blob 服务,必须创建至少一个根容器。To write a SQL Server backup to an Azure Blob service, you must have at least the root container created.
BlobBlob 任何类型和大小的文件。A file of any type and size. 可使用以下 URL 格式对 Blob 进行寻址:https://[storage account].blob.core.chinacloudapi.cn/[container]/[blob]Blobs are addressable using the following URL format: https://[storage account].blob.core.chinacloudapi.cn/[container]/[blob]. 有关页 Blob 的详细信息,请参阅了解块 Blob 和页 BlobFor more information about page Blobs, see Understanding Block and Page Blobs

SQL Server 组件SQL Server Components

备份到 Azure Blob 存储服务时,会使用以下 SQL Server 组件。The following SQL Server components are used when backing up to the Azure Blob storage service.

组件Component 说明Description
URLURL URL 指定到唯一备份文件的统一资源标识符 (URI)。A URL specifies a Uniform Resource Identifier (URI) to a unique backup file. URL 用于提供 SQL Server 备份文件的位置和名称。The URL is used to provide the location and name of the SQL Server backup file. URL 必须指向实际 blob,而不是仅指向容器。The URL must point to an actual blob, not just a container. 如果 blob 不存在,则创建一个。If the blob does not exist, it is created. 如果指定了现有 blob,除非指定了 > WITH FORMAT 选项,否则 BACKUP 将失败。If an existing blob is specified, BACKUP fails, unless the > WITH FORMAT option is specified. 以下是在 BACKUP 命令中指定的 URL 示例:http[s]://[存储帐户].blob.core.chinacloudapi.cn/[容器]/[文件名.bak]The following is an example of the URL you would specify in the BACKUP command: http[s]://[storageaccount].blob.core.chinacloudapi.cn/[container]/[FILENAME.bak]. HTTPS 不是必需的,但建议使用它。HTTPS is recommended but not required.
凭据Credential 连接到 Azure Blob 存储服务并通过其进行身份验证所需的信息将存储为凭据。The information that is required to connect and authenticate to Azure Blob storage service is stored as a Credential. 为了使 SQL Server 将备份写入 Azure Blob 或从中进行还原,必须创建 SQL Server 凭据。In order for SQL Server to write backups to an Azure Blob or restore from it, a SQL Server credential must be created. 有关详细信息,请参阅 SQL Server 凭据For more information, see SQL Server Credential.

Note

SQL Server 2016 已更新以支持块 blob。Sql Server 2016 has been updated to support block blobs. 有关详细信息,请参阅教程:将 Azure Blob 存储服务用于 SQL Server 2016 数据库Please see Tutorial: Using the Azure Blob storage service with SQL Server 2016 databases for more details.

后续步骤Next steps

  1. 创建 Azure 帐户(如果还没有帐户)。Create an Azure account if you don't already have one. 如果你正在评估 Azure,请考虑使用试用版If you are evaluating Azure, consider the trial.

  2. 接着,完成以下教程之一,这些教程会引导创建存储帐户以及执行还原。Then go through one of the following tutorials that walk you through creating a storage account and performing a restore.

  3. 查看其他文档,从使用 Azure Blob 存储服务进行 SQL Server 备份和还原开始。Review additional documentation starting with SQL Server Backup and Restore with Azure Blob Storage Service.

如果有任何问题,请查看 SQL Server 备份到 URL 最佳实践和故障排除主题。If you have any problems, review the topic SQL Server Backup to URL Best Practices and Troubleshooting.

有关其他 SQL Server 备份和还原选项,请参阅 Azure 虚拟机中 SQL Server 的备份和还原For other SQL Server backup and restore options, see Backup and Restore for SQL Server in Azure Virtual Machines.