SQLServer2008数据库备份还原和数据恢复
在完整恢复模式或大容量日志恢复模式下,必须先备份活动事务日志(称为日志尾部),然后才能在SQLServerManagementStudio中还原数据库。有关详细信息,请参阅如何备份事务日志(SQLServerManagementStudio)。若要还原已加密的数据库,您必须有权访问用于加密数
在完整恢复模式或大容量日志恢复模式下,必须先备份活动事务日志(称为日志尾部),然后才能在SQLServerManagementStudio中还原数据库。有关详细信息,请参阅如何备份事务日志(SQLServerManagementStudio)。若要还原已加密的数据库,您必须有权访问用于加密数据库的证书或非对称密钥。如果没有证书或非对称密钥,数据库将无法还原。
认识数据库备份和事务日志备份
数据库备份与日志备份是数据库维护的日常工作,备份的目的是在于当数据库出现故障或者遭到破坏时可以根据备份的数据库及事务日志文件还原到最近的时间点将损失降到最低点。
数据库备份
数据库备份可以手动备份和语句备份
一.手动备份数据库
1.鼠标右键选择你要进行备份的数据库-任务-备份
可以在常规选项页面你可以选择备份类型是进行完整数据库备份还是差异数据库备份
2.点击添加选项,选择数据库文件的存放路径
注意文件名记得加后缀.bak,便于恢复时的查找
3.你还可以在选项页面是追加到现有的备份集,还是覆盖所有的现有备份集,还可以选择备份验证完整性(建议选择),还可以选择是否压缩备份等。
二.语句备份数据库
use master goBACKUP DATABASE [test] TO DISK = N'D:Microsoft sql serverMSSQL10.MSSQLSERVERMSSQLBackuptest.bak' WITH NOFORMAT, NOINIT, NAME = N'test-完整 数据库 备份', SKIP, NOREWIND, NOUNLOAD, STATS = 10GO
数据库日志备份
首先需要注意,数据库日志的备份是基于数据库完整备份,也就是说你备份数据库日志之前你首先要先对数据库进行一次完整的备份,因为之间会涉及到坚持到检查点lsn,这也是本文接下来要讲的重点。
一.手动备份数据库日志
1.右键数据库-任务-备份-选择备份类型(事务日志)
2.点添加,添加日志文件备份存储路径
3.同数据库完整备份一样,你也可以选择覆盖现有备份集或者追加到现有备份集,这里现在覆盖现有备份集、验证完整性,然后确认备份
二.语句备份数据库事务日志
BACKUP LOG [test] TO DISK = N'D:test.trn' WITH NOFORMAT, INIT, NAME = N'test-事务日志 备份', SKIP, NOREWIND, NOUNLOAD, STATS = 10GO
数据库还原
右键数据库-还原数据库-添加需要进行还原的数据库文件路径
在还原源选项中你可以选择‘源数据库’,‘源设备’。1.选择源数据库工具会自动显示该数据库之前的一些备份,然后直接选择需要还原的数据库备份集。
2.选择源设备点击后面的...,添加需要还原的数据库文件
2.点击确认还原数据库
数据库恢复
数据库恢复的前提是1.一个完整的数据库备份2.包含这个完整数据库备份的事务日志备份3.完整备份之间也可以存在数个差异备份
对于数据库维护空间始终是一个比较头疼的问题,特别是对于大型数据库而言,每天的日志文件增长是庞大的,很多数据库管理员会定时对数据库日志文件进行收缩,但是经常收缩会存在收缩完日志文件还是不能减少,这是因为存在很多活动的日志无法收缩可以用
DBCC LOGINFO('数据库名称')
我们看到
status=0的日志,代表已经备份到磁盘的日志文件;而
status=2的日志还没有备份。当我们收缩日志文件时,收缩掉的空
间其实就是
status=0的空间,如果日志物理文件无法减小,这里一
定能看到非常多 status=2的记录
解决办法:1.可以分离要收缩的数据库,然后手动删除日志文件,然后附加数据库,数据库就会产生一个很小的日志文件(不推荐使用这种方法)
2.右键要出来的数据库选择“属性”-"选项",将恢复模式改成"简单",然后利用收缩工具可以讲日志文件收缩到很小,收缩完记得讲恢复模式改成"完整"
也可以用语句进行处理(dbname是你要进行收缩的数据库名,dbname_log是你要进行收缩的数据库的逻辑日志名称)
USE [master]
GO ALTER DATABASE [dbname] SET recovery SIMPLE WITH NO_WAIT GO
ALTER DATABASE [dbname] SET RECOVERY SIMPLE --简单模式
GO
USE [dbname]
GO
DBCC SHRINKFILE (N'dbname_log' , 11, TRUNCATEONLY) GO
USE [master]
GO
ALTER DATABASE [dbname] SET RECOVERY FULL WITH NO_WAIT ALTER DATABASE [dbname] SET RECOVERY FULL
对于第一种方法不赞同使用,首先对于数据库的分离与附加有时候会破坏数据库,造成数据库无法还原,还有就是对于在线数据库也不允许进行分离操作。
对于第二种方法是slq2008收缩日志文件的一种方法,但是此方法也不能使用过于频繁,因为进行数据库恢复模式的更改会截断事务日志文件,这样的话当时利用事务日志文件进行恢复的时候检查点不能包含数据库文件,而且当你要对事务日志进行备份的时候会重新提示你需要对数据库进行完整备份。
举个例子:比如你昨天晚上进行了一次完整备份,然后同时你也进行了一次日志备份(提前日志未被截断),然后你每个小时进行过一次差异备份,最近的差异备份时间点是14点,如果此时数据库错误修改了数据,你可以立马备份一个日志文件将数据库恢复到日志备份开始到日志备份终点前的任意时间点 。

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

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.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

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())

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.

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

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.

Analysis of the basic principles of the MySQL database management system MySQL is a commonly used relational database management system that uses structured query language (SQL) for data storage and management. This article will introduce the basic principles of the MySQL database management system, including database creation, data table design, data addition, deletion, modification, and other operations, and provide specific code examples. 1. Database Creation In MySQL, you first need to create a database instance to store data. The following code can create a file named "my

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u
