完整数据库备份Create a Full Database Backup

09/12/2019

本文内容

适用于:Applies to: SQL ServerSQL Server(所有支持的版本)SQL ServerSQL Server (all supported versions)适用于:Applies to: SQL ServerSQL Server(所有支持的版本)SQL ServerSQL Server (all supported versions)

本主题说明如何使用 SQL ServerSQL Server 、 SQL Server Management StudioSQL Server Management Studio或 PowerShell 在 Transact-SQLTransact-SQL中创建完整数据库备份。This topic describes how to create a full database backup in SQL ServerSQL Server using SQL Server Management StudioSQL Server Management Studio, Transact-SQLTransact-SQL, or PowerShell.

限制和局限Limitations and restrictions

不允许在显式或隐式事务中使用 BACKUP 语句。The BACKUP statement is not allowed in an explicit or implicit transaction.

无法在早期版本的 SQL ServerSQL Server 中还原较新版本的 SQL ServerSQL Server创建的备份。Backups created by more recent version of SQL ServerSQL Server cannot be restored in earlier versions of SQL ServerSQL Server.

有关备份概念和任务的概述和详细信息,请在继续操作前先参阅备份概述 (SQL Server)。For an overview of, and deeper dive into, backup concepts and tasks, see Backup Overview (SQL Server) before proceeding.

建议Recommendations

随着数据库不断增大,完整数据库备份的完成时间会延长,并且需要占用更多存储空间。As a database increases in size, full database backups take more time to complete and require more storage space. 对于大型数据库,请考虑用一系列差异数据库备份来补充完整数据库备份。For large databases, consider supplementing full database backups with a series of differential database backups.

使用 sp_spaceused 系统存储过程估计完整数据库备份的大小。Estimate the size of a full database backup by using the sp_spaceused system stored procedure.

默认情况下,每个成功的备份操作都会在 SQL ServerSQL Server 错误日志和系统事件日志中添加一个条目。By default, every successful backup operation adds an entry in the SQL ServerSQL Server error log and in the system event log. 若频繁备份,这些成功消息会迅速累积,从而生成巨大的错误日志!If you back up frequently, these success messages will accumulate quickly, resulting in huge error logs! 这会使查找其他消息变得非常困难。This can make finding other messages difficult. 在这些情况下,如果脚本均不依赖于这些备份日志条目,则可使用跟踪标志 3226 取消这些条目。In such cases, you can suppress these backup log entries by using trace flag 3226 if none of your scripts depend on those entries. For more information, see Trace Flags (Transact-SQL).

SecuritySecurity

针对数据库备份,TRUSTWORTHY 设置为 OFF 。TRUSTWORTHY is set to OFF on a database backup. For information about how to set TRUSTWORTHY to ON, see ALTER DATABASE SET Options (Transact-SQL).

从 SQL Server 2012 (11.x)SQL Server 2012 (11.x) 开始,PASSWORD 和 MEDIAPASSWORD 选项不再可用于创建备份 。Beginning with SQL Server 2012 (11.x)SQL Server 2012 (11.x), the PASSWORD and MEDIAPASSWORD options are discontinued for creating backups. 不过,您仍可以还原使用密码创建的备份。You can still restore backups created with passwords.

权限Permissions

默认情况下,为 sysadmin 固定服务器角色以及 db_owner 和 db_backupoperator 固定数据库角色的成员授予 BACKUP DATABASE 和 BACKUP LOG 权限 。BACKUP DATABASE and BACKUP LOG permissions default to members of the sysadmin fixed server role and the db_owner and db_backupoperator fixed database roles.

备份设备的物理文件的所有权和权限问题可能会妨碍备份操作。Ownership and permission problems on the backup device's physical file can interfere with a backup operation. SQL ServerSQL Server 服务必须能够读取和写入设备,这意味着运行 SQL ServerSQL Server 服务的帐户必须对备份设备具有写入权限。The SQL ServerSQL Server service must be able to read and write to the device which means that the account under which the SQL ServerSQL Server service runs must have write permissions to the backup device. 但是,用于在系统表中为备份设备添加项目的 sp_addumpdevice不检查文件访问权限。However, sp_addumpdevice, which adds an entry for a backup device in the system tables, does not check file access permissions. 因此,除非你因尝试备份或还原而访问物理资源,否则可能看不到备份设备物理文件中的这些问题。As a result, problems on the backup device's physical file may not appear until the physical resource is accessed when the backup or restore is attempted.

