Groups | Blog | Home
all groups > sql server programming > october 2006 >

sql server programming : Copy DB in Express



Kungen
10/18/2006 11:31:59 PM
Hi!

This question is a bit embarrasing since it's so basic.

Copying a database in SQLserver2005 is done in tasks/copy. Now I'm
using the Express Edition and there is no "Copy" function under
"Tasks", so I did a copy of the DB right in the folder where it's
physically located and tried to get the copy in by attaching it.
Doesn't seem to be the right method, though. It tries to attach it to
the DB that it is a copy of, so I guess I misunderstood the meaning of
"attach".

I just want to make a copy of a DB and I don't want the copy to have
any connection to the DB it is a copy of.

What do I do?
Martin Poon [MVP]
10/19/2006 12:00:00 AM
How about backing up the database and restoring it to another database from
the backup files?

--
Martin C K Poon
Microsoft MVP - SQL Server
----------
- SQL Server 2005 & 2000 books online
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
========================================
[quoted text, click to view]

Kungen
10/19/2006 3:08:54 AM
Hi Martin!

I've tried that but I can't make it work. I make a backup and try to
restore it to a new database, created for this purpose, named
'mydatabase'. When trying to restore, an error msg is displayed, saying
that the restoration failed, and with the details (translated from
Swedish):

System.Data.SqlClient.SqlError: There is already a backup copy of
another database for the existing
'mydatabase'-database.(Microsoft.SqlServer.Express.Smo)

I don't understand this message since I definitely havn't done any
previous backup copy of or for 'mydatabase'. I haven't done anything
but created an empty database with that name.

The full version of SQLserver 2005 has a very simple command for
copying. Isn't there an equally simple way of doing it in Express
edition?

Kungen
Kungen
10/19/2006 7:09:00 AM
Thanks (again!) Tracy!

I've found this in the help section, which I executed (my names):

BACKUP DATABASE mydatabase
TO mydatabaseBU ;

RESTORE FILELISTONLY
FROM mydatabaseBU ;

RESTORE DATABASE mydatabaseCOPY
FROM mydatabaseBU
WITH MOVE 'mydatabase_Data' TO 'C:\MySQLServer\mydatabaseCOPY.mdf',
MOVE 'mydatabase_Log' TO 'C:\MySQLServer\mydatabaseCOPY.ldf';
GO

I get this error message in return (translated from Swedish):

Msg 3206, Level 16, State 1, Line 1
There is no post in sysdevices for the backup unit 'mydatabaseBU'.
Update sysdevices and execute the statement again.
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE interrupted.

Msg 3206, Level 16, State 1, Line 4
There is no post in sysdevices for the backup unit 'mydatabaseBU'.
Update sysdevices and execute the statement again.
Msg 3013, Level 16, State 1, Line 4
BACKUP DATABASE interrupted.

Msg 3206, Level 16, State 1, Line 7
There is no post in sysdevices for the backup unit 'mydatabaseBU'.
Update sysdevices and execute the statement again.
Msg 3013, Level 16, State 1, Line 7
BACKUP DATABASE interrupted.

I don't know what this means and searching the help section for
"sysdevices" didn't return anything helpful.

Sorry, but I'm stuck again.

Thanks for your time.

Kungen
Kart
10/19/2006 8:15:20 AM
Hi Kungen,

The backup and restore statement seem fine. I assume you have created
the devices.

Can you also try the backup statements direct to disk ....as follows

BACKUP DATABASE mydatabase TO DISK = 'C:\mydb.bak'

RESTORE DATABASE mydatabaseCOPY
FROM DISK = 'C:\mydb.bak'
WITH MOVE 'mydatabase_Data' TO 'C:\MySQLServer\mydatabaseCOPY.mdf',
MOVE 'mydatabase_Log' TO 'C:\MySQLServer\mydatabaseCOPY.ldf', REPLACE

I assume that the folder C:\MySQLServer already exists

