--书上偶然看到,测试一下


--清空备份记录(执行一条命令就行),在测试库执行!~
use msdb;
exec sp_delete_backuphistory '2014-10-27';
exec sp_delete_database_backuphistory 'TEST';

--注:备份名称相同的【完整-差异-日志】备份
BACKUP DATABASE TEST
TO DISK = 'E:\TEST2014.BAK'
WITH INIT,DESCRIPTION = 'FULL BACKUP'

BACKUP DATABASE TEST
TO DISK = 'E:\TEST2014.BAK'
WITH DIFFERENTIAL,DESCRIPTION = 'DIFF BACKUP'

BACKUP LOG TEST
TO DISK = 'E:\TEST2014.BAK'
WITH DESCRIPTION = 'LOG BACKUP'


--可以查看,[TEST2014.BAK]就是一个外部备份集.
SELECT * FROM msdb.dbo.backupmediafamily
SELECT * FROM msdb.dbo.backupmediaset
SELECT position ,* FROM msdb.dbo.backupset--position指定文件顺序


RESTORE DATABASE TEST
FROM DISK = 'E:\TEST2014.BAK'
WITH FILE = 1 ,NORECOVERY, REPLACE

RESTORE DATABASE TEST
FROM DISK = 'E:\TEST2014.BAK'
WITH FILE = 2 ,NORECOVERY

--跳过上一步差异直接还原日志,默认同时还原最近一次差异和此日志
RESTORE DATABASE TEST
FROM DISK = 'E:\TEST2014.BAK'
WITH FILE = 3 ,RECOVERY



从界面还原数据库时,选择【源数据库】可看的内容:



RESTORE DATABASE WITH FILE 简单实例说明_数据库



--  当清空备份记录后不在【源数据库】显示,只能从【源设备】查找备份集;
-- 可以看到之前的同名备份都在同一个集合里;
-- 再添加完整备份时,NOFORMAT,NOINIT不起作用,因此只能有一个完整备份;