Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Adding variables to Restore script Expand / Collapse
Author
Message
Posted Tuesday, January 22, 2013 10:24 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, February 22, 2013 10:15 AM
Points: 41, Visits: 155
Hi all, I just need to automate a script as far as possible, at the moment I'm using Ctrl H to replace the database name and .bak with the current value, but I'd like to just pass in a couple of params at the start, and just run. Hopefully I'll be able to create a sproc and do the same. Here's what I've got so far, I need to keep the 'DCM' string and add on the db name from the variable...

Exec master..xp_cmdshell 'MKDIR "U:\Archives\YourDatabaseNameHere\DATA"'

Restore Database YourDatabaseNameHere
From
Disk = 'YourBackupFilePathHere\YourDatabaseNameHere.BAK'

WITH
MOVE 'DCMYourDatabaseNameHere' TO 'U:\Archives\YourDatabaseNameHere\DATA\YourDatabaseNameHere.mdf',
MOVE 'DCMYourDatabaseNameHere_log' TO 'W:\Archives\Log\YourDatabaseNameHere_log.ldf',
STATS = 1
Exec master..xp_cmdshell ' DEL /Q YourBackupFilePathHere\YourDatabaseNameHere.BAK'

Thanks,

BLL.
Post #1410152
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse