Digressive/HyperV-Backup-Utility

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

glazkovalex opened this issue ยท 6 comments

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

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

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.

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
    }

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

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 Thank you for this!