SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Error when retoring database from TSQL


Error when retoring database from TSQL

Author
Message
dndaughtery
dndaughtery
SSCrazy Eights
SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)SSCrazy Eights (9.6K reputation)

Group: General Forum Members
Points: 9594 Visits: 1105
I'm trying to restore a SQL Server 2005 database to a SQL Server 2008 server with the following script but I am getting an error which states:




Restoring CDR_Main_Dev (database) from:
E:\SQLBackups\CDR_Main_Dev\CDR_Main_FULL_20100609_000003_04.sqb
E:\SQLBackups\CDR_Main_Dev\CDR_Main_FULL_20100609_000003_05.sqb
E:\SQLBackups\CDR_Main_Dev\CDR_Main_FULL_20100609_000003_03.sqb
E:\SQLBackups\CDR_Main_Dev\CDR_Main_FULL_20100609_000003_01.sqb
E:\SQLBackups\CDR_Main_Dev\CDR_Main_FULL_20100609_000003_02.sqb

Thread 0 error:
Failed to service command. Error code: -2139684860
Process terminated unexpectedly. Error code: -2139684860 (An abort request is preventing anything except termination actions.)

Thread 1 error:
Failed to service command. Error code: -2139684860
Process terminated unexpectedly. Error code: -2139684860 (An abort request is preventing anything except termination actions.)

Thread 2 error:
Process terminated unexpectedly. Error code: -2139684860 (An abort request is preventing anything except termination actions.)

Thread 3 error:
Process terminated unexpectedly. Error code: -2139684860 (An abort request is preventing anything except termination actions.)

Thread 4 error:
Process terminated unexpectedly. Error code: -2139684860 (An abort request is preventing anything except termination actions.)

SQL error 3013: SQL error 3013: RESTORE DATABASE is terminating abnormally.
SQL error 3241: SQL error 3241: The media family on device 'SQLBACKUP_273C82FD-3412-49B2-9669-42A275B6845802' is incorrectly formed. SQL Server cannot process this media family.
SQL error 3203: SQL error 3203: Read on "SQLBACKUP_273C82FD-3412-49B2-9669-42A275B68458" failed: 995(The I/O operation has been aborted because of either a thread exit or an application request.)

SQL Backup exit code: 790
SQL error code: 3203







[code]
use master
go
SET NOCOUNT ON

declare @optstring varchar(4000)
declare @targetDB varchar(100)
declare @dt varchar(8)
declare @ix varchar(6)
declare @KILL_EXISTING_CONNS varchar(5)
select @dt = CONVERT(varchar, getdate(), 112)

-----------------------------------------------------------
-- SET THESE FIRST
-----------------------------------------------------------
SET @KILL_EXISTING_CONNS = 'TRUE'
--SET @KILL_EXISTING_CONNS = 'FALSE'

SET @targetDB = 'CDR_Main_Dev'
--SET @targetDB = 'CDR_Main_Test'

SET @ix = '000003'
--SET @ix = '000001'

IF COALESCE(@targetDB, '') = ''
BEGIN
RAISERROR('SPECIFY THE TARGET DATABASE', 0, 1) WITH NOWAIT
RETURN
END

-----------------------------------------------------------
-- Check if one of the files exists using default filename.
-- Abort if it does not, the sqlbackup command takes 25 mins
-- to run only to tell you that the files do not exist.
-----------------------------------------------------------
DECLARE @file VARCHAR(255)
DECLARE @status bit
DECLARE @CopyCmd as varchar(4000)
SET @file = '\\MedCDR\f$\SQLBackups\CDR_Main\CDR_Main_FULL_' + @dt + '_' + @ix + '_01.sqb'
SET @status = 0
Declare @FileCheck Table (
FileName varchar(200)
)
DECLARE @FileExists TABLE(isFile bit, isDir bit, hasParentDir bit)
INSERT INTO @FileExists exec master.dbo.xp_fileexist @file
SELECT @status = isFile FROM @FileExists
IF @status = 1
BEGIN

