January 22, 2013 at 10:24 am
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.
Viewing 0 posts
You must be logged in to reply to this topic. Login to reply