MS2000 差异备份 还原

 --查询文件是否存在
CREATE TABLE #tmp ([File Exists] BIT, [File is a Directory] BIT, [Parent Directory Exists] BIT)
INSERT INTO #tmp ([File Exists], [File is a Directory], [Parent Directory Exists])
EXEC master.dbo.xp_fileexist 'D:\Test.bak'
SELECT * FROM #tmp
DROP TABLE #tmp

--完整备份数据库

BACKUP DATABASE MyBakTest TO DISK='D:\Test.bak' WITH FORMAT

--对tb表插入第一条记录

INSERT INTO tb_user(uname) VALUES('第一1次差异备份')

--第一次差异备份

BACKUP DATABASE MyBakTest TO DISK='D:\Test_One_Dif.bak' WITH FORMAT,DIFFERENTIAL

--对tb表插入第二条记录

INSERT INTO tb_user(uname) VALUES('第二3次差异备份')

--第二次差异备份

BACKUP DATABASE MyBakTest TO DISK='D:\Test_Two_Dif.bak' WITH FORMAT,DIFFERENTIAL

--OK.现在直接还原.完整备份+第二次差异备份.看看第二条记录在不在.

GO

--完整备份还原
RESTORE DATABASE MyBackTest2 FROM DISK='D:\Test.bak' WITH REPLACE,NORECOVERY

RESTORE DATABASE MyBackTest2 FROM DISK='D:\Test_one_Dif.bak' WITH RECOVERY

--第二次差异备份还原
RESTORE DATABASE MyBackTest2 FROM DISK='D:\Test_Two_Dif.bak' WITH RECOVERY
 
--若存储位置有变换则需要更改存储位置,使用restore filelistonly 查询逻辑名
restore filelistonly from disk='F:\DBBak\VNetBilling_db_201112060230.BAK'
--使用 Move 更改存储位置并还原
RESTORE DATABASE SCVNetBillings FROM DISK='F:\DBBak\VNetBilling_db_201112060230.BAK' WITH REPLACE,NORECOVERY,
move 'vnet_billing_data001_2'     to 'F:\DBBak\VNET_Billing\data\vnet_dbdata2_01.mdf',
move 'vnet_billing_data002_16'     to 'F:\DBBak\VNET_Billing\data\vnet_dbdata16_01.ndf'
...

 

posted @ 2011-12-09 17:13  大笑江湖  阅读(288)  评论(0编辑  收藏  举报