Let us know....

Kart

[quoted text, click to view]
Tracy McKibben
10/19/2006 8:15:52 AM
[quoted text, click to view]

Use the BACKUP DATABASE command to create a backup. Use RESTORE
DATABASE, including the WITH MOVE option to restore that backup as a new
database name. WITH MOVE is required so that you can specify new
physical filenames for the MDF and LDF files. Restoring without WITH
MOVE will attempt to restore to the original physical files.


--
Tracy McKibben
MCDBA
Kungen
10/19/2006 10:59:08 AM
Hi (again) Kart!

No, I haven't created the devices cause I don't know what "devices" or
"sysdevices" is. That's why I don't understand the error message
mentioned above. What should I have done that I didn't?

I also tried your new script. (Thank you) The backup part of it works,
but the restore part returns this error message (translated from
Swedish):

Msg 3234, Level 16, State 2, Line 4
The logical file mydatabase_Data is not a part of the database
mydatabaseCOPY. Use RESTORE FILELISTONLY to retrieve a list of the
names for the logical files.
Msg 3013, Level 16, State 1, Line 4
RESTORE DATABASE interrupted.

And I'm sad to say that I don't understand this error message either...
:o(

Thank you for your time. I'm quite new to this and I really appreciate
all the help I can get.

Kungen
Kungen
10/19/2006 12:16:12 PM
Hi!

Big thank you's for your patience.

Yes I better bypass it because I don't know what it is...

The problem is, as I wrote above, that when I use the script you
supplied (thanks):

RESTORE DATABASE mydatabaseCOPY
FROM DISK = 'C:\mydb.bak'
WITH MOVE 'mydatabase_Data' TO
'C:\MySQLServer\mydatabaseCOPY.mdf',
MOVE 'mydatabase_Log' TO 'C:\MySQLServer\mydatabaseCOPY.ldf',
REPLACE

I get another error message that I don't understand either:

Msg 3234, Level 16, State 2, Line 4
The logical file mydatabase_Data is not a part of the database
mydatabaseCOPY. Use RESTORE FILELISTONLY to retrieve a list of the

names for the logical files.
Msg 3013, Level 16, State 1, Line 4
RESTORE DATABASE interrupted.

What does it mean and what should I do?
(Or, if your growing bored with my ignorance, could you please nod in a
direction where I can find further guidance?)

A very thankful
Kungen
Tracy McKibben
10/19/2006 1:06:51 PM
[quoted text, click to view]

This is because you are attempting to backup to a pre-defined deviced
named "mydatabaseBU", which you haven't defined yet. It's much easier
to bypass the whole device construct, and use "TO
DISK=c:\somepath\somefile" instead. This applies to BACKUP and RESTORE
both.


--
Tracy McKibben
MCDBA
Kungen
10/19/2006 1:28:27 PM
Hi again and thank you for your time.

I'm sorry, but I don't know what "Use RESTORE FILELISTONLY to see the
valid logical
filenames" means.

I understand if my question annoys you, but I really need to make an
"independent" copy with a new name of my database and I just don't
understand how to do it. Isn't there an easy way to do it without
writing script? Like in the full version?

Or could you please tell me if you know where to look for a basic
tutorial on these matters, or what keywords to use when searching the
books online, since I'm obviously not knowledgeble enough to understand
what you are saying to me. For example, I don't know what sysdevice is
and I don't know what "logical file name" means etc.

Thanks

Kungen
Tracy McKibben
10/19/2006 2:36:41 PM
[quoted text, click to view]

Every SQL database has, at minimum, two logical filenames and two
physical filenames, one for the data file and one for the log file.
This error is telling you that the logical filename "mydatabase_Data"
that you specified in your WITH MOVE clause is not valid for this
database backup. Use RESTORE FILELISTONLY to see the valid logical
filenames for your database backup.


--
Tracy McKibben
MCDBA
AddThis Social Bookmark Button