使用 SQL Server Management StudioUsing SQL Server Management Studio

备注

使用 SQL Server Management StudioSQL Server Management Studio 指定备份任务时,可以通过单击“脚本”按钮并选择脚本目标生成相应的 Transact-SQLTransact-SQL BACKUP 脚本 。When you specify a backup task by using SQL Server Management StudioSQL Server Management Studio, you can generate the corresponding Transact-SQLTransact-SQL BACKUP script by clicking the Script button and selecting a script destination.

连接到相应的 MicrosoftMicrosoft SQL Server 数据库引擎SQL Server Database Engine 实例之后,在“对象资源管理器”中,展开服务器树 。After connecting to the appropriate instance of the MicrosoftMicrosoft SQL Server 数据库引擎SQL Server Database Engine, in Object Explorer, expand the server tree.

展开“数据库”,选择用户数据库,或展开“系统数据库”,选择系统数据库。Expand Databases, and either select a user database or expand System Databases and select a system database.

右键单击要备份的数据库,指向“任务”,再单击“备份...” 。Right-click the database that you wish to backup, point to Tasks, and then click Back Up....

在“备份数据库”对话框中,所选的数据库显示在下拉列表中(可将其更改为服务器上的任何其他数据库) 。In the Back Up Database dialog box, the database that you selected appears in the drop-down list (which you can change to any other database on the server).

在“备份类型”下拉列表中,选择所需的备份类型,默认值为“完整” 。In the Backup type drop-down list, select the desired backup type - the default is Full.

重要

必须先至少执行一个完整数据库备份,然后才能执行差异备份或事务日志备份。You must perform at least one full database backup before you can perform a differential or a transaction log backup.

在“备份组件”下,选择“数据库” 。Under Backup component, select Database.

在“目标”部分中,查看备份文件的默认位置(位于 ../mssql/data 文件夹) 。In the Destination section, review the default location for the backup file (in the ../mssql/data folder).

要备份到其他设备,请使用“备份到”下拉列表更改选择 。To backup to a different device, change the selection using the Back up to drop-down list. 要跨多个文件条带化备份集来提高备份速度,请单击“添加”,添加其他备份对象和/或目标 。To stripe the backup set across multiple files for increased backup speed, click Add to add additional backup objects and/or destinations.

若要删除备份目标,请选择该备份目标并单击 “删除” 。To remove a backup destination, select it and click Remove. 若要查看现有备份目标的内容,请选择该备份目标并单击“内容”。To view the contents of an existing backup destination, select it and click Contents.

(可选)查看“介质选项”和“备份选项”页面下的其他可用设置 。(optional) Review the other available settings under the Media Options and Backup Options pages.

要详细了解各种备份选项,请参阅常规页、介质选项页和备份选项页。For more information about the various backup options, see General page, Media options page, and Backup options page.

单击“确定”,启动备份 。Click OK to initiate the backup.

备份成功完成后,单击“确定”,关闭“SQL Server Management Studio”对话框 。When the backup completes successfully, click OK to close the SQL Server Management Studio dialog box.

其他信息Additional information

创建完整数据库备份后,可以创建差异数据库备份或事务日志备份。After creating a full database backup, you can create a differential database backup or a transaction log backup.

还可以选择“仅复制备份”复选框创建仅复制备份 。(optional) You can select the Copy-only backup checkbox to create a copy-only backup. 仅复制备份 是SQL ServerSQL Server独立于常规备份序列SQL ServerSQL Server的备份。A copy-only backup is a SQL ServerSQL Server backup that is independent of the sequence of conventional SQL ServerSQL Server backups. 仅复制备份不可用于 差异 备份类型。A copy-only backup is not available for the Differential backup type.

如果要备份到 URL,请禁用“介质选项”页上的“覆盖介质”选项 。The Overwrite media option is disabled on the Media Options page if you are backing up to a URL.

