Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Automatically Restore Backup Files for SQL 2005


Automatically Restore Backup Files for SQL 2005

Author
Message
Lester Policarpio
Lester Policarpio
Mr or Mrs. 500
Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)

Group: General Forum Members
Points: 507 Visits: 2459
Comments posted to this topic are about the item Automatically Restore Backup Files for SQL 2005

"-=Still Learning=-"

Lester Policarpio
mario.lottering@gmail.com
mario.lottering@gmail.com
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 187
Tried this script on SQL 2008, added a few columns and it worked like a charm. We will be saving a lot of time.BigGrin
Lester Policarpio
Lester Policarpio
Mr or Mrs. 500
Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)

Group: General Forum Members
Points: 507 Visits: 2459
I'm glad it worked for sql version 2008. The only difference is the schema of the tables in sql 2000, 2005 and 2008 Smile

"-=Still Learning=-"

Lester Policarpio
mario.lottering@gmail.com
mario.lottering@gmail.com
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 187
We braught in the following on a few parts to ensure that we limit the possiblilty duplicates of the .mdf, .ndf and .ldf physical names and database names are not used.

Have you considered something like that?

We have quite a few environments and this helped to set them apart.


DECLARE @RestoreFrom varchar(20)
SET @RestoreFrom = '_ServerName'

SET @restoredb = 'RESTORE DATABASE '+(select top 1 DatabaseName+@RestoreFrom from header_lester)

UPDATE migration_lester SET physicalname = left(Physicalname,charindex('.',Physicalname)-1)+ @RestoreFrom + Right(Physicalname,4)
dryan-735480
dryan-735480
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 20
Edited the listing of the path for the location of the .bak files to use

SET @pathension = 'dir /OD /s /b '+@Path+'*.'+@Extension

Allowing for all .bak files in subdirectories and a shorter directory listing format. Just easier when all my .bak files were sitting in their own folders Smile

Also had to remove the +@path in front of +@migrate in the 'Restoreheaderonly' statement as I was getting multiple '///' when the .bak file location was on the network.

Currently using it to restore 37 databases though, so it works like a charm!

Good job...
Lester Policarpio
Lester Policarpio
Mr or Mrs. 500
Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)Mr or Mrs. 500 (507 reputation)

Group: General Forum Members
Points: 507 Visits: 2459
Glad it works :-)

"-=Still Learning=-"

Lester Policarpio
rs 77322
rs 77322
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 12
I have a problem with running this script, it returns this error message:
--------------------------------------------------------
Msg 3201, Level 16, State 2, Line 1
Cannot open backup device 'C:\folder\abase1.bak'. Operating system error 2(The system cannot find the file specified.).
Msg 3013, Level 16, State 1, Line 1
RESTORE HEADERONLY is terminating abnormally.
---------------------------------------------------------

I know it can't find abase1.bak because the real physical filename is database1.bak. Please, I'm not very good with SQL but I do have 150+ databases i want to import into MS SQL. Can anyone tell me where i need to look in the script to fix this up?

Thanks in advance for all helpful hints / solutions.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search