SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 BACKUP/RESTORE to different database name
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

joriz
Starting Member

2 Posts

Posted - 06/18/2004 :  19:01:09  Show Profile  Reply with Quote
I have 2 databases called UC_MAIN and UC_DEV. They are exactly the same except for the name of course. i wanna backup the data/logs from the uc_main and restore it to uc_dev. Im having all sort of problems. I tried restore database with replace, MOve..it didnt work..

anybody has the step by step tsql that do this.

i know i can do DTS. but i wanna do it using tsql first.

please help..TIA

tkizer
Almighty SQL Goddess

USA
36983 Posts

Posted - 06/18/2004 :  19:08:34  Show Profile  Visit tkizer's Homepage  Reply with Quote
BACKUP DATABASE uc_main
TO DISK = 'F:\MSSQL\BACKUP\uc_main.BAK;
WITH INIT

RESTORE DATABASE uc_dev
FROM DISK = 'F:\MSSQL\BACKUP\uc_main.BAK'
WITH MOVE 'uc_main_data' TO 'F:\MSSQL\BACKUP\uc_dev_data.MDF',
MOVE 'uc_main_log' TO 'F:\MSSQL\BACKUP\uc_dev_log.ldf',
REPLACE

You just need to figure out which logical names to use in the WITH MOVE option. Use RESTORE FILELISTONLY for this.

Tara
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

USA
4184 Posts

Posted - 06/18/2004 :  19:13:12  Show Profile  Visit derrickleggett's Homepage  Send derrickleggett an AOL message  Send derrickleggett a Yahoo! Message  Reply with Quote
--This will give you the name of the logical files on the backup file.
RESTORE FILELISTONLY
FROM DISK = 'file.bak'

--You then need to restore using both replace and move.
RESTORE database_name
FROM DISK = file.bak
WITH
MOVE 'logical_file_data' TO 'file.mdf',
--logical_file_data is the data file from RESTORE FILELISTONLY.
--file.mdf is the .mdf file for the database.
MOVE 'logical_file_log' TO 'file.ldf',
--logical_file_log is the log file from RESTORE FILELISTONLY.
--file.mdf is the .ldf file for the database.
REPLACE



MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

joriz
Starting Member

2 Posts

Posted - 06/18/2004 :  19:30:05  Show Profile  Reply with Quote
thanks..guys..it works sweet!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000