示例Examples

对于以下示例,使用以下 Transact-SQL 代码创建测试数据库:For the following examples, create a test database with the following Transact-SQL code:

USE [master]

GO

CREATE DATABASE [SQLTestDB]

GO

USE [SQLTestDB]

GO

CREATE TABLE SQLTest

(

ID INT NOT NULL PRIMARY KEY,

c1 VARCHAR(100) NOT NULL,

dt1 DATETIME NOT NULL DEFAULT getdate()

);

GO

USE [SQLTestDB]

GO

INSERT INTO SQLTest (ID, c1) VALUES (1, 'test1')

INSERT INTO SQLTest (ID, c1) VALUES (2, 'test2')

INSERT INTO SQLTest (ID, c1) VALUES (3, 'test3')

INSERT INTO SQLTest (ID, c1) VALUES (4, 'test4')

INSERT INTO SQLTest (ID, c1) VALUES (5, 'test5')

GO

SELECT * FROM SQLTest

GO

A.A. 完整备份到默认位置的磁盘Full back up to disk to default location

在此示例中,将 SQLTestDB 数据库备份到默认备份位置处的磁盘。In this example, the SQLTestDB database will be backed up to disk at the default backup location.

连接到相应的 MicrosoftMicrosoft SQL Server 数据库引擎SQL Server Database Engine 实例之后,在“对象资源管理器”中,展开服务器树 。After connecting to the appropriate instance of the MicrosoftMicrosoft SQL Server 数据库引擎SQL Server Database Engine, in Object Explorer, expand the server tree.

展开“数据库” ,右键单击 SQLTestDB,然后指向“任务” ,再单击“备份...” 。Expand Databases, right-click SQLTestDB, point to Tasks, and then click Back Up....

单击“确定”。Click OK.

备份成功完成后,单击“确定”,关闭“SQL Server Management Studio”对话框 。When the backup completes successfully, click OK to close the SQL Server Management Studio dialog box.

B.B. 完整备份到非默认位置的磁盘Full back up to disk to non-default location

在此示例中,将 SQLTestDB 数据库备份到所选位置处的磁盘。In this example, the SQLTestDB database will be backed up to disk at a location of your choice.

连接到相应的 MicrosoftMicrosoft SQL Server 数据库引擎SQL Server Database Engine 实例之后,在“对象资源管理器”中,展开服务器树 。After connecting to the appropriate instance of the MicrosoftMicrosoft SQL Server 数据库引擎SQL Server Database Engine, in Object Explorer, expand the server tree.

展开“数据库” ,右键单击 SQLTestDB,然后指向“任务” ,再单击“备份...” 。Expand Databases, right-click SQLTestDB, point to Tasks, and then click Back Up....

在“常规”页的“目标”部分中,从“备份到:”下拉列表中选择“磁盘”。On the General page in the Destination section select Disk from the Back up to: drop-down list.

选择“删除”,直到所有现有备份文件均已删除 。Select Remove until all existing backup files have been removed.

选择“添加”,这将打开“选择备份目标”对话框 。Select Add and the Select Backup Destination dialog box will open.

在“文件名”文本框中输入有效的路径和文件名,并使用 .bak 作为扩展名,以简化此文件的分类 。Enter a valid path and file name in the File name text box and use .bak as the extension to simplify the classification of this file.

单击“确定”,然后再次单击“确定”,启动备份 。Click OK and then click OK again to initiate the backup.

备份成功完成后,单击“确定”,关闭“SQL Server Management Studio”对话框 。When the backup completes successfully, click OK to close the SQL Server Management Studio dialog box.

C.C. 创建加密备份Create an encrypted backup

在此示例中,将已加密的 SQLTestDB 数据库备份到默认备份位置。In this example, the SQLTestDB database will be backed up with encryption to the default backup location.

连接到相应的 MicrosoftMicrosoft SQL Server 数据库引擎SQL Server Database Engine 实例之后,在“对象资源管理器”中,展开服务器树 。After connecting to the appropriate instance of the MicrosoftMicrosoft SQL Server 数据库引擎SQL Server Database Engine, in Object Explorer, expand the server tree.

