Restore a database to another server

Restore a database to another server

am 15.11.2007 19:43:24 von Seguros Catatumbo

Hi, i am using sql server 2000, and i make daily backups. I want to
restore my backup to a test msde database i have. I don't know how i
did it last time.

-The database name is the same: "web" on both places
-The database is located on different hard drives and the file name
are different on both places.

I tried to do it from enterprise manager, restore database, from
device, i chose the transaction file and the database backup itself
and tried to restore, but i got an error that i don't have exclusive
access to the database.

How can i fix this?

Re: Restore a database to another server

am 15.11.2007 22:57:09 von Erland Sommarskog

Seguros Catatumbo (seguroscatatumbo@gmail.com) writes:
> Hi, i am using sql server 2000, and i make daily backups. I want to
> restore my backup to a test msde database i have. I don't know how i
> did it last time.
>
> -The database name is the same: "web" on both places
> -The database is located on different hard drives and the file name
> are different on both places.
>
> I tried to do it from enterprise manager, restore database, from
> device, i chose the transaction file and the database backup itself
> and tried to restore, but i got an error that i don't have exclusive
> access to the database.

RESTORE DATABASE db FROM DISK ='filenamehere'
WITH MOVE 'logicalname1' TO 'path.mdf',
MOVE 'logicalname2' TO 'path_log.ldf',
REPLACE

logicalname1/2 are the logical names of the device file. You find these
with help of sp_helpdb on the source database, or RESTORE FILELISTONLY
on the backup file.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downlo ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books .mspx

Re: Restore a database to another server

am 16.11.2007 13:09:32 von Seguros Catatumbo

> RESTORE DATABASE db FROM DISK ='filenamehere'
> WITH MOVE 'logicalname1' TO 'path.mdf',
> MOVE 'logicalname2' TO 'path_log.ldf',
> REPLACE
>

Hey Erland, thanks for replying. I couldn't get it to work. Here's the
command:

RESTORE DATABASE db FROM DISK ='c:\publica\web_db_200711150500.bak'
WITH MOVE 'WEB_Data' TO 'c:\pruebadb\web_dos.mdf',
MOVE 'WEB_Log' TO 'c:\pruebadb\web_dos_log.ldf',
REPLACE

Here's the error message:

The file 'c:\pruebadb\web_dos.mdf' cannot be overwritten. It is being
used by database 'web'.
File 'WEB_Data' cannot be restored to 'c:\pruebadb\web_dos.mdf'. Use
WITH MOVE to identify a valid location for the file.
The file 'c:\pruebadb\web_dos_log.ldf' cannot be overwritten. It is
being used by database 'web'.
File 'WEB_Log' cannot be restored to 'c:\pruebadb\web_dos_log.ldf'.
Use WITH MOVE to identify a valid location for the file.
RESTORE DATABASE is terminating abnormally.

Here's the output of sp_helpdb on the source db and destination db:

source:

WEB_Data
1 D:\DataWEB\Data
\web_Data.MDF
PRIMARY 4348096 KB Unlimited 5120 KB data only
WEB_Log
2 D:\DataWEB\Data
\web_Log.LDF
NULL 32448 KB Unlimited 10% log only


destination:

WEB_Data
1 C:\pruebadb
\web_dos.mdf
PRIMARY 2092928 KB Unlimited 5120 KB data only
WEB_Log
2 C:\pruebadb
\web_dos_log.ldf
NULL 1024 KB Unlimited 10% log only


The c:\publica\web_db_200711150500.bak was obtained from a backup made
by sql server itself on the source server itself

Re: Restore a database to another server

am 16.11.2007 13:41:14 von Seguros Catatumbo

I made a mistake with the command. My database name is not db, it's
"web". So now i get the same error i get when i do with the GUI:

RESTORE DATABASE db FROM DISK ='c:\publica\web_db_200711150500.bak'
WITH MOVE 'WEB_Data' TO 'c:\pruebadb\web_dos.mdf',
MOVE 'WEB_Log' TO 'c:\pruebadb\web_dos_log.ldf',
REPLACE

Here's the error message:

Exclusive access could not be obtained because the database is in use.

Do i need to take the database offline or something?

Re: Restore a database to another server

am 16.11.2007 13:48:40 von Seguros Catatumbo

Ok, i think i know how to fix it.

-WEB is my default database, so when i use query analizer it opens
that database. It can't restore the database if i am connected. So
instead of figuring off how to change the default database, i
connected, changed the current db to master (use master), and then i
could take web offline with enterprise manager. Now the command seems
to be working, it will take long, the database is 4GB.

RESTORE DATABASE web FROM DISK ='c:\publica\web_db_200711150500.bak'
WITH MOVE 'WEB_Data' TO 'c:\pruebadb\web_dos.mdf',
MOVE 'WEB_Log' TO 'c:\pruebadb\web_dos_log.ldf',
REPLACE

Re: Restore a database to another server

am 16.11.2007 16:13:44 von Seguros Catatumbo

Yup, it worked, so the conclusion is that it would have worked from
the start if i just would have taken the database offline. Thanks for
your help