National Computer Rank Examination Level 3 Database Technology (12)

Chapter 12_Backing up and Restoring Databases

test analysis

◆Generally, multiple-choice questions will appear in the exam.
◆Common test knowledge points include:
1. Familiar with the concepts of backing up and restoring databases
2. Master the backup and recovery mechanism of SQL Server (such as recovery mode and backup type, etc.)
3. Understand the backup and recovery mechanism of Oracle

Test point 1: The concept of backup and recovery

1. Backup database
1. Backup: It is to make a copy of the database. Includes data rate structures, objects, and data.
2. The main purpose of backing up the database; to prevent data loss. The reasons for data loss are as follows:
01 Storage medium failure
Storage medium has a certain lifespan, after a long time of use. Storage media may appear corrupted or completely crash+. This will inevitably result in data loss.
02 User's operation error
If the user unintentionally or maliciously performs illegal operations in the database, such as deleting or changing important data, etc. It can also cause data damage.
03Server failure
A phenomenon in which a large server may be damaged or crashed by hardware or software.
04Data loss or damage caused by virus.
05Data loss or damage due to natural disasters

Backing up the database is a very important task for the database administrator. You can use the data rate backup to restore the database that has problems. Another role of the backup database is to transfer data. It is the same database on the two servers.

2. Restoring the database
1. Restoring the database refers to the process that the database system uses the previously established redundant data (backup copy) to restore the data army to a correct and consistent state when a failure occurs.
2. According to the impact of the failure on the database system and the degree of repairability of the failure, the failure recovery of the database system can be classified into the following two types:
01. Media failure recovery: also known as catastrophic failure, such as a disk crash causing large-scale database data damaged or lost. The main way to deal with this kind of failure is to restore the latest copy of the database, and use the backup log to redo the operation of the committed transaction, so that the database can be restored to a certain working state before the failure.
02. Non-media failure recovery: also known as recoverable failure, the basic method to solve this kind of failure is to use the information in the online log file according to the detected database inconsistency after a certain process of the DBMS restarts the database system Perform the necessary REDO and UNDO operations to restore the database.
Non-medium failure generally does not need a backup copy of the database, and its recovery work is automatically completed by the database management system.

Test point 2: SQL Server backup and recovery mechanism

1. Recovery mode
1. The role of the recovery mode: to control the maintenance of the transaction log. SQL Server 2008 supports three recovery modes: simple recovery mode, complete recovery mode, and bulk log recovery mode.
(1) Simple recovery model
Advantages: No backup of transaction logs can minimize the processing overhead of transaction logs.
Disadvantages: If the database is damaged, there will be a great risk of data loss, and it can only be restored to the latest backup state.

In the simple recovery mode, the backup interval should be as short as possible to prevent massive data loss.
For user databases, the simple recovery model is only used for test and development databases, or for databases that primarily contain read-only data (such as data warehouses).
The simple recovery model is not suitable for production systems because of the risk of losing data.

(2) Complete recovery mode
A. The complete recovery mode records all transactions completely, and keeps the transaction log records until the backup is completed.
B. If you can back up the tail of the log after a failure, you can use the full recovery model to restore the database to the point of failure.
C. The full recovery model also supports restoring individual data pages.
(3) Bulk log recovery mode
A. The bulk log recovery mode only records (limited) the bulk operation at a minimum, so that the transaction log will not be filled by the bulk load operation. This mode protects bulk operations against media failure, provides the best performance, and consumes the least amount of log space.
B. The large-capacity log recovery mode is generally only used as an additional mode of the complete recovery mode, and the transaction log records are also kept until the backup is completed. This mode does not support point-in-time recovery, and a trade-off must be made between increasing log backups and increasing the risk of work loss.
C. The figure below shows the construction method of log backup under the large-capacity log recovery mode.
insert image description here

(4) View and change the recovery mode
insert image description here

2. Backup content and backup
1. Backup content
When backing up the database, user data and system data must be backed up to ensure that the database can be completely restored when the system fails.
2. Backup time
backup time
Special user database backup
insert image description here

3. The backup mechanism of SQL Server
1. Backup device
(1) The backup device is the file of the backup database. These files can be created on tape or disk. A backup device is actually a file on a tape or disk that exists physically at the operating system level.
SQL Server supports the following two backup methods.
Temporary backup device
Click to back up the database to a physical file.
Permanent Backup Device
Create a backup device first. Then back up the database to the backup device.

