Sql-Server

如何在 Sql Server 2008 中備份和恢復單個 FILEGROUP

  • October 15, 2014

以前,在 ServerFault 上,我問了一個關於備份和恢復 Sql Server 2008 文件組的問題。

今天,當我嘗試RESTORE其中一個FILEGROUP備份時,出現以下錯誤:-

Processed 1895080 pages for database 'XWing', file 'XWing' on file 1.
Processed 4 pages for database 'XWing', file 'XWing_log' on file 1.
The database cannot be recovered because the log was not restored.
The database cannot be recovered because the log was not restored.
The roll forward start point is now at log sequence number (LSN) 221218000000010400001. Additional roll forward past LSN 221218000000010400001 is required to complete the restore sequence.
This RESTORE statement successfully performed some actions, but the database could not be brought online because one or more RESTORE steps are needed. Previous messages indicate reasons why recovery cannot occur at this point.
RESTORE DATABASE ... FILE=<name> successfully processed 1895084 pages in 69.504 seconds (213.014 MB/sec).

我使用了以下 Sql 程式碼…

alter Database [XWing] SET SINGLE_USER With ROLLBACK IMMEDIATE

restore database [XWing] filegroup = 'PRIMARY'
FROM  DISK = N'C:\Temp\XWing Manual Full Primary Filegroup.bak'
with
   MOVE N'XWing' TO N'D:\XWing.mdf',
   MOVE N'XWing_log' TO N'L:\XWing_Log.ldf',
   replace, recovery

所以我假設數據庫沒有正確備份?

這是我用來備份的腳本PRIMARY FILEGROUP

BACKUP DATABASE [XWing] FILEGROUP = N'PRIMARY' 
TO  DISK = N'F:\Sql DB Backups\XWing Manual Full Primary Filegroup.bak' WITH NOFORMAT, INIT,
NAME = N'XWing-Full Filegroup Backup', SKIP, NOREWIND, NOUNLOAD, COMPRESSION,  STATS = 10
GO
declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=N'XWing' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'XWing' )
if @backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''XWing'' not found.', 16, 1) end
RESTORE VERIFYONLY FROM  DISK = N'F:\Sql DB Backups\XWing Manual Full Primary Filegroup.bak' WITH  FILE = @backupSetId,  NOUNLOAD,  NOREWIND
GO

問題

  1. 恢復語法正確嗎?
  2. 我的備份語法呢?

乾杯!

您需要恢復事務日誌,以便擁有一致的數據庫。目前,您已恢復的文件組與數據庫的其餘部分處於不同的時間點。一旦日誌前滾並且一切一致,您就可以使數據庫聯機。

如果您查看 msdb 數據庫中的數據,您將能夠看到需要恢復哪些事務日誌文件才能使數據庫聯機。

您的備份和恢復語法沒有問題。

正如消息中所述,您必須將日誌備份還原到文件組備份的時間點。為了使數據庫聯機,它需要將日誌回放到同一時間點,以使數據庫保持一致。但是,僅恢復主文件組是一種特殊情況。我相信為了恢復主文件組,您幾乎必須進行完全恢復,而不僅僅是文件組。(我對此並不積極,但相信下面的文字指出了這一要求。)

了解備份的還原和恢復如何在 SQL Server 中工作

重做一致性

在重做階段,數據總是前滾到與恢復點的數據庫狀態重做一致的點。所有數據都已前滾到可以撤消的點。

數據庫的狀態由主文件定義,如下:

如果正在恢復主文件,則恢復點將確定整個數據庫的狀態。例如,如果將數據庫恢復到表被意外刪除之前的某個時間點,則必須將整個數據庫恢復到同一時間點。

如果未恢復主文件,則數據庫狀態是已知的,並且恢復的數據將前滾到與數據庫在事務上一致的恢復點。SQL Server 強制執行此操作。

但是,數據庫可能包含在恢復點未送出的事務所做的更改。對於聯機恢復,數據恢復到與數據庫聯機部分的目前狀態一致的時間點。

引用自:https://dba.stackexchange.com/questions/5511