我使用 Sql Server 2019 并且需要备份和恢复文件组。
执行步骤:
1.创建数据库Two FilesGroup
并[TestFileGroup]
命名。
2.在两个表中插入数据,一个在 First FileGroup 中,另一个在第二个 FileGroup 中。
3.第一次完整备份[TestFileGroup]
。
4.然后re-enter the data
进行更改 5.BackUP FileGroup From [FG2] 。
6.Restore First FullBackup With [TestFileGroup_New]
name。
7.对于恢复部分备份需要尾部备份。和来自 [TestFileGroup_New] 的尾日志备份。
8.恢复FILEGROUP
备份。
9.restore Database [TestFileGroup_New]
with RECOVERY
10.引发错误!
错误文本:
消息 4303,级别 16,状态 1,第 100 行 前滚起点现在位于日志序列号 (LSN) 37000000056800001。需要额外前滚超过 LSN 37000000058400001 才能完成恢复序列。消息 3013,级别 16,状态 1,第 100 行 RESTORE DATABASE 异常终止。
Sql 服务器查询:
USE master
GO
DROP DATABASE IF EXISTS TestFileGroup
GO
DROP DATABASE IF EXISTS TestFileGroup_New
GO
--================================================================= Create DataBase
CREATE DATABASE TestFileGroup
ON PRIMARY
( NAME = N'PRIMARY', FILENAME = N'D:\Temp\TestDB\TestFileGroup_PRIMARY.mdf'),
FILEGROUP FG2
( NAME = N'secondary', FILENAME = N'D:\Temp\TestDB\TestFileGroup_secondary.ndf')
LOG ON
( NAME = N'TestFileGroup_log', FILENAME = N'D:\Temp\TestDB\FGRestoreTEST_log.ldf')
GO
--================================================================= Insert Data(Level 1)
USE TestFileGroup
GO
CREATE TABLE T_primary
(
ID INT PRIMARY KEY,
Fname NVARCHAR(100),
Lname NVARCHAR(100)
) ON [PRIMARY]
GO
CREATE TABLE T_fg2
(
ID INT PRIMARY KEY,
Fname NVARCHAR(100),
Lname NVARCHAR(100)
) ON FG2
GO
--==================================================================
USE TestFileGroup
GO
INSERT INTO T_primary (ID,Fname,Lname) VALUES
(1,N'Json',N'JJ'),
(2,N'C#',N'CC'),
(3,N'Python',N'PP'),
(4,N'Test1',N'TT'),
(5,N'C++',N'C')
GO
INSERT INTO T_fg2 (ID,Fname,Lname) VALUES
(10,N'MMMM',N'M'),
(20,N'SSSS',N'S'),
(30,N'PPPPP',N'P')
GO
SELECT * FROM T_primary
SELECT * FROM T_fg2
GO
--================================================================== First Full Backup IN First year
BACKUP DATABASE TestFileGroup TO DISK = N'D:\Temp\TestDB\Backup\TestFileGroup_Full.bak'
WITH FORMAT,COMPRESSION
GO
RESTORE FILELISTONLY FROM DISK = N'D:\Temp\TestDB\Backup\TestFileGroup_Full.bak'
--================================================================== Change Data
USE TestFileGroup
GO
INSERT T_primary
SELECT 6 ID,'Java'Fname,'jv' Lname
INSERT T_fg2
SELECT 40 ID,'HHHH'Fname,'H' Lname
SELECT * FROM T_primary
SELECT * FROM T_fg2
--================================================================== First FileGroup Backup
USE master
GO
BACKUP DATABASE TestFileGroup FILEGROUP = N'FG2' TO DISK = N'D:\Temp\TestDB\Backup\TestFileGroup_FG2.bak'
WITH FORMAT,COMPRESSION
GO
RESTORE LABELONLY FROM DISK=N'D:\Temp\TestDB\Backup\TestFileGroup_FG2.bak'
GO
RESTORE HEADERONLY FROM DISK=N'D:\Temp\TestDB\Backup\TestFileGroup_FG2.bak'
GO
RESTORE FILELISTONLY FROM DISK=N'D:\Temp\TestDB\Backup\TestFileGroup_FG2.bak'
GO
--================================================================== Restore Full Backup --->TestFileGroup_New
RESTORE DATABASE TestFileGroup_New FROM DISK=N'D:\Temp\TestDB\Backup\TestFileGroup_Full.bak' WITH
MOVE 'PRIMARY' TO N'D:\Temp\TestDB\New\TestFileGroupNew_PRIMARY.mdf',
MOVE 'secondary' TO N'D:\Temp\TestDB\New\TestFileGroupNew_secondary.ndf',
MOVE 'TestFileGroup_log' TO N'D:\Temp\TestDB\New\TestFileGroupNew_log.ldf',
STATS=10 ,RECOVERY
--================================================================== For Restore Partial Backup Need Tail Backup
BACKUP LOG TestFileGroup_New
to DISK = N'D:\Temp\TestDB\Backup\TestFileGroup_New_Tail.trn' ---- Not Real
WITH NORECOVERY,FORMAT,COMPRESSION
GO
--================================================================== Restore FileGroup Backup
RESTORE DATABASE TestFileGroup_New FILEGROUP = N'FG2'
FROM DISK = N'D:\Temp\TestDB\BackUP\TestFileGroup_FG2.bak' WITH
NORECOVERY,REPLACE
GO
--==================================================================
RESTORE DATABASE TestFileGroup_New WITH RECOVERY
/*
Msg 4303, Level 16, State 1, Line 100
The roll forward start point is now at log sequence number (LSN) 37000000056800001. Additional roll forward past LSN 37000000058400001 is required to complete the restore sequence.
Msg 3013, Level 16, State 1, Line 100
RESTORE DATABASE is terminating abnormally.
*/
在恢复日志文件备份之前,您无法恢复。必须通过 WITH RECOVERY 将整个数据库调到一致的时间点。
文件组恢复后,FG2 领先于 FG1,恢复日志备份会将丢失的事务重播到 FG1。
从文档:
零碎恢复 - 应用日志备份
所以像:
此外,您无法将 TestFileGroup 的完整备份恢复到 TestFileGroup_new WITH RECOVERY,因为如果这样做,您将永远无法应用来自 TestFileGroup 的日志备份。