We're currently migrating our LIMS (Laboratory Information Management System) from Oracle to MS-SQL, and I'm having difficulty in a a certain area. We run three separate instances: Production, Development & Test. The Prod instance is the live one, being used by the laboratories, the dev instance is where I mess around developing new features, and the test instance is where those new features get tested before deployment to production. This being the case, I periodically copy (using backup/restore) the production database to the other two instances, so that I'm working with the same configuration as the operators. However, the production DB contains a large amount of archived data which I don't need in the dev/test instances, so I don't include those tables in the backup - this saves me tens of minutes in the process. Oracle is good for this because you can specify the tables to be included in a backup. However, AFAIK this isn't possible in MS-SQL, but what can be done is to put the active and archive tables into different filegroups. These can then be backed up separately.
I've successfully created a backup of my PRIMARY filegroup, but I'm having great difficulty restoring it. Sometimes the command completes but the database remains inaccessible and I'm told that the restore has not completed - other times it just refuses to execute the command. This seems to be related to the transaction log, but this stretches my knowledge.
The backup command I'm using is:
BACKUP DATABASE production FILEGROUP='PRIMARY' TO DISK='C:\Temp\db.bak' WITH FORMAT,COPY_ONLY
The restore command I'm trying is:
RESTORE DATABASE development FROM DISK='C:\Temp\db.bak' WITH REPLACE,NORECOVERY
and it tells me that 'The backup set holds a backup of a database other than the existing 'development' database'.
At the moment the source and dest are in the same instance of SQL Server, but in future they will be on completely different machines, possibly with no direct connectivity (so I have to go via some type of file transfer). Both are configured with Full recovery.
I've found a few similar questions, but they haven't really helped me. Is this a reasonable way to create this partial clone of my production database? How do I get my restore command to work as I need it to?
答案 0 :(得分:2)
You are on the right track, but you need to backup the tail log as well since you are in FULL recovery model, and restore the log files since the last backup of the filegroup. If the log backups are happening infrequent (like every hour) then you only need to take the tail log backup and restore this single log file after you restore the filegroup. You also need to add WITH PARTIAL
and FILEGROUP = 'PRIMARY'
to the restore command.
It would look something like this:
BACKUP DATABASE production FILEGROUP='PRIMARY' TO DISK='C:\Temp\db.bak' WITH FORMAT
GO
BACKUP LOG productionLog TO DISK 'C:\Temp\tail.trn'
GO
RESTORE DATABASE development FILEGROUP = 'Primary' FROM DISK='C:\Temp\db.bak' WITH PARTIAL,NORECOVERY
RESTORE LOG FROM DISK 'C:\Temp\tail.trn' WITH RECOVERY
答案 1 :(得分:0)
非常感谢您的建议-它使我感动,但我仍然遇到问题。我现在正在使用以下命令:
BACKUP DATABASE Prod FILEGROUP='PRIMARY' TO DISK='C:\Temp\Temp\prod.bak' WITH FORMAT;
BACKUP LOG Prod TO DISK='C:\Temp\Temp\prod.trn';
RESTORE DATABASE Test FILEGROUP='PRIMARY' FROM DISK='C:\Temp\Temp\prod.bak' WITH PARTIAL,RECOVERY;
RESTORE LOG Test FROM DISK='C:\Temp\Temp\prod.trn' WITH RECOVERY;
我得到以下答复:
Processed 376 pages for database 'Prod', file 'Prod' on file 1.
Processed 2 pages for database 'Prod', file 'Prod_log' on file 1.
BACKUP DATABASE...FILE=<name> successfully processed 378 pages in 0.082 seconds (36.013 MB/sec).
Processed 7 pages for database 'Prod', file 'Prod_log' on file 6.
BACKUP LOG successfully processed 7 pages in 0.007 seconds (7.254 MB/sec).
Msg 3154, Level 16, State 4, Line 3
The backup set holds a backup of a database other than the existing 'Test' database.
Msg 3013, Level 16, State 1, Line 3
RESTORE DATABASE is terminating abnormally.
Msg 3154, Level 16, State 4, Line 4
The backup set holds a backup of a database other than the existing 'Test' database.
Msg 3013, Level 16, State 1, Line 4
RESTORE LOG is terminating abnormally.
如果我使用WITH REPLACE
而不是WITH PARTIAL
,则会收到不同的错误消息:
The database cannot be recovered because the log was not restored.
The roll forward start point is now at log sequence number (LSN) 35000000203200001. Additional roll forward past LSN 35000000203200001 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 378 pages in 0.024 seconds (123.046 MB/sec).
Msg 4326, Level 16, State 1, Line 4
The log in this backup set terminates at LSN 35000000092800001, which is too early to apply to the database. A more recent log backup that includes LSN 35000000203200001 can be restored.
Msg 3013, Level 16, State 1, Line 4
RESTORE LOG is terminating abnormally.
如果我在数据库还原中使用WITH NORECOVERY
,该命令会成功,但是RESTORE LOG
然后会给我:
RESTORE DATABASE ... FILE=<name> successfully processed 378 pages in 0.032 seconds (92.285 MB/sec).
Msg 4326, Level 16, State 1, Line 4
The log in this backup set terminates at LSN 35000000092800001, which is too early to apply to the database. A more recent log backup that includes LSN 35000000203200001 can be restored.
Msg 3013, Level 16, State 1, Line 4
RESTORE LOG is terminating abnormally.
在任何情况下,目标数据库都处于“正在还原”状态。