数据库的恢复模式
---恢复内容开始--- 数据库的恢复模式是数据库遭到破坏时还原数据库中数据的数据存储方式,它与可用性、性能、磁盘空间等因素相关。每一种恢复模式都按照不同的方式维护数据库的数据和日志。系统提供了3种数据库的恢复模式: 1、完整恢复模式 2、大容量日志
---恢复内容开始---
数据库的恢复模式是数据库遭到破坏时还原数据库中数据的数据存储方式,它与可用性、性能、磁盘空间等因素相关。每一种恢复模式都按照不同的方式维护数据库的数据和日志。系统提供了3种数据库的恢复模式:
1、完整恢复模式
2、大容量日志记录的恢复模式
3、简单恢复模式
完整恢复模式是最高等级的数据库恢复模式。在完整恢复模式中,对数据库的所有操作都记录在数据库的事务日志中。即使那些大容量数据库操作和创建索引的操作,也就记录在数据库的事务日志中。当数据库遭到破坏之后,可以使用该数据库的事务日志迅速还原数据库。
在完整恢复模式中,由于事务日志记录了数据库的所有变化,所以可以使用事务日志将数据库还原到任意的时刻点。但是,这种恢复模式耗费大量的磁盘空间。除非是那种事务日志非常重要的数据库备份策略,否则一般不建议使用这种恢复模式。
就想完整恢复模式一样,大容量日志记录的恢复模式也使用数据库备份和日志备份还原数据库。但是,在使用了大容量日志记录的恢复模式的数据库中,其事务日志耗费了的磁盘空间远远小于使用完整恢复模式的数据库的事务日志。在大容量日志记录的恢复模式中,Check Index、bulk insert、BCP、Select Into等操作不记录在事务日志中。
对于那些规模比较小的数据库或数据不经常改变的数据库来说,可以使用简单恢复模式。当使用简单恢复模式时,可以通过执行完全数据库备份和增量数据库备份来还原数据库,数据库只能还原到执行备份操作的时刻点。执行备份操作之后的所有的数据修改都丢失并且需要重建。这种模式的特点是数据库没有事务日志。这种模型的好处是耗费比较少的磁盘空间,恢复模式最简单。
举个例子:
假设出问题的数据库为A, 新恢复后的数据库为B
1.前提:A数据库的恢复模式必须为:完整。
2.备份A数据库的日志,假设文件名为log.bak
3.使用A数据库的最近的完整备份,使用 WITH NORECOVERY 的方式,恢复为B数据库
4.使用恢复日志的方式,指定还原的时间点(T),将Log.bak文件还原到B数据库,完成后,B数据库的内容即是T时间之前的完整数据。
以下为测试语句建A数据库
--<span>创建A数据库 CREATE DATABASE A GO </span>--<span>对A数据库进行备份 BACKUP DATABASE A TO DISK</span>= <span>'</span><span>c:\A.bak </span><span>'</span><span> WITH FORMAT GO </span>--<span>创建测试表 CREATE TABLE A.dbo.TB_test(ID </span><span>int</span><span>) GO </span>--<span>插入数据 Insert Into A.dbo.TB_test(ID) </span><span>select</span> <span>1</span><span> GO </span>--<span>延时1秒钟,再进行后面的操作 </span>--<span>(这是由于SQL Server的时间精度最大为百分之三秒,不延时的话,可能会导致还原到时间点的操作失败) WAITFOR DELAY </span><span>'</span><span>00:00:01 </span><span>'</span><span> GO </span>--<span>假设我们现在误操作删除了 A.dbo.TB_test 这个表 DROP TABLE A.dbo.TB_test </span>--<span>为了测试还原时间点,先记录操作的时间点 SELECT dt</span>=<span>GETDATE() INTO #T GO </span>--<span>在删除操作后,发现不应该删除表 TB_test </span>--<span>下面演示了如何恢复这个误删除的表 TB_test,以及数据行 </span>--<span>为了避免覆盖A数据库,恢复时,生成到B数据库 GO </span>--<span>首先,备份A数据库的事务日志(使用事务日志才能还原到指定的时间点) BACKUP LOG A TO DISK</span>= <span>'</span><span>c:\A_log.bak </span><span>'</span><span> WITH FORMAT GO </span>--<span>接下来,我们要先还原完全备份(还原日志必须在还原完全备份的基础上进行),生成数据库B RESTORE DATABASE B FROM DISK</span>= <span>'</span><span>c:\A.bak </span><span>'</span><span> WITH FILE </span>= <span>1</span>, MOVE N<span>'</span><span>A</span><span>'</span> TO N<span>'</span><span>C:\B.mdf</span><span>'</span><span>, MOVE N</span><span>'</span><span>A_log</span><span>'</span> TO N<span>'</span><span>C:\B.ldf</span><span>'</span><span>, NORECOVERY, REPLACE GO </span>--<span>将事务日志还原到删除操作前(这里的时间对应上面的删除时间,并比删除时间略早 DECLARE @dt datetime SELECT @dt</span>=DATEADD(ms,-<span>20</span>,dt) FROM #T --<span>获取比表被删除的时间略早的时间 RESTORE LOG B FROM DISK</span>= <span>'</span><span>c:\A_log.bak </span><span>'</span> WITH RECOVERY,STOPAT=<span>@dt GO </span>--<span>查询一下,看表是否恢复 SELECT </span>*<span> FROM B.dbo.TB_test </span>--<span>最后删除我们做的测试环境 DROP DATABASE A DROP DATABASE B DROP TABLE #T</span>
---恢复内容结束---

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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



Even answering calls in Do Not Disturb mode can be a very annoying experience. As the name suggests, Do Not Disturb mode turns off all incoming call notifications and alerts from emails, messages, etc. You can follow these solution sets to fix it. Fix 1 – Enable Focus Mode Enable focus mode on your phone. Step 1 – Swipe down from the top to access Control Center. Step 2 – Next, enable “Focus Mode” on your phone. Focus Mode enables Do Not Disturb mode on your phone. It won't cause any incoming call alerts to appear on your phone. Fix 2 – Change Focus Mode Settings If there are some issues in the focus mode settings, you should fix them. Step 1 – Open your iPhone settings window. Step 2 – Next, turn on the Focus mode settings

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.
