0

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
        }
Fabio
  • 53
  • 4
  • Cannot reproduce... Can you show more of the code you use? Seems to me that something other that the `Compress-Archive` call produces this error – Theo Dec 06 '21 at 14:54
  • Some older versions of windows have very low (1024 MB) max memory settings - try checking with `Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB`. `Compress-Archive` (.NET compression) is not memory-efficient at all and can balloon to double the size of the file it's compressing. – Cpt.Whale Dec 06 '21 at 16:46

0 Answers0