展开“数据库”,展开“系统数据库”,右键单击 master,然后单击“新建查询”,打开连接到 SQLTestDB 数据库的查询窗口 。Expand Databases, expand System Databases, right-click master, and click New Query to open a query window with a connection to your SQLTestDB database.

执行以下命令,在 master 数据库中创建数据库主密钥和证书 。Execute the following commands to create a database master key and a certificate within the master database.

-- Create the master key

CREATE MASTER KEY ENCRYPTION BY PASSWORD = '23987hxJ#KL95234nl0zBe';

-- If the master key already exists, open it in the same session that you create the certificate (see next step)

OPEN MASTER KEY DECRYPTION BY PASSWORD = '23987hxJ#KL95234nl0zBe'

-- Create the certificate encrypted by the master key

CREATE CERTIFICATE MyCertificate

WITH SUBJECT = 'Backup Cert', EXPIRY_DATE = '20201031';

在对象资源管理器的“数据库”节点中,右键单击 SQLTestDB,然后指向“任务”,再单击“备份...” 。In Object Explorer, in the Databases node, right-click SQLTestDB, point to Tasks, and then click Back Up....

在“介质选项”页的“覆盖介质”部分中,选择“备份到新介质集并清除所有现有备份集” 。On the Media Options page, in the Overwrite media section select Back up to a new media set, and erase all existing backup sets.

在“备份选项”页的“加密”部分中,选择“加密备份”复选框。On the Backup Options page in the Encryption section select the Encrypt backup check box.

从“算法”下拉列表中选择 AES 256 。From the Algorithm drop-down list, select AES 256.

从“证书”或“非对称密钥”下拉列表中选择 MyCertificate。From the Certificate or Asymmetric key drop-down list select MyCertificate.

选择“确定” 。Select OK.

D.D. 备份到 Azure Blob 存储服务Back up to the Azure Blob storage service

以下示例对 Azure Blob 存储服务执行完整的 SQLTestDB 数据库备份。The example below performs a full database backup of SQLTestDB to the Azure Blob storage service. 此示例假设你已有一个具有 blob 容器的存储帐户。This example assumes that you already have a storage account with a blob container. 此示例会创建一个共享访问签名;如果容器具有现有的共享访问签名,此示例会失败。This example creates a shared access signature for you; this example fails of the container has an existing shared access signature.

如果在存储帐户中不具有 Azure blob 容器,请先创建一个,然后再继续操作。If you do not have an Azure blob container in a storage account, create one before continuing.

连接到相应的 MicrosoftMicrosoft SQL Server 数据库引擎SQL Server Database Engine 实例之后,在“对象资源管理器”中,展开服务器树 。After connecting to the appropriate instance of the MicrosoftMicrosoft SQL Server 数据库引擎SQL Server Database Engine, in Object Explorer, expand the server tree.

展开“数据库” ,右键单击 SQLTestDB,然后指向“任务” ,再单击“备份...” 。Expand Databases, right-click SQLTestDB, point to Tasks, and then click Back Up....

在“目标” 部分中的“常规” 页上,从“备份到:” 下拉列表中选择“URL”On the General page in the Destination section select URL from the Back up to: drop-down list.

单击“添加” “选择备份目标” 对话框。Click Add and the Select Backup Destination dialog box will open.

如果以前已注册要与 SQL Server Management Studio 配合使用的 Azure 存储容器,请选择该容器。If you have previously registered the Azure storage container that you wish to use with SQL Server Management Studio, select it. 否则,单击“新建容器”,注册新的容器 。Otherwise, click New container to register a new container.

在“连接到 Microsoft 订阅”对话框中,登录你的帐户 。In the Connect to a Microsoft Subscription dialog box, sign in to your account.

在“选择存储帐户”下拉文本框中,选择你的存储帐户 。In the Select Storage Account drop-down text box, select your storage account.

在“选择 Blob 容器”下拉文本框中,选择你的 Blob 容器 。In the Select Blob Container drop-down text box, select your blob container.

在“共享访问策略过期”下拉日历框中,为此示例中创建的共享访问策略选择到期日期 。In the Shared Access Policy Expiration drop-down calendar box, select an expiration date for the shared access policy that you create in this example.

