SQL Server的还原

2022-11-16 00:00:00 数据库 备份 日志 还原 完整

1.差异备份的还原

不备份结尾日志的情况下还原数据

创建差异备份的放在我们已经在前面一篇博客SQL Server的备份中提到了,这里我们不再赘述,下面我们给出差异备份与还原的T-SQL方法,代码如下:

--创建备份设备
EXEC sp_addumpdevice 'disk', 'MyAdvWorks_1', 'd:\backup\MyAdvWorks_1.bak';
EXEC sp_addumpdevice 'disk', 'MyAdvWorks_diff1', 'd:\backup\MyAdvWorks_diff1.bak';
EXEC sp_addumpdevice 'disk', 'MyAdvWorks_log1', 'd:\backup\MyAdvWorks_log1.bak';
EXEC sp_addumpdevice 'disk', 'MyAdvWorks_log2', 'd:\backup\MyAdvWorks_log2.bak';

--数据库备份阶段
-- 创建完整备份
BACKUP DATABASE MyAdvWorks
TO MyAdvWorks_1
WITH INIT;
GO
-- 在完整备份之后创建差异备份
BACKUP DATABASE MyAdvWorks
TO MyAdvWorks_diff1
WITH DIFFERENTIAL;
GO

--数据库还原阶段
-- 完整还原
RESTORE DATABASE MyAdvWorks
FROM MyAdvWorks_1
WITH NORECOVERY;
GO
-- 在完整还原之后差异还原
RESTORE DATABASE MyAdvWorks
FROM MyAdvWorks_diff1
WITH RECOVERY;
GO


相关文章