Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/Tools
diff options
context:
space:
mode:
authorMax <michal@naiman.eu>2018-02-02 15:39:34 +0300
committerMax <michal@naiman.eu>2018-02-02 15:39:34 +0300
commitda9014f3638d0e762020bb6a17150865300a02f1 (patch)
tree46dbe39760ade08e299d29a2cd75d1f46f685a3c /Tools
parent31dc2be98ec512a240449502296df3eb93bfd421 (diff)
fixes
Diffstat (limited to 'Tools')
-rw-r--r--Tools/Verification/DuplicatiVerify.ps1113
1 files changed, 84 insertions, 29 deletions
diff --git a/Tools/Verification/DuplicatiVerify.ps1 b/Tools/Verification/DuplicatiVerify.ps1
index 799ec7367..717e6ef66 100644
--- a/Tools/Verification/DuplicatiVerify.ps1
+++ b/Tools/Verification/DuplicatiVerify.ps1
@@ -1,3 +1,4 @@
+#Requires -Version 5.1
param
(
[Parameter(Mandatory = $true)]
@@ -5,6 +6,35 @@ param
[string]$FileOrDir
)
+Set-StrictMode -Version Latest
+$ErrorActionPreference = "Stop"
+
+enum RemoteVolumeState
+{
+ # Indicates that the remote volume is being created
+ Temporary
+ # Indicates that the remote volume is being uploaded
+ Uploading
+ # Indicates that the remote volume has been uploaded
+ Uploaded
+ # Indicates that the remote volume has been uploaded, and seen by a list operation
+ Verified
+ # Indicattes that the remote volume should be deleted
+ Deleting
+ # Indicates that the remote volume was successfully deleted from the remote location
+ Deleted
+}
+
+enum RemoteVolumeType
+{
+ # Contains data blocks
+ Blocks
+ # Contains file lists
+ Files
+ # Contains redundant lookup information
+ Index
+}
+
function HexToBase64
{
param
@@ -33,28 +63,38 @@ function Verify-Hashes
[int]$errorCount = 0
[int]$checked = 0
-
- if(-not $(Test-Path $filename)) {
- Write-Host "Specified file does not exist: $filename"
- return -1
- }
-
[string]$folder = Split-Path -Path $filename
- $remoteVolumes = (Get-Content $filename) -Join "`n" | ConvertFrom-Json
+ $remoteVolumes = (Get-Content $filename) -Join "`n" | ConvertFrom-Json | Sort-Object Name
+
+ $statsState = @{}
+ foreach ($n in 0..5) { $statsState.Add($n, $(New-Object PSObject -Property @{SumSize=0;SumCount=0})) }
+ $statsType = @{}
+ foreach ($n in 0..2) { $statsType.Add($n, $(New-Object PSObject -Property @{SumSize=0;SumCount=0})) }
foreach ($remoteVolume in $remoteVolumes) {
[string]$volFileName = $remoteVolume.Name
- [long]$volFileSize = $remoteVolume.Size
[string]$volFilePath = Join-Path -Path $folder -ChildPath $volFileName
if(-not $(Test-Path $volFilePath)) {
- Write-Host "File missing: $volFileName" -ForegroundColor Red
- $errorCount++
+ if($remoteVolume.State -eq $([RemoteVolumeState]::Deleted -as [int])) {
+ $checked++
+ $statsState[$($remoteVolume.State)].SumCount += 1
+ $statsState[$($remoteVolume.State)].SumSize += $remoteVolume.Size
+ $statsType[$($remoteVolume.Type)].SumCount += 1
+ $statsType[$($remoteVolume.Type)].SumSize += $remoteVolume.Size
+ } else {
+ Write-Host "File missing: $volFileName" -ForegroundColor Red
+ $errorCount++
+ }
} else {
- $checked++
-
Write-Host "Verifying file $volFileName"
+ $checked++
+ $statsState[$($remoteVolume.State)].SumCount += 1
+ $statsState[$($remoteVolume.State)].SumSize += $remoteVolume.Size
+ $statsType[$($remoteVolume.Type)].SumCount += 1
+ $statsType[$($remoteVolume.Type)].SumSize += $remoteVolume.Size
+
$shaHash = Get-FileHash -Path $volFilePath -Algorithm SHA256
if($remoteVolume.Hash -ne $(HexToBase64 $shaHash.Hash)) {
@@ -68,8 +108,7 @@ function Verify-Hashes
[array]$filesInStorage = Get-ChildItem $folder -Include "$prefix*" -Exclude $(Split-Path -Path $filename -Leaf) | `
Select-Object -ExpandProperty Name | Sort-Object
[array]$filesInVerification = $remoteVolumes | Select-Object -ExpandProperty Name | Sort-Object
-
-
+
$filesInStorage | Where-Object {$filesInVerification -NotContains $_} | ForEach-Object {
Write-Host "Found extra file which is not in verification file: $_" -ForegroundColor Red
$errorCount++
@@ -81,28 +120,44 @@ function Verify-Hashes
Write-Host "`nNo errors found" -ForegroundColor Green
}
+ Write-Host "`nSTATISTICS:"
+
+ foreach ($n in 0..5) {
+ Write-Host "`t$([Enum]::ToObject([RemoteVolumeState], $n)) - Count $($statsState[$n].SumCount), Size $("{0:n1} GB" -f ($statsState[$n].SumSize / 1gb))"
+ }
+
+ Write-Host
+
+ foreach ($n in 0..2) {
+ Write-Host "`t$([Enum]::ToObject([RemoteVolumeType], $n)) - Count $($statsType[$n].SumCount), Size $("{0:n1} GB" -f ($statsType[$n].SumSize / 1gb))"
+ }
+
+ Write-Host
+
return $errorCount
}
-Set-StrictMode -Version Latest
-
if(-not $(Test-Path $FileOrDir)) {
Write-Host "No such file or directory: $FileOrDir" -ForegroundColor Red
+ exit 1
}
if(Test-Path $FileOrDir -PathType Leaf) {
- exit Verify-Hashes -filename $FileOrDir
-} else {
- [int]$files = 0
- [int]$errorCount = 0
+ exit $(Verify-Hashes -filename $FileOrDir)
+}
- Get-ChildItem $FileOrDir -Filter "*-verification.json" |
- Foreach-Object {
- $files++
- Write-Host "Verifying file: $($_.Name)"
- $errorCount = $errorCount + $(Verify-Hashes -filename $_.FullName)
- }
+$verFiles = @(Get-ChildItem $FileOrDir -Filter "*-verification.json")
- if ($files -eq 0) { Write-Host "No verification files in folder: $FileOrDir" }
- exit $errorCount
-} \ No newline at end of file
+if ($verFiles.Count -eq 0) {
+ Write-Host "No verification files in folder: $FileOrDir"
+ exit 1
+}
+
+[int]$errorCount = 0
+
+$verFiles | % {
+ Write-Host "Verifying file: $($_.Name)"
+ $errorCount += $(Verify-Hashes -filename $_.FullName)
+}
+
+exit $errorCount \ No newline at end of file