单击“创建凭据”,在 SQL Server Management Studio 中生成共享访问签名和凭据 。Click Create Credential to generate a shared access signature and credential in SQL Server Management Studio.

单击“确定”,关闭“连接到 Microsoft 订阅”对话框 。Click OK close the Connect to a Microsoft Subscription dialog box.

在“备份文件”文本框中,修改备份文件的名称(可选) 。In the Backup File text box, modify the name of the backup file (optional).

单击“确定”,关闭“选择备份目标”对话框 。Click OK to close the Select a backup destination dialog box.

单击“确定”,启动备份 。Click OK to initiate the backup.

备份成功完成后,单击“确定”,关闭“SQL Server Management Studio”对话框 。When the backup completes successfully, click OK to close the SQL Server Management Studio dialog box.

使用 Transact-SQLUsing Transact-SQL

通过执行 BACKUP DATABASE 语句创建完整数据库备份,同时指定:Create a full database backup by executing the BACKUP DATABASE statement to create the full database backup, specifying:

要备份的数据库的名称。The name of the database to back up.

写入完整数据库备份的备份设备。The backup device where the full database backup is written.

完整数据库备份的基本 Transact-SQLTransact-SQL 语法如下:The basic Transact-SQLTransact-SQL syntax for a full database backup is:

BACKUP DATABASE database TO backup_device [ , ...n ] [ WITH with_options [ , ...o ] ] ;BACKUP DATABASE database TO backup_device [ ,...n ] [ WITH with_options [ ,...o ] ] ;

选项Option

说明Description

databasedatabase

要备份的数据库。Is the database that is to be backed up.

backup_device [ , ...n ]backup_device [ ,...n ]

指定一个列表,它包含 1 至 64 个用于备份操作的备份设备。Specifies a list of from 1 to 64 backup devices to use for the backup operation. 您可以指定物理备份设备,也可以指定对应的逻辑备份设备(如果已定义)。You can specify a physical backup device, or you can specify a corresponding logical backup device, if already defined. 若要指定物理备份设备,请使用 DISK 或 TAPE 选项:To specify a physical backup device, use the DISK or TAPE option:

{ DISK | TAPE } = 物理_备份_设备_名称{ DISK | TAPE } =physical_backup_device_name

WITH with_options [ , ...o ]WITH with_options [ ,...o ]

您也可以指定一个或多个附加选项 o。Optionally, specifies one or more additional options, o. 有关某些基本 WITH 选项的信息,请参阅步骤 2。For information about some of the basic with options, see step 2.

(可选)指定一个或多个 WITH 选项 。Optionally, specify one or more WITH options. 下面描述了几个基本 WITH 选项 。A few basic WITH options are described here. 有关所有 WITH 选项的详细信息,请参阅 BACKUP (Transact-SQL) 。For information about all the WITH options, see BACKUP (Transact-SQL).

基本备份集 WITH 选项 :Basic backup set WITH options:

{ COMPRESSION | NO_COMPRESSION } :在 SQL Server 2008 EnterpriseSQL Server 2008 Enterprise 及更高版本中,指定是否为此备份执行 备份压缩 ,该设置将替代服务器级默认设置。{ COMPRESSION | NO_COMPRESSION }: In SQL Server 2008 EnterpriseSQL Server 2008 Enterprise and later only, specifies whether backup compression is performed on this backup, overriding the server-level default.

ENCRYPTION (ALGORITHM, SERVER CERTIFICATE |ASYMMETRIC KEY) :仅在 SQL Server 2014 或更高版本中,指定要使用的加密算法以及要用于保护加密的证书或非对称密钥。ENCRYPTION (ALGORITHM, SERVER CERTIFICATE | ASYMMETRIC KEY): In SQL Server 2014 or later only, specify the encryption algorithm to use, and the Certificate or Asymmetric key to use to secure the encryption.

DESCRIPTION = { ' text ' | @ text_variable }:指定说明备份集的自由格式文本。DESCRIPTION = { 'text' | @text_variable }: Specifies the free-form text that describes the backup set. 该字符串最长可达 255 个字符。The string can have a maximum of 255 characters.

