Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Restore WITH MOVE

Author  Topic 

cblatchford
Starting Member

40 Posts

Posted - 2007-06-05 : 10:36:31
Hi all,

I'm running the below script on a current 2000 server trying to backup and restore all databases to a 2005 server:

DECLARE @DB varchar(100),
@Backup_location varchar(100),
@cmd varchar(100)

DECLARE ICursor CURSOR
FOR
SELECT name from sysdatabases where name not in ('master','msdb','model','tempdb')
OPEN ICursor

Fetch Next From ICursor Into @DB
WHILE(@@fetch_status = 0)
BEGIN
SET @Backup_Location = '\\LON-SQAPPS01\backup\'+@DB+'.BAK'
SET @cmd = 'del '+@Backup_Location
Backup Database @DB to disk = @Backup_Location with init
Exec('[LON-SQAPPS01].master.dbo.sp_executesql N''restore database ' + @DB + ' from disk =''''' + @Backup_Location + ''''' WITH move ''''' + @DB + '_data' + ''''' to ''''G:\Data\' + @DB + '_data.mdf'''', move ''''' + @DB + '_log' + ''''' to ''''F:\Data\' + @DB + '_Log.ldf''''''')
/*exec xp_cmdshell @cmd*/
Fetch Next From ICursor Into @DB
END

deallocate ICursor


The backup part of the script works fine, but the restore keeps giving me the following error:

Server: Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
Server: Msg 3119, Level 16, State 1, Line 1
Problems were identified while planning for the RESTORE statement. Previous messages provide details.
Server: Msg 3156, Level 16, State 1, Line 1
File 'AML_Log' cannot be restored to 'F:\Data\AML_Log.ldf'. Use WITH MOVE to identify a valid location for the file.
Server: Msg 5184, Level 16, State 1, Line 1
Cannot use file 'F:\Data\AML_Log.ldf' for clustered server. Only formatted files on which the cluster resource of the server has a dependency can be used.

I'm specifying the "WITH MOVE" syntax in the script, but it still keeps throwing this up, any ideas?

Thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2007-06-05 : 10:39:51
see
http://www.nigelrivett.net/SQLAdmin/s_RestoreDatabase.html

It does a move for the data and logs getting the names from the backup file.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-06-05 : 11:35:34
If it was me I wouldn't be using nested EXEC and sp_ExecuteSQL.

Plus I would put the SQL into a variable first so that I could use a PRINT statement, or similar, so see what was happening.

Perhaps a database name has a reserved character in it?

Maybe the Logical Names of the database being backed up / restore do NOT end in "_data" / "_log" ?

Not sure what this error means (but it may only be a cascade error)

"Cannot use file 'F:\Data\AML_Log.ldf' for clustered server. Only formatted files on which the cluster resource of the server has a dependency can be used"

Kristen
Go to Top of Page

cornall
Posting Yak Master

148 Posts

Posted - 2007-06-05 : 11:38:36
I know this may sound stupid but does the folder F:\Data exist?
Go to Top of Page

cblatchford
Starting Member

40 Posts

Posted - 2007-06-05 : 12:25:10
Thanks, yes the folders exist and i'm only testing it on a few databases, all of which end in _data (or where applicable); i'll try the script nr suggested...

thanks for your responses thus far!
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-06-05 : 23:09:21
Did you add f:\ drive as sql resource's dependency resource?
Go to Top of Page

rcavill
Starting Member

1 Post

Posted - 2007-06-10 : 23:15:52
Have a look at the following KB article.

How to create databases or change disk file locations on a shared cluster drive on which SQL Server was not originally installed

http://support.microsoft.com/default.aspx/kb/295732

If might be that you need to add the F: drive to the dependency list of drives that SQL 2005 is able to use.

------
Robert
* smile - its infectious *
Go to Top of Page
   

- Advertisement -