SQL Service Database BACKUP & RESTORE

1. 完整恢复模式下的数据库备份

 1 USE master;
 2 ALTER DATABASE AdventureWorks2012 SET RECOVERY FULL;
 3 GO
 4 -- Back up the AdventureWorks2012 database to new media set (backup set 1).
 5 BACKUP DATABASE AdventureWorks2012
 6   TO DISK = ‘Z:\SQLServerBackups\AdventureWorks2012FullRM.bak‘
 7   WITH FORMAT;
 8 GO
 9 --Create a routine log backup (backup set 2).
10 BACKUP LOG AdventureWorks2012 TO DISK = ‘Z:\SQLServerBackups\AdventureWorks2012FullRM.bak‘;
11 GO

2. 完整数据库还原(完整恢复模式)

 1 USE master;
 2 --Create tail-log backup.
 3 BACKUP LOG AdventureWorks2012
 4 TO DISK = ‘Z:\SQLServerBackups\AdventureWorksFullRM.bak‘
 5    WITH NORECOVERY;
 6 GO
 7 --Restore the full database backup (from backup set 1).
 8 RESTORE DATABASE AdventureWorks2012
 9   FROM DISK = ‘Z:\SQLServerBackups\AdventureWorksFullRM.bak‘
10   WITH FILE=1,
11     NORECOVERY;
12
13 --Restore the regular log backup (from backup set 2).
14 RESTORE LOG AdventureWorks2012
15   FROM DISK = ‘Z:\SQLServerBackups\AdventureWorksFullRM.bak‘
16   WITH FILE=2,
17     NORECOVERY;
18
19 --Restore the tail-log backup (from backup set 3).
20 RESTORE LOG AdventureWorks2012
21   FROM DISK = ‘Z:\SQLServerBackups\AdventureWorksFullRM.bak‘
22   WITH FILE=3,
23     NORECOVERY;
24 GO
25 --recover the database:
26 RESTORE DATABASE AdventureWorks2012 WITH RECOVERY;
27 GO

3. 根据数据库生成相应的SQL 脚本

SELECT Name ,

N‘ALTER DATABASE ‘+Name+‘  SET RECOVERY FULL;
GO
BACKUP DATABASE ‘+Name+‘  TO DISK = ‘‘C:\Databases_Backup\‘+Name+‘_FullRM.bak‘‘  WITH FORMAT;
GO
BACKUP LOG ‘+Name+‘  TO DISK = ‘‘C:\Databases_Backup\‘+Name+‘_FullRM.bak‘‘;
GO‘ as [BACKUP SQL] ,

N‘RESTORE DATABASE ‘+Name+‘
FROM DISK = ‘‘C:\Databases_Backup\‘+Name+‘_FullRM.bak‘‘
WITH FILE=1,
NORECOVERY;

RESTORE LOG AdventureWorks2012
FROM DISK = ‘‘C:\Databases_Backup\‘+Name+‘_FullRM.bak‘‘
WITH FILE=2,
NORECOVERY;

RESTORE LOG AdventureWorks2012
FROM DISK = ‘‘C:\Databases_Backup\‘+Name+‘_FullRM.bak‘‘
WITH FILE=3,
NORECOVERY;
GO
RESTORE DATABASE ‘+Name+‘ WITH RECOVERY;
GO‘ as [RESTORE SQL] 

FROM Master..SysDatabases ORDER BY Name 

时间: 2024-10-01 16:45:35

SQL Service Database BACKUP & RESTORE的相关文章

转 RMAN: RAC Backup, Restore and Recovery using RMAN

PURPOSE The purpose of this document is to give a quick guide for using RMAN on RAC databases. We will follow this points: 1. Verify the database mode and archive destination.2. Verify connectivity using sqlnet for target and catalog.3. Determine the

SQL Server 还原错误“restore database正在异常终止 错误 3154”

今天在还原数据库时,先建立相同名字的数据库,然后在该数据库上右键还原数据库.遇到了这样的一个错误: “备份集中的数据库备份与现有的 'RM_DB' 数据库不同. RESTORE DATABASE 正在异常终止. (Microsoft SQL Server,错误: 3154) ” 很显然,这是由于备份的数据库版本和我现在还原的数据库版本不一样导致的. 最终通过以下方法解决了此类问题: (1)直接在“数据库”上右键菜单->还原文件和文件组 (2)直接写入数据库名字-RM_DB,点击确定,OK!还原成

P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1

P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1       May 2016 Contents About This Guide...................................................................................... 11 Shared Topics in This Guide .

Database Backup and Recovery Basics2

1.6.Automatic Disk-Based Backup and Recovery: The Flash Recovery Area 创建不同备份和恢复文件的组件对每个文件系统的大小没有任何了解.使用Automatic Disk-Based Backup and Recovery,你可以创建一个闪回恢复区,使备份文件的管理自动化.在磁盘上选择一个位置,为存储空间提供一个更大的边界,同时设置一个备份策略,那么数据库在那块空间管理用做备份的存储.归档日志和其他与恢复相关的文件.oracle建议

RAC(11gR2) OCR BACKUP & RESTORE

首先检查下OCR盘 [[email protected]1 cdata]$ ocrcheck Status of OracleCluster Registry is as follows : Version                  :          3 Total space (kbytes)     :    262120 Used space (kbytes)      :      3068 Available space (kbytes) :     259052 ID  

MySQL Database Backup Methods Season 1 - mysqldump

mysqldump工具是MySQL数据库备份时, 经常用到的一个工具. 可以指定数据表, 某些数据库, 所有数据库级别的备份, 在命令行上敲入mysqldump回车, 可看到该三种方式的示例. [email protected]:~$ mysqldump Usage: mysqldump[OPTIONS] database [tables] OR     mysqldump [OPTIONS] --databases [OPTIONS]DB1 [DB2 DB3...] OR     mysqld

官方文档 恢复备份指南七 Using Flashback Database and Restore Points

本章内容: Understanding Flashback Database, Restore Points and Guaranteed Restore Points Logging for Flashback Database and Guaranteed Restore Points Prerequisites for Flashback Database and Guaranteed Restore Points Using Normal and Guaranteed Restore P

SQL UNION 和 UNION ALL 操作符\SQL SELECT INTO 语句\SQL CREATE DATABASE 语句

SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每条 SELECT 语句中的列的顺序必须相同. SQL UNION 语法 SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FROM table_name2 注释:默认地,UNION 操作符选取不同的值.如果允许重复的

Database Backup and Recovery Basics

一.Backup and Recovery Overview 1.Backup and Recovery Overview 1.1 What is Backup and Recovery? 一般,备份和恢复引用各个策略和过程保护你的数据库背离数据丢失,同时在任何一种数据丢失后重建数据库. 1.1.1 Physical Backups and Logical Backups 一个备份是来自数据库文件的一个拷贝,它可以用做重建数据.备份可以被分为物理备份和逻辑备份. 物理备份是被用做还原和恢复数据库