The following error occurs when you restore a database file group:
MSG 3159, level 16, state 1, line 1
The tail of the log for the database "testfile" has not been backedup. use backup log with norecovery to backup the log if it contains work you donot want to lose. use the with replace or with stopat clause of the restorestatement to just overwrite the contents
Of the log.
MSG 3013, level 16, state 1, line 1
Restore database is terminating abnormally.
There are two ways to solve this problem:
1. Back up the tail log: if the database encounters a problem and you confirm that the tail log has some required information, it is very useful to back up the tail log.
-- Backup primaryfilegroup
Backup database [testfile] filegroup =
N 'Primary'
Disk = n'd: \ primary. Bak'
-- Backupsecondary filegroup
Backup database [testfile] filegroup =
N 'test1'
Disk = n'd: \ secondeary. Bak'
-- Backup log
Backup log [testfile]
Disk = 'd: \ log. trn'
-- Backup taillog
Backup log [testfile]
Disk = 'd: \ log1.trn'
Withnorecovery
-- Restoreprimary filegroup
Restore database testfile filegroup = 'primary'
From Disk
= N' D: \ primary. Bak'
Withnorecovery
-- Restoresecondary filegroup
Restore database testfile filegroup = 'test1'
From Disk
= N'd: \ secondeary. Bak 'withnorecovery
-- Restore firstlog with norecovery
Restore log [testfile] From
Disk =
N'd: \ log. trn' with file
= 1, norecovery,
Nounload,
Stats = 10
-- Restore taillog with recovery
Restore log [testfile] From
Disk =
N'd: \ log1.trn' with file
= 1, recovery,
Nounload,
Stats = 10
2. If the log tail cannot be backed up, use the with stopat statement in the restore statement.
Or the with replace clause.
-- Backup primaryfilegroup
Backup database [testfile] filegroup =
N 'Primary'
Disk = n'd: \ primary. Bak'
-- Backupsecondary filegroup
Backup database [testfile] filegroup =
N 'test1'
Disk = n'd: \ secondeary. Bak'
-- Backup log
Backup log [testfile]
Disk = 'd: \ log. trn'
-- Restoreprimary filegroup
Restore database testfile filegroup = 'primary'
From Disk
= N' D: \ primary. Bak'
Withreplace, norecovery
-- Restoresecondary filegroup
Restore database testfile filegroup = 'test1'
From Disk
= N'd: \ secondeary. Bak 'withnorecovery
-- Restore firstlog with norecovery
Restore log [testfile] From
Disk =
N'd: \ log. trn' with file
= 1, recovery,
Nounload,
Stats = 10
For more information, see mssqlserver_3159http: // msdn.microsoft.com/en-us/library/bb283410.aspx.