Creating a backup device can be realized graphically through the SQL Server Management Studio tool, or by using T-SQL statements.

(2) A statement to create a backup device
insert image description here

(3) A statement to create a backup device
insert image description here
2. Backup type
(1) The recovery mode of the database determines the type of backup that can be used, and the backup type of the database determines the content of the backup. The backup types supported by SQL Server are as follows.
Backup Types Supported by SQL Server
(2) Database backup
SQL Server supports two types of complete database backup and differential database backup.
01. Full database backup (full dump)
A. Full database backup is the most basic and important backup among all backup methods, and it is the basis of backup. It backs up all the information in the database and is the baseline for recovery.
B. When performing a full backup, not only the data files and log files of the database are backed up, but also the storage location information of the files and all objects in the database are backed up.
C. When the database is relatively large. A complete database backup takes a relatively long time and resources.

02. Differential database backup (differential dump)
A. Differential database backup changes all the content of the database since the latest full backup. It takes the previous full backup as the reference point, and backs up the changed data files, log files and files after the full backup. Other modified content in the database.
B. Differential database backups usually take up less space than full database backups and perform faster, but will increase the complexity of the backup.
C. The size of the differential backup depends on the amount of data that has changed since the differential baseline was established. The older the differential base, the larger the new differential backup.
(3) Working principle of differential backup
Differential Backup Working Principle Diagram

(4) Principles of using differential database backups
01. Regularly schedule differential database backups after each full database backup. For example: Differential database backups can be performed once a day, for systems with high activity. This frequency can be increased.
02. Regularly schedule new full database backups while ensuring that differential backups are not too large. For example; a full database can be backed up weekly.
(5) File backup
Back up the files in the database. Using the file backup method, the user can only restore the damaged file without restoring the rest of the old database, which speeds up the recovery speed. SQL Server supports the following two methods of file backup and differential file backup.
01. File backup
A complete backup of all data in one or more files or filegroups.
Note: File backups in the simple recovery model are basically limited to read-only secondary filegroups. Users can create file backups of read/write filegroups. But you must first set the filegroup as read-only, and perform a differential file backup of the read-only files before you can restore the read/write file backup.
02. Differential file backup
Contains data areas that have changed since the latest full backup of each file.
(6) Transaction data backup
A. Transaction log backup is only used for the full recovery mode and the large-capacity log recovery mode. Simple recovery mode does not support transaction log backup
B. Transaction log backup does not back up the database itself, it only backs up log records, and only backs up the log content that has changed since the last backup to the current backup time.
C. Using transaction log backup, the database can be restored to the point of failure or to a fixed point in time.
D. In general, transaction log backup uses less resources than full backup and differential backup, and transaction log backup can be used more frequently to reduce the risk of data loss.
(7) Three backup types of transaction log backup
A. Pure log backup
A backup that contains only transaction log records at a certain interval and does not contain any bulk changes performed under the bulk-logged recovery model.
B. Large-capacity operation log backup
Contains log records and backups of data pages changed by large-capacity operations. Point-in-time recovery of bulk oplog backups is not allowed.
C. Tail log backup
A log backup of a potentially corrupted database to capture log records that have not been backed up. Tail log backup is performed when a failure occurs to prevent data loss, and can include pure log records or large-capacity operation log records.
Note: A full or differential backup must be synchronized with a transaction log backup only when the transaction log backup sequence is started. Every sequence of transaction log backups must start after a full or differential backup is performed.
(8) Log Chain
A. Description: A continuous sequence of log backups is called a "log chain", starting with a full backup of the database. To restore the database to the point of failure, the log chain must be complete ----- the continuous sequence of transaction log backups must be able to continue to the point of failure.
B. The starting position of the log sequence depends on the type of database backup restored: database backup or file backup.
The starting position of the log sequence
01. For data backup, the log backup sequence must continue from the end of the database backup.

02. For a set of file backups, the log backup sequence must continue from the beginning of the entire set of file backups.

Note: In the full recovery model or the bulk-logged recovery model, SQL Server 2008 requires users to back up the end of the log to capture log records that have not yet been backed up.

Test point 3: Oracle backup and recovery mechanism (to be determined)

For group file backup, the log backup sequence must continue from the beginning of the entire group file backup.

Note: In the full recovery model or the bulk-logged recovery model, SQL Server 2008 requires users to back up the end of the log to capture log records that have not yet been backed up.

Guess you like

Origin blog.csdn.net/weixin_47288291/article/details/123586148