Piecemeal restore refers to restore just page,file or file group. If the SQL Server is Enterprise. SQL Server may do the online restore which means the database will be online and only the restoring file or file group is not accessible.
Lets Create new file group and add 1 file to the file group
- -- Create 2nd file group
- USE [master]
- GO
- ALTER DATABASE [AdventureWorks_new] ADD FILEGROUP [MYFILEGOUP]
- GO
- -- Add 2 files on the file group
- USE [master]
- GO
- ALTER DATABASE [AdventureWorks_new] ADD FILE ( NAME = N'GROUP2file1', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQL2008R2\MSSQL\DATA\GROUP2file1.ndf' , SIZE = 1024KB , FILEGROWTH = 1024KB ) TO FILEGROUP [MYFILEGOUP]
- GO
Exam the file group status
- --- Exam FIlegroup
- use [AdventureWorks_new]
- go
- SELECT df.name, df.size*8/1024 AS [SIZE IN MB],fg.name
- FROM sys.database_files df
- INNER JOIN
- sys.filegroups fg on df.data_space_id = fg.data_space_id
Create the Table on the new file group
- -- Create Tabe1 on FIle 1 add 1000 row data
- use [AdventureWorks_new]
- go
- CREATE TABLE TB_1
- (number INT IDENTITY(1,1) NOT NULL,
- name varchar(50) NOT NULL,
- updateTIme datetime default getdate(),
- ) on MYFILEGOUP
Backup the database
- --- Backup database
- BACKUP DATABASE [AdventureWorks_new] to DISK ='C:\dump\AdventureWorks_new.1.db' with format
- --- Exam the backup file
- RESTORE FILELISTONLY FROM DISK ='C:\dump\AdventureWorks_new.1.db'
Insert some data
- --- Insert Test data
- use [AdventureWorks_new]
- go
- DECLARE @count INT
- SET @count = 0
- WHILE (@count < 40000)
- BEGIN
- Insert into TB_1 (name)values('SUMMER')
- SET @count = (@count + 1)
- END
Backup the transaction log
- -- Backup Log
- BACKUP LOG [AdventureWorks_new] to DISK ='C:\dump\tran\AdventureWorks_new.1.log' with format
Exam the file group size change
- --- Exam FIlegroup
- use [AdventureWorks_new]
- go
- SELECT df.name, df.size*8/1024 AS [SIZE IN MB],fg.name
- FROM sys.database_files df
- INNER JOIN
- sys.filegroups fg on df.data_space_id = fg.data_space_id
- GO
- --- Exam table
- use [AdventureWorks_new]
- go
- declare @id int
- set @id = object_id('TB_1')
- exec sp_objectfilegroup @id
- go
- sp_spaceused TB_1
- go
- select top 5 * from TB_1
- go
To simulate the file group corruption, we need to shutdown the database and delete the GROUP2file1.ndf then restart the SQL Server.
Upon the SQL Server start up, you will find out the Database is in the RECOVERY PENDING state, the error log will also indicate it can not find the database file.
- --- database status
- SELECT state_desc DatabaseStatus_sysDatabase
- FROM sys.databases
- WHERE name = 'AdventureWorks_new'
- GO
Lets start the piece meal recovery
First, we need to backup the tail log
- --- Backup tail log
- use master;
- BACKUP LOG [AdventureWorks_new] TO DISK ='C:\dump\tran\AdventureWorks_new.tail.log' WITH NORECOVERY, NO_TRUNCATE, FORMAT
Check the Database status again, the status become “RESTORING”
- --- database status
- SELECT state_desc DatabaseStatus_sysDatabase
- FROM sys.databases
- WHERE name = 'AdventureWorks_new'
- GO
Since the Primary file group is intact, Lets bring it up ASAP
Restore Primary file group , log 1 and the tail log
- --- Restore filgrop from backup
- RESTORE DATABASE [AdventureWorks_new] FILEGROUP='PRIMARY' FROM disk ='C:\dump\AdventureWorks_new.1.db'
- WITH PARTIAL, NORECOVERY
- --- Revcover log
- RESTORE LOG [AdventureWorks_new] FROM DISK ='C:\dump\tran\AdventureWorks_new.1.log' WITH NORECOVERY
- RESTORE LOG [AdventureWorks_new] FROM DISK ='C:\dump\tran\AdventureWorks_new.tail.log' WITH RECOVERY
Check the status again, the database is online now, but if you try to select the TB1, you will get the error message regarding the file group is not online. The table in the primary file group will be accessible for user .
Lets restore the 2nd file group.
- --- Recover the filgroup
- use master;
- RESTORE DATABASE [AdventureWorks_new] FILEGROUP='MYFILEGOUP' FROM disk ='C:\dump\AdventureWorks_new.1.db' WITH NORECOVERY
- RESTORE LOG [AdventureWorks_new] FROM DISK ='C:\dump\tran\AdventureWorks_new.1.log' WITH NORECOVERY
- RESTORE LOG [AdventureWorks_new] FROM DISK ='C:\dump\tran\AdventureWorks_new.tail.log' WITH RECOVERY
Now , you have fully usable database.
Reference
Performing Piecemeal Restores http://msdn.microsoft.com/en-us/library/ms177425.aspx
Perform Page restore http://msdn.microsoft.com/en-us/library/ms175168.aspx
Sơn Song Thánh sao?
ReplyDeleteLão bà áo tím kinh ngạc vô cùng nhìn Nhạc Thành mà nói.
Những người khác cũng kinh ngạc không tưởng tượng nổi nhìn Nhạc Thành, giết bốn cường giả Đấu Thánh, điều này tuyệt đối không ai tin tưởng.
- Không sai, ta vừa mới trở về từ Hồ Điệp cốc, đụng phải đám người U Minh Thánh, sư tôn cũng bị một vết thương nhẹ.
Nhạc Thành cất tiếng nói với lão bà áo tím.
- Nói như vậy, ngươi thực sự giết bốn cường giả Đấu Thánh?
dongtam
mu moi ra hom nay
tim phong tro
http://nhatroso.com/
nhạc sàn
tổng đài tư vấn luật
văn phòng luật hà nội
tổng đài tư vấn luật
thành lập công ty trọn gói
http://we-cooking.com/
chém gió
trung tâm tiếng anh
Lão bà áo tím nhìn thấy ý tứ của Nhạc Thành, tự nhiên là tin tưởng lời nói của Nhạc Thành.
- Bốn đấu thánh, cũng chỉ có hai nhị tinh Đấu Thánh mà thôi, cũng không có gì.
Nhạc Thành cất tiếng nói.
Nghe thấy lời nói của Nhạc Thành, Cuồng Sư môn, Vạn Kim Môn, Tuyệt Tình cốc ba thái thượng trưởng lão nhìn nhau, không biết trong lòng bọn họ đang nghĩ gì.