Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
glazkovalex opened this issue Feb 12, 2024 · 6 comments
Closed

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

glazkovalex opened this issue Feb 12, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@glazkovalex
Copy link

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

@Digressive
Copy link
Owner

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

@glazkovalex
Copy link
Author

glazkovalex commented Feb 13, 2024

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
Copy link
Author

glazkovalex commented Feb 13, 2024

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
    }

@Digressive
Copy link
Owner

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

@Digressive Digressive added the enhancement New feature or request label Feb 16, 2024
@Digressive Digressive self-assigned this Feb 16, 2024
@jlaraby
Copy link

jlaraby commented Mar 17, 2024

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

@Digressive
Copy link
Owner

@jlaraby Thank you for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants