mssqlServer 数据库备份和还原认识和总结(二)
本文将针对上文继续进行数据备份和还原讲解,主要讲解备份和还原的一些关键选项。
数据库备份选项
备份数据库时,有几个备份选项需要了解一下,覆盖介质、事务日志等。谈到覆盖介质时,必须先对这个概念有所了解,不然无从谈起。
● 介质集 (media set):备份介质(磁带或磁盘文件)的有序集合,使用固定类型和数量的备份设备向其写入了一个或多个备份操作。介质集所使用的备份设备的数量决定了介质集中的介质簇的数量。 例如,如果介质集使用两个非镜像备份设备,则该介质集包含两个介质簇。通常,创建介质集后,后续备份操作将依次向介质集追加其备份集。
● 介质簇 (media family):在介质集中的单个非镜像设备或一组镜像设备上创建的备份。
● 备份集 (backup set):成功的备份操作将向介质集中添加一个备份集。
大致了解以上概念后,回到备份选项上来:
◆ 备份到现有介质集-追加到现有备份集
如果要将数据库备份到磁盘上,那么选择磁盘后(可以选择一个或多个磁盘驱动器,也可选择磁带机设备,在此以磁盘驱动器为例),如果保持默认【备份到现有介质集-追加到现有备份集】SQL Server将自动创建一个介质集(备份介质(磁盘文件或磁带)的每个卷都包含介质标头,介质标头是在第一次使用磁带(或磁盘)执行备份操作时创建的,它将包含介质的名称、介质集的唯一标识号、介质簇的唯一标识号等等),然后再将备份集添加到介质集中。例如上篇文章中首次完整备份,SQL Server将自动创建一个介质集,并将备份集添加到介质集中,接着再备份事务日志文件,此事务日志文件备份集将被追加到现有备份集,最终备份文件我们看到的只是一个备份文件MyTest.bak,但还原时选择此文件后,要还原的备份集列表将显示先后备份的备份集,如完整备份集、第一次事务日志备份集、第二次事务日志备份集等。
◆ 备份到现有介质集-覆盖所有现有备份集
此选项将覆盖介质上的所有备份集并保留介质标头(如果有)。 如果没有介质标头,则创建一个标头。覆盖备份时,保留现有的所有介质标头,同时将新的备份创建为备份设备中的第一个备份。
存在下列任一条件时不覆盖备份介质:
● 介质上的现有备份尚未过期。 (如果指定 SKIP,则不检查过期。)
过期日期将指定备份过期的日期,并可以由另一个备份覆盖。 创建备份时可以指定过期日期。 默认情况下,过期日期由使用 sp_configure 设置的 media retention 选项确定。
● 介质名称(如果有)与备份介质上的名称不匹配。
● 介质名称是一个描述性名称,用于方便地识别介质。
综上所述,它们的最大区别是,一个是向现在备份集追加备份集,一个是将现有备份集覆盖,即以前保存在该备份集里的信息将无法重新读取。
图1:备份时选择【追加到现有备份集】,还原时要还原的备份集里显示的,每次追加的备份集。
图2:备份时选择【覆盖所有现有备份集】,还原时要还原的备份集里显示的是已覆盖的备份集,以前追加的备份集已被覆盖。
◆ 检查介质集名称和备份集过期时间
图3:备份时输入的备份集名称和备份集过期时间,一般备份集默认会带有名称,如有必要可以修改为有意义的名称,过期时间一般保持默认永不过程。
有了上图,【检查介质集名称和备份集过期时间】里就明白该如何输入了,这个我没实验过,没有太大必要一一实验了。
◆ 备份到新介质集并清除所有现有备份集
选择此项可以清除以前的备份集,并使用新的媒体集备份数据库。
若要创建新介质集,必须格式化备份介质(一个或多个磁带或磁盘文件)。 格式化进程会对备份介质进行以下更改:
● 删除旧标头(如果存在),从而有效地删除备份介质中以前的内容。
格式化磁带设备会删除当前装入的磁带中以前所有内容。 格式化磁盘只影响您为备份操作指定的文件。
● 向每个备份设备中的备份介质(磁带或磁盘文件)写入新的介质标头。
◆ 可靠性
● 完成后验证备份。将会验证备份集是否完整以及所有卷是否都可读。
● 写入媒体前检查校验和。将会在写入备份媒体前验证校验和,如果选中此项,可能会增大工作负荷,并降低备份操作的备份吞吐量。
● 出错时继续。如果备份数据库时发生了错误,备份工作还将继续进行。
◆ 事务日志(只有在备份时备份类型选择为【事务日志】,此项才会被激活)
● 截断事务日志。选择此项会备份事务日志并将其截断,以便释放更多的日志空间,此时数据库处于在线状态。
● 备份日志尾部,并使数据库处于还原状态。选择此项会备份日志尾部并使数据库处于还原状态,该项创建尾日志备份,用于备份尚未备份的日志。当故障转移到辅助数据库或为了防止在还原操作之前丢失所做工作,该选项很有作用。选择该项后,在数据库完全还原之前,数据库无法使用。
◆ 磁带机。选择用磁带机设备备份数据库时选择此选项。
备份相关选项,MSDN有一篇文档讲得相当细,在此推荐。看完此文档后将对备份存储方面有一个深入的认识。http://msdn.microsoft.com/zh-cn/vcsharp/ms178062.aspx
数据库还原选项
◆ 【覆盖现有数据库】复选框:选中此项会覆盖所有现有数据库以及相关文件,包括已存在的同名其他数据库或文件。
◆ 【保留复制设置】复选框:选中此项会将已发布的数据库还原到创建该数据库的服务器之外的服务器时,保留复制设置。不过该项只有在选择了【回滚未提交的事务,使数据库处于可以使用的状态】单选按钮之后才可以使用。
◆ 【限制访问还原的数据库】复选框:使还原的数据库仅供 db_owner、dbcreator 或 sysadmin 的成员使用。
恢复状态:
◆ RESTORE WITH RECOVERY,通过回滚未提交的事务,使数据库处于可以使用的状态。无法还原其他事务日志。此项则让数据库在还原后进入可正常使用的状态,并自动恢复尚未完成的事务,如果本次还原是还原的最后一步操作,可以选择该项。此项为默认选项。
◆ RESTORE WITH NORECOVERY,不对数据库执行任何操作,不回滚未提交的事务。可以还原其他事务日志。此项则在还原后数据库仍然无法正常使用,也不恢复未完成的事务操作,但可继续还原事务日志备份或差异备份,让数据库能恢复到最接近目前的状态。
◆ RESTORE WITH STANDBY,使数据库处于只读模式。撤消未提交的事务,但将撤消操作保存在备用文件中,以便可使恢复效果逆转。选择此项时,备用文件选择目录将被激活。此项则在还原后进行恢复未完成事务的操作,并使数据库处于只读状态,为了可继续还原事务日志备份,还必须指定一个还原文件来存放被恢复的事务内容。
到此为止,数据库备份还原选项基本介绍完毕,有遗漏介绍的选项通过名称能直接明白。至于数据库备份还原脚本MSDN文档有语法和示例,再说也可以通过UI设置好后导出标准脚本。
以上为我对SQL Server数据库备份和还原的认识和总结,如有遗漏掉的细节或讲解错误

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

