i'm tryng to compress a .bak file after creation (the uncompressed file's size is 550mb) with
Compress-Archive -Path "F:\backupfolder\mydatabase.bak" -CompressionLevel optimal -DestinationPath "F:\backupfolder\mydatabase.bak.zip"
and i get this error:
$destStream.Write($buffer, 0, $numberOfBytesRead)
FullyQualifiedErrorId : OutOfMemoryException
the file is only one and is under the 2gb limit, what i'm doing wrong?
the code is the following:
$datetime = (Get-Date -Format "yyyy.MM.dd.hhmmss")
$databasename = "mydatabase"
$path = "F:\backupfolder\$databasename-$datetime.bak"
$pathzip = "F:\backupfolder\"+$databasename+"-"+$datetime+".bak.zip"
try {
Backup-SqlDatabase -ServerInstance "myserver" -Database "mydatabase" -BackupFile "F:\backupfolder\mydatabase-$datetime.bak"
try {
Compress-Archive -Path "F:\backupfolder\mydatabase-$datetime.bak" -DestinationPath "F:\backupfolder\mydatabase-$datetime.bak.zip"
}
catch {
Write-Host "An error occurred:"
Write-Host $_.ScriptStackTrace
}
#this is to remove the uncompressed file after compression
#if(Test-Path $path -PathType Leaf){
# Remove-Item $path
#}
}
catch {
Write-Host "An error occurred:"
Write-Host $_.ScriptStackTrace
}