diff options
author | Jean-François Paris <jfparis@rouge.eu.org> | 2021-02-21 21:35:00 +0300 |
---|---|---|
committer | Jean-François Paris <jfparis@rouge.eu.org> | 2021-02-22 14:14:55 +0300 |
commit | a1b684a1fb6abe984d2a5adbd9c0fff30d11207b (patch) | |
tree | e7bb72a1c054039eca3ed2b53cae0ad4259feffa /Tools | |
parent | fb16b1ad9331397cdb47fd8c20f8df04d0f13176 (diff) |
Rewrote DuplicatiVerify to make it compatible with python2 (now unsupported) and python3
Increase processing speed by feeding the file by 8k chunk rather than by byte
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/Verification/DuplicatiVerify.py | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/Tools/Verification/DuplicatiVerify.py b/Tools/Verification/DuplicatiVerify.py index a715ebb56..4330362c6 100644 --- a/Tools/Verification/DuplicatiVerify.py +++ b/Tools/Verification/DuplicatiVerify.py @@ -1,13 +1,14 @@ -#!/usr/bin/env python2
+#!/usr/bin/env python
"""
-This file is a standalone python script that is tested with python 2.7
+This file is a standalone python script that is tested with python 2.7 & python 3.8
If Duplicati is producing a backup with the option --upload-verification-file,
it will produce a *-verification.json file on the backend, which can be verified
by this script. Simply run this script with the path to the backup
folder as input, and it will verify all *-verification.json files in the folder.
"""
+from __future__ import print_function
import sys
import os
import string
@@ -22,8 +23,9 @@ def bytes_from_file(filename, chunksize=8192): while True:
chunk = f.read(chunksize)
if chunk:
- for b in chunk:
- yield b
+ #for b in chunk:
+ # yield b
+ yield chunk
else:
break
@@ -33,7 +35,7 @@ def verifyHashes(filename): checked = 0
if (not os.path.exists(filename)):
- print "Specified file does not exist: ", filename
+ print("Specified file does not exist:", filename)
return -1
folder = os.path.dirname(filename)
@@ -47,34 +49,35 @@ def verifyHashes(filename): fullpath = os.path.join(folder, filename)
if not os.path.exists(fullpath):
- print "File missing: ", fullpath
+ print("File missing:", fullpath)
errorCount += 1
else:
checked += 1
- print "Verifying file ", filename
+ print("Verifying file", filename)
hashalg = sha256()
for b in bytes_from_file(fullpath):
hashalg.update(b)
hashval = base64.b64encode(hashalg.digest())
+ hashval = hashval.decode('utf-8')
if hashval != hash:
- print "*** Hash check failed for file: ", fullpath
+ print("*** Hash check failed for file:", fullpath)
errorCount += 1
if errorCount > 0:
- print "Errors were found"
+ print("Errors were found")
else:
- print "No errors found"
+ print("No errors found")
return errorCount
if __name__ == "__main__":
if len(sys.argv) != 1 and len(sys.argv) != 2:
- print "Usage:", len(sys.argv)
- print "DuplicatiVerify.py <path to verification file>"
- print "DuplicatiVerify.py <folder with verification files>"
- print "DuplicatiVerify.py (no arguments, uses current dir)"
+ print("Usage:", len(sys.argv))
+ print("DuplicatiVerify.py <path to verification file>")
+ print("DuplicatiVerify.py <folder with verification files>")
+ print("DuplicatiVerify.py (no arguments, uses current dir)")
else:
if len(sys.argv) == 1:
argument = os.getcwd()
@@ -82,7 +85,7 @@ if __name__ == "__main__": argument = sys.argv[1]
if not os.path.exists(argument):
- print "No such file or directory: ", argument
+ print("No such file or directory: ", argument)
else:
if os.path.isfile(argument):
verifyHashes(argument)
@@ -90,9 +93,9 @@ if __name__ == "__main__": files = 0
for f in os.listdir(argument):
if (f.endswith("-verification.json")):
- print "Verifying file: ", f
+ print("Verifying file:", f)
files += 1
verifyHashes(os.path.join(argument, f))
if files == 0:
- print "No verification files in folder: ", argument
+ print("No verification files in folder:", argument)
|