ThinkPHP6 data backup and recovery: ensuring data security With the rapid development of the Internet, data has become an extremely important asset. Therefore, the security of data is of great concern. In web application development, data backup and recovery are an important part of ensuring data security. In this article, we will introduce how to use the ThinkPHP6 framework for data backup and recovery to ensure data security. 1. Data backup Data backup refers to copying or storing the data in the database in some way. This way even if the data

Data backup and restoration of PHP applications through DockerCompose, Nginx and MariaDB. With the rapid development of cloud computing and containerization technology, more and more applications choose to use Docker to deploy and run. In the Docker ecosystem, DockerCompose is a very popular tool that can define and manage multiple containers through a single configuration file. This article will introduce how to use DockerCompose, Ng

Backup is a very important task during website operation. If there is data loss or loss on the website, backup can facilitate the restoration of the website. PHP is a commonly used server-side programming language. The backup function of the website can be implemented by writing PHP scripts. This article will introduce how to use PHP to implement website backup function. 1. Types of backup files When backing up a website, you need to back up the database and website files. Usually website files include static files, program files, pictures and uploaded attachments, etc., while the database contains all the information of the website.

In the process of web development, data storage and backup are undoubtedly a very important part. In case of data loss or recovery needs, backup is very necessary. For PHP, an open source back-end language, there are also many options for data backup. Let’s take a closer look at data backup in PHP. 1. Database backup 1.1 MYSQLdump tool MYSQLdump is a command line tool for backing up MYSQL databases. It copies the entire database or database by executing SQL statements.

How to use Java to write the data backup function of a CMS system. In a content management system (ContentManagementSystem, CMS), data backup is a very important and essential function. Through data backup, we can ensure that the data in the system can be restored in time in the event of damage, loss or incorrect operation, thereby ensuring the stability and reliability of the system. This article will introduce how to use Java to write the data backup function of the CMS system and provide relevant code examples.

Using PHP and SQLite to implement data backup and recovery strategies Backup and recovery is a very important aspect of database management, which can protect our data from accidental damage or loss. This article will introduce how to use PHP and SQLite to implement data backup and recovery strategies, helping us better manage and protect the data in the database. First, we need to create a database using SQLite and establish some test data for subsequent operations. Here's a simple example: <?php

How to deal with the data backup consistency problem in C++ big data development? In C++ big data development, data backup is a very important part. In order to ensure the consistency of data backup, we need to take a series of measures to solve this problem. This article will discuss how to deal with data backup consistency issues in C++ big data development and provide corresponding code examples. Using transactions for data backup Transactions are a mechanism to ensure the consistency of data operations. In C++, we can use the transaction concept in the database to implement data backup.

As the amount of data continues to increase, database backup becomes more and more difficult. Backup not only requires data integrity and consistency, but also requires backup speed and backup file size to meet actual needs. Data compression backup technology emerged as the times require and has become one of the indispensable technical means for database backup. MySQL is currently one of the most popular relational databases, and its officially provided backup tool mysqldump cannot meet the needs of compressed backup. Therefore, this article will introduce the use of compression command on Linux system ta