NAME = { backup_set_name | @backup_set_name_var } :指定备份集的名称。NAME = { backup_set_name | @backup_set_name_var }: Specifies the name of the backup set. 名称最长可达 128 个字符。Names can have a maximum of 128 characters. 如果未指定 NAME,它将为空。If NAME is not specified, it is blank.

默认情况下,BACKUP 将备份追加到现有介质集中,并保留现有备份集。By default, BACKUP appends the backup to an existing media set, preserving existing backup sets. 若要显式指定此项,请使用 NOINIT 选项。To explicitly specify this, use the NOINIT option. For information about appending to existing backup sets, see Media Sets, Media Families, and Backup Sets (SQL Server).

或者,若要将备份介质格式化,可以使用 FORMAT 选项 :Alternatively, to format the backup media, use the FORMAT option:

FORMAT [ , MEDIANAME= { media_name | @ media_name_variable } ] [ , MEDIADESCRIPTION = { text | @ text_variable } ]FORMAT [ , MEDIANAME = { media_name | @media_name_variable } ] [ , MEDIADESCRIPTION = { text | @text_variable } ]

当您第一次使用介质或者希望覆盖所有现有数据时可以使用 FORMAT 子句 。Use the FORMAT clause when you are using media for the first time or you want to overwrite all existing data. 根据需要,可以为新介质指定介质名称和说明。Optionally, assign the new media a media name and description.

重要

当使用 BACKUP 语句的 FORMAT 子句时要十分小心,因为它会破坏以前存储在备份介质中的所有备份 。Use extreme caution when you are using the FORMAT clause of the BACKUP statement because this destroys any backups that were previously stored on the backup media.

示例Examples

对于以下示例,使用以下 Transact-SQL 代码创建测试数据库:For the following examples, create a test database with the following Transact-SQL code:

USE [master]

GO

CREATE DATABASE [SQLTestDB]

GO

USE [SQLTestDB]

GO

CREATE TABLE SQLTest (

ID INT NOT NULL PRIMARY KEY,

c1 VARCHAR(100) NOT NULL,

dt1 DATETIME NOT NULL DEFAULT GETDATE()

)

GO

USE [SQLTestDB]

GO

INSERT INTO SQLTest (ID, c1) VALUES (1, 'test1')

INSERT INTO SQLTest (ID, c1) VALUES (2, 'test2')

INSERT INTO SQLTest (ID, c1) VALUES (3, 'test3')

INSERT INTO SQLTest (ID, c1) VALUES (4, 'test4')

INSERT INTO SQLTest (ID, c1) VALUES (5, 'test5')

GO

SELECT * FROM SQLTest

GO

A.A. 备份到磁盘设备Back up to a disk device

下面的示例通过使用 SQLTestDB 创建新的介质集,将整个 FORMAT 数据库备份到磁盘。The following example backs up the complete SQLTestDB database to disk, by using FORMAT to create a new media set.

USE SQLTestDB;

GO

BACKUP DATABASE SQLTestDB

TO DISK = 'c:\tmp\SQLTestDB.bak'

WITH FORMAT,

MEDIANAME = 'SQLServerBackups',

NAME = 'Full Backup of SQLTestDB';

GO

B.B. 备份到磁带设备Back up to a tape device

下面的示例将完整的 SQLTestDB 数据库备份到磁带上,并将该备份追加到以前的备份中。The following example backs up the complete SQLTestDB database to tape, appending the backup to the previous backups.

USE SQLTestDB;

GO

BACKUP DATABASE SQLTestDB

TO TAPE = '\\.\Tape0'

WITH NOINIT,

NAME = 'Full Backup of SQLTestDB';

GO

C.C. 备份到逻辑磁带设备Back up to a logical tape device

下例为某个磁带驱动器创建一个逻辑备份设备,The following example creates a logical backup device for a tape drive. 然后,将完整的 SQLTestDB 数据库备份到该设备上。The example then backs up the complete SQLTestDB database to that device.

-- Create a logical backup device,

-- SQLTestDB_Bak_Tape, for tape device \\.\tape0.

