Hi,I am attempting to produce a script to perform a cross network restore of multiple databases onto a different server incorporating SQLBackup from Red Gate. The full backups on the source server were performed using SQLBackup. Once restored, the .mdf and .ldf's need to reside in a different directory on the destination server to the source server. To accomplish this I have incorporated WITH MOVE into the cursor.The problem I have is that the logical filenames are inconsistent. Some are '_DAT', some are '_DATA' and some are just the same as the database name. So, when I run the code below:declare @dbname sysnamedeclare @cmd varchar(2000)declare csr cursor for select [name] from catsql.master.dbo.sysdatabases where dbid>4order by 1open csrfetch next from csr into @dbnamewhile @@fetch_status = 0begin SET @cmd = 'exec master..sqlbackup ''-SQL "RESTORE DATABASE [' + @dbname + '] FROM DISK = [\\CATSQL\D$\backups\' + @dbname + '(FULL)_' + convert(varchar(8), getdate(), 112) + '.sqb] WITH NORECOVERY, MOVE [' + @dbname + '_dat] TO [F:\MSSQL.1\' + @dbname + '.mdf], MOVE [' + @dbname + '_log] TO [E:\MSSQL.1\' + @dbname + '.ldf]" '''print @cmdexec (@cmd) fetch next from csr into @dbnameendclose csrdeallocate csr
I ultimately get this error for certain databases:SQL error 3234: SQL error 3234: Logical file 'MyDatabase' is not part of database 'MyDatabase'. Use RESTORE FILELISTONLY to list the logical file names.How can I pull the correct file names for each database into the cursor?Thanks,Pat.