Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to restore with script from file?

Status
Not open for further replies.

toetag

MIS
Sep 27, 2002
166
US
Could someone point me to a resource for creating a script to restore a DB from a file device?

Going to be working on a SQL2000 server, where I wont have access to the console or enterprise manager. I've scripted creating the DB, backing up the DB but need to figure out the restore from file device part.

any assistance as always is much appreciated.
 
Hi I wrote a SP for restoring backup file.
------------------------------------------------------
--(1)Copy this stored procedure

create proc step3 @dbname varchar(128),@drive_fordata varchar(200),@drive_forlog varchar(200),@path varchar(500) as
drop table table3000
create table table3000(LogicalName nvarchar(128),PhysicalName nvarchar(260),Type char(1),FileGroupName nvarchar(128),
Size bigint,MaxSize bigint)
declare @string varchar(1000)
set @string = "restore filelistonly from disk = '"+@path+"'"
--print @string
insert into table3000 exec(@string)

declare @logical1 varchar(128)
set @logical1 = (select logicalname from table3000 where type = 'D')

declare @logical2 varchar(128)
set @logical2 = (select logicalname from table3000 where type = 'L')

set @string = "restore database "+@dbname+" from disk = '"+@path+"' with replace,move '"+@logical1+"' to '"+@drive_fordata+"\"+@logical1+".mdf', move '"+@logical2+"' to '"+@drive_forlog+"\"+@logical2+".ldf'"
--print @string
exec (@string)

-------------------------------------------------
--(2)Execute procedure
exec step3 'xyz','d:\test','d:\test','d:\backups\xyzbackup1.bak'

-------------------------------------------------
All you need to pass into the stored procedure are
(1)databasename
(2)new folder name for .mdf file
(3)new folder name for .ldf file
(4)physical path for backup file

but you need to make sure the (2),(3) folder exist!
 
Thanks ClaireHsu. It's gonna take me a few to process it. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top