USE master;

GO

EXEC sp_addumpdevice 'tape', 'SQLTestDB_Bak_Tape', '\\.\tape0'; USE SQLTestDB;

GO

BACKUP DATABASE SQLTestDB

TO SQLTestDB_Bak_Tape

WITH FORMAT,

MEDIANAME = 'SQLTestDB_Bak_Tape',

MEDIADESCRIPTION = '\\.\tape0',

NAME = 'Full Backup of SQLTestDB';

GO

使用 PowerShellUsing PowerShell

使用 Backup-SqlDatabase cmdlet。Use the Backup-SqlDatabase cmdlet. 若要显式指示这是完整数据库备份,请使用其默认值 Database 指定 -BackupAction 参数 。To explicitly indicate that this is a full database backup, specify the -BackupAction parameter with its default value, Database. 对于完整数据库备份而言,此参数是可选的。This parameter is optional for full database backups.

备注

这些示例需要安装 SqlServer 模块。These examples require the SqlServer module. 要确定是否已安装该模块,请运行 Get-Module -Name SqlServer。To determine if it is installed, run Get-Module -Name SqlServer. 要安装此模块,请在 PowerShell 的管理员会话中运行 Install-Module -Name SqlServer。To install this module, run Install-Module -Name SqlServer in an administrator session of PowerShell.

重要

如果从 SQL Server Management Studio 中打开 PowerShell 窗口来连接到 SQL Server 的安装,则可省略此示例的凭据部分,因为 SSMS 中的凭据会自动用于建立 PowerShell 和 SQL Server 实例之间的连接。If you are opening a PowerShell window from within SQL Server Management Studio to connect to an installation of SQL Server, you can omit the credential portion of this example as your credential in SSMS is automatically used to establish the connection between PowerShell and your SQL Server instance.

示例Examples

A.A. 完整备份(本地)Full backup (local)

下面的示例在服务器实例 的默认备份位置创建数据库 Computer\Instance的完整数据库备份。The following example creates a full database backup of the database to the default backup location of the server instance Computer\Instance. 此示例也可以指定 -BackupAction Database。Optionally, this example specifies -BackupAction Database.

For the full syntax and additional examples, see Backup-SqlDatabase.

$credential = Get-Credential

Backup-SqlDatabase -ServerInstance Computer[\Instance] -Database -BackupAction Database -Credential $credential

B.B. 完整备份到 AzureFull backup to Azure

下面的示例在 实例上向 Azure Blob 存储服务创建 数据库的完整备份。The following example creates a full backup of the database on the instance to the Azure Blob Storage service. 已经创建具有读取、写入和表权限的存储访问策略。A stored access policy has been created with read, write, and list rights. 已使用与存储访问策略相关联的共享访问签名创建 SQL Server 凭据 https://.blob.core.windows.net/ 。The SQL Server credential, https://.blob.core.windows.net/, was created using a Shared Access Signature that is associated with the Stored Access Policy. PowerShell 命令使用 BackupFile 参数指定位置 (URL) 和备份文件名。The PowerShell command uses the BackupFile parameter to specify the location (URL) and the backup file name.

$credential = Get-Credential

$container = 'https://blob.core.windows.net/'

$fileName = '.bak'

$server = ''

$database = ''

$backupFile = $container + '/' + $fileName

Backup-SqlDatabase -ServerInstance $server -Database $database -BackupFile $backupFile -Credential $credential

Related tasksRelated tasks

另请参阅See also