--Set @CopyCmd = 'xcopy \\MedCDR\f$\SQLBackups\CDR_Main\CDR_Main_FULL_' + @dt + '_' + @ix + '_01.sqb E:\SQLBackups\CDR_Main_Dev /r /y'
--Insert Into @FileCheck Exec xp_cmdshell @CopyCmd
--Set @CopyCmd = 'xcopy \\MedCDR\f$\SQLBackups\CDR_Main\CDR_Main_FULL_' + @dt + '_' + @ix + '_02.sqb E:\SQLBackups\CDR_Main_Dev /r /y'
--Insert Into @FileCheck Exec xp_cmdshell @CopyCmd
--Set @CopyCmd = 'xcopy \\MedCDR\f$\SQLBackups\CDR_Main\CDR_Main_FULL_' + @dt + '_' + @ix + '_03.sqb E:\SQLBackups\CDR_Main_Dev /r /y'
--Insert Into @FileCheck Exec xp_cmdshell @CopyCmd
--Set @CopyCmd = 'xcopy \\MedCDR\f$\SQLBackups\CDR_Main\CDR_Main_FULL_' + @dt + '_' + @ix + '_04.sqb E:\SQLBackups\CDR_Main_Dev /r /y'
--Insert Into @FileCheck Exec xp_cmdshell @CopyCmd
--Set @CopyCmd = 'xcopy \\MedCDR\f$\SQLBackups\CDR_Main\CDR_Main_FULL_' + @dt + '_' + @ix + '_05.sqb E:\SQLBackups\CDR_Main_Dev /r /y'
--Insert Into @FileCheck Exec xp_cmdshell @CopyCmd

set @optstring = '-SQL "RESTORE DATABASE [' + @targetDB +']
FROM DISK = ''E:\SQLBackups\CDR_Main_Dev\CDR_Main_FULL_' + @dt + '_' + @ix + '_04.sqb'',
DISK = ''E:\SQLBackups\CDR_Main_Dev\CDR_Main_FULL_' + @dt + '_' + @ix + '_05.sqb'',
DISK = ''E:\SQLBackups\CDR_Main_Dev\CDR_Main_FULL_' + @dt + '_' + @ix + '_03.sqb'',
DISK = ''E:\SQLBackups\CDR_Main_Dev\CDR_Main_FULL_' + @dt + '_' + @ix + '_01.sqb'',
DISK = ''E:\SQLBackups\CDR_Main_Dev\CDR_Main_FULL_' + @dt + '_' + @ix + '_02.sqb'' WITH RECOVERY,
DISCONNECT_EXISTING,
MOVE ''CDR_Main_Dev'' TO ''E:\Data\Databases\' + @targetDB +'.mdf'',
MOVE ''CDR_Main_Dev_log'' TO ''E:\Data\Databases\' + @targetDB +'_log.ldf'',
REPLACE,
ORPHAN_CHECK"'



BEGIN TRY
--RAISERROR(@optstring, 0, 1) WITH nowait
--print @optstring
EXECUTE sqlbackup @optstring
END TRY
BEGIN CATCH
DECLARE @ErrorMessage NVARCHAR(4000),
@ErrorNumber INT,
@ErrorSeverity INT,
@ErrorState INT
SELECT @ErrorMessage = Error_Message(),
@ErrorNumber = Error_Number(),
@ErrorSeverity = Error_Severity(),
@ErrorState = Error_State()

SET @ErrorMessage = REPLACE('ERROR trying to restore: @@err', '@@err', @ErrorMessage)

RAISERROR(@ErrorMessage,@ErrorSeverity, @ErrorState)
END CATCH
END
ELSE
BEGIN
DECLARE @Msg VARCHAR(300)
SET @Msg = @file + ' does not exist, try changing ' + @ix + ' to another value'
RAISERROR(@Msg, 0, 1) WITH NOWAIT
END

GO

[\code]
GilaMonster
GilaMonster
SSC Guru
SSC Guru (860K reputation)SSC Guru (860K reputation)SSC Guru (860K reputation)SSC Guru (860K reputation)SSC Guru (860K reputation)SSC Guru (860K reputation)SSC Guru (860K reputation)SSC Guru (860K reputation)

Group: General Forum Members
Points: 860674 Visits: 48577
What 3rd party backup tool are you using?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (340K reputation)SSC Guru (340K reputation)SSC Guru (340K reputation)SSC Guru (340K reputation)SSC Guru (340K reputation)SSC Guru (340K reputation)SSC Guru (340K reputation)SSC Guru (340K reputation)

Group: General Forum Members
Points: 340201 Visits: 34009
Sure sounds like something is broken in the backup file:

SQL error 3241: SQL error 3241: The media family on device 'SQLBACKUP_273C82FD-3412-49B2-9669-42A275B6845802' is incorrectly formed. SQL Server cannot process this media family.


----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
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