Monday, March 26, 2012

restore to new db restores less data than what is in the source backup file

I am trying to create sql code that restores a backup of a master database to a new database on the same server. It seems to run correctly as no errors are produced. However, the most recent updates to the master database are not present in the new databases. All databases are using the Full recovery model. What is really strange is that if I do (what I think is) the same function in Enterprise Administrator, the restore works fine! For both methods I used the same backup file!



Any and all help is sincerely appreciated.


The master databases from which the backups are made start with MODTRNMaster

The databases which are created from the restores start with M1_ and M2_. (We call them training room databases.)



My script for backing up the master databases:



-- Backup the master training database

backup database MODTRNMaster
to disk = 'f:\bkup\MODTRNMaster.bak'

backup database MODTRNMaster_IMG
to disk = 'f:\bkup\MODTRNMaster_IMG.bak'

backup database MODTRNMaster_MNC
to disk = 'f:\bkup\MODTRNMaster_MNC.bak'

backup database MODTRNMaster_VM
to disk = 'f:\bkup\MODTRNMaster_VM.bak'

go


This is the restore script for restoring the first training room databases. Im hoping that there is just something simple that Im overlooking in these restore statements! J



-- Restore the backup of the master training database into the

-- training room #1 database.

use master
go

drop database M1_MSLH
go

restore database M1_MSLH
from disk = 'f:\bkup\MODTRNMaster.bak'
with move 'DEV5_Data' to 'f:\mssql\data\M1_MLSH.mdf',
move 'MM' to 'f:\mssql\data\M1_MLSH_1.mdf',
move 'AMB' to 'f:\mssql\data\M1_MLSH_2.mdf',
move 'DM' to 'f:\mssql\data\M1_MLSH_3.mdf',
move 'IMM' to 'f:\mssql\data\M1_MLSH_4.mdf',
move 'ED' to 'f:\mssql\data\M1_MLSH_5.mdf',
move 'DEV5_Log' to 'f:\mssql\log\M1_MLSH_log.ldf',
recovery

go



Thanks in advance

:eek:

:eek:that surely sounds like some magic. I do not know off the the top of my head what the problem could be but you should only have one mdf file and the rest of your data files should be ndfs.|||I am trying to create sql code that restores a backup of a master database to a new database on the same server. It seems to run correctly as no errors are produced. However, the most recent updates to the master database are not present in the new databases. All databases are using the Full recovery model. What is really strange is that if I do (what I think is) the same function in Enterprise Administrator, the restore works fine! For both methods I used the same backup file!

Are you sure that the master database is in full recovery mode? I did not think that was possible and/or mattered.

Also, even if it is in full recovery, your restore script indicated that you had restored only the last full backup (.BAK) file and had not restored any transaction logs (.TRN). Without restoring the transaction logs, you will only restore the database to the point in time when the last full backup completed; any transacations performed after that will not get restored.

Finally, I have to ask: why are you restoring the master database? I'm not sure that doing so gets you anything (except maybe practice).

Regards,

hmscott|||sorry. I should have been a little clearer. :o It is not actually THE master database that I'm backing up. We are having some training sessions for users of a new system. The trainer makes his updates in a database named MODTRNMaster (the master database for our purposes). At night I am restoring into 2 individual training databases M1_MLSH and M2_MLSH that the users are accessing.

No transaction log backups are being done. These databases are only being accessed during the day. At night there is no activity in those databases. At night I backup MODTRNMaster and then immediately (attempt to) restore the backup file as M1_MLSH and then again as M2_MLSH.|||You need to add with init to your backup commands, or with file = # to the restore commands. By default, SQL Server will append your backup to the exisiting file (you may have noticed them getting bigger), and restore from the first backup found. Do this and get back to us with the results:

restore headeronly from disk = 'f:\bkup\MODTRNMaster.bak'|||Thanks So much for your suggestion! Adding the "init" parameter to the backup database statement was exactly what was needed!! :D

No comments:

Post a Comment