I have a development in visual studio that makes backups of the database of a SQL Server 2014 Standard Edition server, after making the backups there is a routine to be able to compress them and leave them as .Gz files:
The backups are made with the following line:
BACKUP DATABASE [BaseName] TO DISK = N'D: \ 'WITH NOFORMAT, CHECKSUM, NOINIT, SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 10
and the compression with the following code:
Public Sub Compress_File (ByVal FileEntry As String, ByVal FileExit As String)
Try
Using sourceFile As FileStream = File.OpenRead(archivoEntrada)
Using destFile As FileStream = File.Create(archivoSalida)
Using compStream As GZipStream = New GZipStream(destFile, CompressionMode.Compress)
Dim data(sourceFile.Length) As Byte
sourceFile.Read(data, 0, data.Length)
compStream.Write(data, 0, data.Length)
compStream.Close()
End Using
destFile.Close()
End Using
sourceFile.Close()
End Using
Catch ex As Exception
DtsBit.T_ErrorS = Mid(ex.Message, 1, 500)
Call FuncBit.Error_Trabajo_Bitacora(DtsBit)
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
but at the moment I decompress the backups with either 7zip, winzip, winrar or with the following code:
Public Sub Compress_File (ByVal FileEntry As String, ByVal FileExit As String)
Try
Using sourceFile As FileStream = File.OpenRead(archivoEntrada)
Using destFile As FileStream = File.Create(archivoSalida)
Using compStream As GZipStream = New GZipStream(sourceFile, CompressionMode.Decompress)
Dim data As Integer
data = compStream.ReadByte()
While (data <> -1)
destFile.WriteByte(CByte(data))
data = compStream.ReadByte()
End While
End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
I can not restore them to the SQL server because it sends the error "is terminating abnormally", what it detects is that if in the line that performs the backup I omit the attribute
COMPRESSION
if I can unzip the backups and restore them without problem.
Does anyone know how I can rescue the backups I already had so I can restore them?