mysql2005备份_创建完整数据库备份 - SQL Server | Microsoft Docs相关推荐

  1. sql server java类型_使用基本 JDBC 数据类型 - SQL Server | Microsoft Docs

    使用基本数据类型Using basic data types 01/29/2021 本文内容 Microsoft JDBC Driver for SQL ServerMicrosoft JDBC Dr ...

  2. access里的多步oledb错误_(ADO) 的 ConnectionString 属性 - SQL Server | Microsoft Docs

    ConnectionString 属性 (ADO)ConnectionString Property (ADO) 01/19/2017 本文内容 指示用于建立与数据源的连接的信息.Indicates ...

  3. mysql表收缩时从库也收缩么_收缩数据库 - SQL Server | Microsoft Docs

    收缩数据库Shrink a Database 03/14/2017 本文内容 适用于:Applies to: SQL ServerSQL Server(所有支持的版本)SQL ServerSQL Se ...

  4. mysql 增量备份_云计算-开源数据库-备份

    关于备份: 备份原因:怕丢,怕被误删. 备份目标:数据的一致性,服务的可用性. 备份技术:物理备份/冷备份 直接复制数据库文件,适用于大型数据库环境,不受存储引擎的限制,但不能恢复到不同的MySQL版 ...

  5. 京东云mysql镜像_京东云数据库RDS SQL Server高可用概述

    数据库的高可用是指在硬件.软件故障发生时,可以将业务从发生故障的数据库节点迁移至备用节点.本文主要讲述SQL Server高可用方案,以及京东云RDS数据库的高可用实现. 一.高可用解决方案总览 1. ...

  6. 文件菜单服务器属性,服务器属性(“数据库设置”页) - SQL Server | Microsoft Docs...

    服务器属性 -"数据库设置"页 05/23/2019 本文内容 适用于: SQL Server(所有支持的版本) 使用此页可以查看或修改数据库设置. 选项 默认索引填充因子 指定在 ...

  7. java sql 查询中的转义序列不对_在 JDBC 中使用 SQL 转义序列 - SQL Server | Microsoft Docs...

    使用 SQL 转义序列Using SQL escape sequences 08/12/2019 本文内容 按照 JDBC API 的定义,Microsoft JDBC Driver for SQL ...

  8. python pymssql安装_步骤 1:配置 pymssql 环境 - SQL Server | Microsoft Docs

    步骤 1:配置用于 pymssql Python 开发的开发环境Step 1: Configure development environment for pymssql Python develop ...

  9. 修改服务器操作系统后sql2008出错,报告操作系统错误 1450 和 665 - SQL Server | Microsoft Docs...

    数据库文件在 DBCC CHECKDB 或数据库快照创建期间报告操作系统错误 1450 和 665 09/25/2020 本文内容 本文帮助您解决在数据库文件创建或数据库快照创建期间报告操作系统错误 ...

最新文章

  1. VC 文件操作(文件查找,打开/保存,读/写,复制/删除/重命名)
  2. Win Srv 2012 R2 RDS移动RDS客户端
  3. 什么?口红输给口罩了?
  4. 远程登录-出现身份验证错误[可能是由于CredSSP加密Oracle修正]
  5. 编程题【Math类】计算类
  6. 干货收藏!Python完整代码带你一文看懂抽样
  7. JavaScript 演练(8). 对象成员、类成员(原型、非原型)
  8. 一些javascript的经验 (3)
  9. Setup Factory 9 Trial使用
  10. 微信小程序 图片处理的几个样式
  11. gltf、glb模型下载
  12. 56个民族静态字典代码创建sql语句
  13. CCS 报警告 #10247-D
  14. 如何在Linux终端查询修改主机名、以及主机名与ip的映射关系?
  15. MySQL内置函数中的日期和时间函数详解
  16. Response设置响应数据功能介绍及重定向
  17. 此身, 此时, 此地
  18. 为Android刷机包签名
  19. 聚合二维码生成(小程序二维码、付款码)
  20. 蓝牙BLE之DA1469x的应用

热门文章

  1. dataset的去重计数 g2_去互联网公司面试,面试官问我SpringCloud,附答案
  2. RocketMQ 介绍 msgId生成算法
  3. 多路复用 I/O 模型详解, 为什么他能支持更高的并发
  4. 4行代码,让app自动化框架支持 webview 混合应用操作
  5. 非标自动化企业前十名_非标自动化设计:非标自动化是如何被称做企业里的血液?...
  6. Java泛型之mybatis,基于spring MVC 和 MyBatis 泛型的代码生成模板
  7. java自动化开发_Java自动化开发指南
  8. php mysql两个表合并_php操作mysql两个数据库中表的数据同步
  9. java中位数_JAVA中位数排序
  10. 获取地区html代码,根据ip地址获取所在城市信息(省市县)代码