SqlServer備份和恢復(二)
SqlServer 備份和恢復 ( 二 )
備份
--- 建立測試資料庫chen20181123
create database chen20181123
on
( name = chen_data ,
filename = 'D:\hrtest\DB\testdata\chen20181123_data.mdf' ,
size = 10 MB ,
filegrowth = 1 MB )
log on
( name = chen_log ,
filename = 'D:\hrtest\DB\testdata\chen20181123_log.ldf' ,
size = 1 MB ,
filegrowth = 10 MB );
--- 建立測試資料
use chen20181123
create table t1 ( id int , a varchar ( 100 ));
insert into t1 values ( 1 , 'a' );
insert into t1 values ( 2 , 'b' );
insert into t1 values ( 3 , 'c' );
--- 資料庫全備
BACKUP DATABASE chen20181123
TO DISK = 'D:\hrtest\DB\testdata\backup\chen20181123_full.bak' WITH COMPRESSION
GO
insert into t1 values ( 4 , 'd' );
insert into t1 values ( 5 , 'e' );
--- 資料庫差異備份
BACKUP DATABASE chen20181123
TO DISK = 'D:\hrtest\DB\testdata\backup\chen20181123_1.bak' WITH COMPRESSION , DIFFERENTIAL ;
GO
insert into t1 values ( 7 , 'f' );
insert into t1 values ( 8 , 'g' );
--- 資料庫日誌備份
BACKUP LOG chen20181123 TO DISK = 'D:\hrtest\DB\testdata\backup\chen20181123_2.trn' WITH COMPRESSION ;
insert into t1 values ( 9 , 'f' );
insert into t1 values ( 10 , 'g' );
---19:51
delete t1 ;
恢復場景
--- 恢復全備+差異備份 恢復
restore filelistonly from disk = 'D:\hrtest\DB\testdata\backup\chen20181123_full.bak' ;
RESTORE DATABASE chen20181123_1
FROM DISK = 'D:\hrtest\DB\testdata\backup\chen20181123_full.bak'
WITH NORECOVERY ,
MOVE 'chen_data' TO 'D:\hrtest\DB\testdata\chen20181123_1_data.mdf' ,
MOVE 'chen_log' TO 'D:\hrtest\DB\testdata\chen20181123_1_log.ldf' ;
RESTORE DATABASE chen20181123_1 from disk = 'D:\hrtest\DB\testdata\backup\chen20181123_1.bak'
WITH RECOVERY ;
select * from chen20181123_1.dbo.t1 ; ---5
--- 恢復全備+差異備份+日誌備份 恢復
USE MASTER
---drop database chen20181123_2;
RESTORE DATABASE chen20181123_2
FROM DISK = 'D:\hrtest\DB\testdata\backup\chen20181123_full.bak'
WITH NORECOVERY ,
MOVE 'chen_data' TO 'D:\hrtest\DB\testdata\chen20181123_2_data.mdf' ,
MOVE 'chen_log' TO 'D:\hrtest\DB\testdata\chen20181123_2_log.ldf' ;
RESTORE DATABASE chen20181123_2 from disk = 'D:\hrtest\DB\testdata\backup\chen20181123_1.bak'
WITH NORECOVERY ;
RESTORE LOG chen20181123_2 from disk = 'D:\hrtest\DB\testdata\backup\chen20181123_2.trn'
WITH RECOVERY ;
select * from chen20181123_2.dbo.t1 ; ---7
---20:33
BACKUP LOG chen20181123 TO DISK = 'D:\hrtest\DB\testdata\backup\chen20181123_3.trn' WITH COMPRESSION ;
--- 恢復全備+差異備份+日誌備份+新日誌備份 恢復
USE MASTER
RESTORE DATABASE chen20181123_3
FROM DISK = 'D:\hrtest\DB\testdata\backup\chen20181123_full.bak'
WITH NORECOVERY ,
MOVE 'chen_data' TO 'D:\hrtest\DB\testdata\chen20181123_3_data.mdf' ,
MOVE 'chen_log' TO 'D:\hrtest\DB\testdata\chen20181123_3_log.ldf' ;
RESTORE DATABASE chen20181123_3 from disk = 'D:\hrtest\DB\testdata\backup\chen20181123_1.bak'
WITH NORECOVERY ;
RESTORE LOG chen20181123_3 from disk = 'D:\hrtest\DB\testdata\backup\chen20181123_2.trn'
WITH NORECOVERY ;
RESTORE LOG chen20181123_3 from disk = 'D:\hrtest\DB\testdata\backup\chen20181123_3.trn'
WITH RECOVERY ;
select * from chen20181123_3.dbo.t1 ; ---0
--- 恢復全備+差異備份+日誌備份+新日誌備份+基於時間點不完全恢復
USE MASTER
---drop database chen20181123_5;
RESTORE DATABASE chen20181123_5
FROM DISK = 'D:\hrtest\DB\testdata\backup\chen20181123_full.bak'
WITH NORECOVERY ,
MOVE 'chen_data' TO 'D:\hrtest\DB\testdata\chen20181123_5_data.mdf' ,
MOVE 'chen_log' TO 'D:\hrtest\DB\testdata\chen20181123_5_log.ldf' ;
RESTORE DATABASE chen20181123_5 from disk = 'D:\hrtest\DB\testdata\backup\chen20181123_1.bak'
WITH NORECOVERY ;
RESTORE LOG chen20181123_5 from disk = 'D:\hrtest\DB\testdata\backup\chen20181123_2.trn'
WITH NORECOVERY ;
RESTORE LOG chen20181123_5 from disk = 'D:\hrtest\DB\testdata\backup\chen20181123_3.trn'
WITH RECOVERY , STOPAT = '2018-11-23 19:50:00' ;
select * from chen20181123_5.dbo.t1 ; ---9
歡迎關注我的微信公眾號"IT小Chen",共同學習,共同成長!!!
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29785807/viewspace-2221488/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SqlServer 備份和恢復(一)SQLServer
- 備份和恢復
- KunlunDB備份和恢復
- redis 備份和恢復Redis
- ORACLE備份&恢復案例二(轉)Oracle
- 【MySQL】MySQL備份和恢復MySql
- SqlServer資料庫恢復備份資料的方法SQLServer資料庫
- RAC備份恢復之Voting備份與恢復
- MySQL入門--備份與恢復(二)MySql
- innobackupex 部分表備份和恢復
- Oracle 備份和恢復介紹Oracle
- 如何備份和恢復你的TFS伺服器(二)伺服器
- 備份與恢復:polardb資料庫備份與恢復資料庫
- MySQL備份與恢復——基於Xtrabackup物理備份恢復MySql
- mydumper備份恢復
- Mysql備份恢復MySql
- SQLServer異常故障恢復(二)SQLServer
- 九 GBase 8a備份和恢復
- gitlab的資料備份和恢復Gitlab
- MySQL日誌管理,備份和恢復MySql
- MySQL備份和恢復方法彙總MySql
- 詳解叢集級備份恢復:物理細粒度備份恢復
- MySQL備份與恢復——基於MyDumper/MyLoader 邏輯備份恢復MySql
- Mysql備份與恢復(1)---物理備份MySql
- rman 增量備份恢復
- Jenkins備份與恢復Jenkins
- Postgresql 備份與恢復SQL
- MySQL 備份與恢復MySql
- RMAN備份恢復技巧
- Grafana 備份恢復教程Grafana
- 帝國cms備份和恢復 帝國cms恢復資料
- Mongo 資料庫備份和恢復命令Go資料庫
- DBV:冷備份的校驗和恢復
- 2.6.1 CDB中備份和恢復的概述
- 12 使用RMAN備份和恢復檔案
- Jira/Confluence的備份、恢復和遷移
- db2 命令列備份和恢復DB2命令列
- PostgreSql資料庫的備份和恢復SQL資料庫