Sunday, March 25, 2012

Create a new database from a .bak backup

Hi
You don't need to start with a database when restoring. Click on the
database leaf in the tree and then enter your own database name in the
database name box, then go on and choose the file to restore from using the
restore from device option.
If you know that there is only one backup in the file and the database
doesn't exist you could use something like the following from a query window
if you change the file path/name and database name:
RESTORE DATABASE NewDatabase
FROM DISK = 'D:\Backups\DBBACKUP.bak'
GO
John
"GM" <guidomarche@.libero.it_n0sp4m> wrote in message
news:XbvAj.10735$q53.6897@.tornado.fastwebnet.it...
> Hi, i have a problem:
> I have a .bak file from a database backup, but i don't have the database
> anymore.
> How can i create the database from the backup file?
> If i try to restore the database with management studio, i should already
> have a database to put the data in.. but i don't have it anymore.
>
> If i create a new database, and try to put the backed up data into it, i
> got
> an error:
> Msg 3154, Level 16, State 4, Line 1
> The backup set holds a backup of a database other than the existing 'XXX'
> database.
>
> Is there a way to re-create the database from the backup?(it's a full
> backup)
> I'm working with MSSQL Server 2005 and Management Studio.
> Thank you for any advice!
>
>
"GM" <guidomarche@.libero.it_n0sp4m> wrote in message
news:7VxAj.10913$q53.947@.tornado.fastwebnet.it...
> Hi, thank you for the answer!
> the .bak file contains only one backup
> If i use the restore option, and type a new database name, when i execute
> i get te following error:
> Msg 5133, Level 16, State 1, Line 1
> Directory lookup for the file "D:\Microsoft SQL
> Server\MSSQL.1\MSSQL\DATA\XXX_Data.mdf" failed with the operating system
> error 3(The system cannot find the path specified.).
>
> I've already tryed
> RESTORE DATABASE NewDatabase
> FROM DISK = 'D:\Backups\DBBACKUP.bak'
> (with the right location/dbname)
> but if the database does not exists, i got an error:
> Msg 5133, Level 16, State 1, Line 1
> Directory lookup for the file "D:\Microsoft SQL
> Server\MSSQL.1\MSSQL\DATA\XXX_Data.mdf" failed with the operating system
> error 3(The system cannot find the path specified.).
> Msg 3156, Level 16, State 3, Line 1
> File 'XXX_Data' cannot be restored to 'D:\Microsoft SQL
> Server\MSSQL.1\MSSQL\DATA\XXX_Data.mdf'. Use WITH MOVE to identify a valid
> location for the file.
> Msg 5133, Level 16, State 1, Line 1
> Directory lookup for the file "D:\Microsoft SQL
> Server\MSSQL.1\MSSQL\DATA\XXX_Log.ldf" failed with the operating system
> error 3(The system cannot find the path specified.).
> Msg 3156, Level 16, State 3, Line 1
> File 'XXX_Log' cannot be restored to 'D:\Microsoft SQL
> Server\MSSQL.1\MSSQL\DATA\XXX_Log.ldf'. Use WITH MOVE to identify a valid
> location for the file.
> Msg 3119, Level 16, State 1, Line 1
> I've tryed to use "WITH MOVE " tu point to another folder, but since i
> don't have the mdf file, it's pointless...
>
Umm, that's not pointless at all. That's the exact whay you do this.
RESTORE DATABASE NewDatabase
from disk='D:\Backups\DBBACKUP.bak'
with move 'XXX_Data' to 'C:\newlocation_fordata\XXX_LOG.MDF',
move 'XXX_log' to 'C:\newlocation_forlogs\XXX_LOG.LDF'

> If i create a new database with the same name of the database i want to
> restor,e before trying to restore, i got the error i reported in the
> previous post..
|||RESTORE DATABASE [NewDatabaseName]
FROM DISK='BackupNameAndPath'
WITH MOVE 'OldDatabaseName' TO 'NewDatabaseNameAndPath.mdf',
MOVE 'OldDatabaseName_log' TO 'NewDatabaseNameAndPath.ldf'
NB the MOVEd strings are the logical database names. Use
RESTORE HEADERONLY FROM DISK = 'BackupNameAndPath'
to get a listing of the contents of the backup file to determine the
old database name.
sql

No comments:

Post a Comment