HyperV-Backup-Utility icon indicating copy to clipboard operation
HyperV-Backup-Utility copied to clipboard

We really miss the option to check the created 7z archive!

Open glazkovalex opened this issue 1 year ago • 6 comments

We really miss the option to check the created 7z archive!

glazkovalex avatar Feb 12 '24 20:02 glazkovalex

I'm sorry I don't understand, what option?

Digressive avatar Feb 12 '24 22:02 Digressive

I'm sorry I don't understand, what option?

Hello! I mean, the 7z archive may be created with an error due to a processor, memory, or disk failure and then it will not be possible to unpack it. Therefore, many archivers, for example, Winzip and many backup creators, for example, Acronis, allow you to check the created archive and only after that consider the backup successfully created. 7z has the ability to check the archive, but only as a separate additional operation after creating the archive. 7z t archive.7z Thus, I suggest adding the "-SzWithTest" parameter to your wonderful script, if available, after creating the archive, run a check of the created archive and only if successful consider the backup successfully created.

glazkovalex avatar Feb 13 '24 17:02 glazkovalex

I'm not good at scripts, but apparently before line 370 you need to insert a check for the presence of an additional parameter "-SzWithTest" and, if available, run:

& "$env:programfiles\7-Zip\7z.exe" t ("$CompressDir\$CompressFileNameSet.7z")

It's even better to leave everything unchanged for the existing parameter "-Sz", and make a separate function for the alternative more reliable parameter "-SzWithTest":

Function CompressFiles7zipWithTest($CompressDateFormat,$CompressDir,$CompressFileName)
    {
        $CompressFileNameSet = $CompressFileName+$CompressDateFormat
        ## 7-zip compression with shortdate
        try {
            & "$env:programfiles\7-Zip\7z.exe" $SzSwSplit -bso0 a ("$CompressDir\$CompressFileNameSet") "$CompressDir\$Vm\*"
            & "$env:programfiles\7-Zip\7z.exe" t ("$CompressDir\$CompressFileNameSet.7z")
            $BackupSucc = $true
        }
        catch {
            $_.Exception.Message | Write-Log -Type Err -Evt "(VM:$Vm) $_"
            $BackupSucc = $false
        }

        $BackupSucc | Out-Null
    }

glazkovalex avatar Feb 13 '24 18:02 glazkovalex

I understand, thank you for providing more information! I'm going to work on this for a future release.

Digressive avatar Feb 16 '24 12:02 Digressive

The 7-zip test feature fails when the archive was created with a password. Here is what I added to the CompressFiles7zip function to allow the archive test to work:

$archivePassword = if ($SzSwitches -ne $null) {
                                $password = ($SzSwitches -split ',') | Where-Object { $_ -match '^-p(.*)' } | ForEach-Object { $matches[1] }
                                if ($password -ne "" -and $password -ne $null) {
                                    "-p$password"
                                } else { "" } 
                            } else { "" }

$7zipTestOutput = & "$env:programfiles\7-Zip\7z.exe" $archivePassword -bso0 t $($GetTheFile.FullName) *>&1

jlaraby avatar Mar 17 '24 01:03 jlaraby

@jlaraby Thank you for this!

Digressive avatar Mar 17 '24 18:03 Digressive