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:
authorJean-François Paris <jfparis@rouge.eu.org>2021-02-23 23:35:05 +0300
committerJean-François Paris <jfparis@rouge.eu.org>2021-02-23 23:35:05 +0300
commit6a74e3aa07e549fe8722065e153d78839ccc398e (patch)
tree84ed10a18414da9acd0d76d9cf910cb4b209682b /Tools
parenta1b684a1fb6abe984d2a5adbd9c0fff30d11207b (diff)
Updates to DuplicatiVerify.py
* Increase block size ro 8MB to make the process faster and still light on memory on a low memory machine * Added a --quiet argument to reduce very verbose output.
Diffstat (limited to 'Tools')
-rw-r--r--Tools/Verification/DuplicatiVerify.py69
1 files changed, 35 insertions, 34 deletions
diff --git a/Tools/Verification/DuplicatiVerify.py b/Tools/Verification/DuplicatiVerify.py
index 4330362c6..e32a12ecd 100644
--- a/Tools/Verification/DuplicatiVerify.py
+++ b/Tools/Verification/DuplicatiVerify.py
@@ -1,7 +1,8 @@
#!/usr/bin/env python
"""
-This file is a standalone python script that is tested with python 2.7 & python 3.8
+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
@@ -16,9 +17,10 @@ import json
import base64
import codecs
from hashlib import sha256
+import argparse
""" Utility function to return byte chunks from a binary file """
-def bytes_from_file(filename, chunksize=8192):
+def bytes_from_file(filename, chunksize=8192*1024):
with open(filename, "rb") as f:
while True:
chunk = f.read(chunksize)
@@ -30,30 +32,31 @@ def bytes_from_file(filename, chunksize=8192):
break
""" Verifies a single -verification.json file """
-def verifyHashes(filename):
+def verifyHashes(filename, quiet):
errorCount = 0
checked = 0
if (not os.path.exists(filename)):
print("Specified file does not exist:", filename)
return -1
-
+
folder = os.path.dirname(filename)
with codecs.open(filename, "r", "utf-8-sig") as f:
doc = json.load(f)
-
+
for file in doc:
filename = file["Name"]
hash = file["Hash"]
size = file["Size"]
-
+
fullpath = os.path.join(folder, filename)
if not os.path.exists(fullpath):
print("File missing:", fullpath)
errorCount += 1
else:
checked += 1
- print("Verifying file", filename)
+ if not quiet:
+ print("Verifying file", filename)
hashalg = sha256()
for b in bytes_from_file(fullpath):
hashalg.update(b)
@@ -62,40 +65,38 @@ def verifyHashes(filename):
if hashval != hash:
print("*** Hash check failed for file:", fullpath)
errorCount += 1
-
-
+
+
if errorCount > 0:
print("Errors were found")
else:
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)")
+ parser = argparse.ArgumentParser(description='Verify hashes of backup files.')
+ parser.add_argument("--quiet", action='store_true', help="Be noisy about each file being verified")
+ parser.add_argument("path", type=str, nargs='?',
+ help="""path to the verification fole or folder containing the verification folder.\
+ Defaulf is curent path""")
+ args = parser.parse_args()
+
+ if args.path is None:
+ args.path = os.getcwd()
+
+ if not os.path.exists(args.path):
+ print("No such file or directory: ", args.path)
else:
- if len(sys.argv) == 1:
- argument = os.getcwd()
- else:
- argument = sys.argv[1]
-
- if not os.path.exists(argument):
- print("No such file or directory: ", argument)
+ if os.path.isfile(args.path):
+ verifyHashes(args.path, args.quiet)
else:
- if os.path.isfile(argument):
- verifyHashes(argument)
- else:
- files = 0
- for f in os.listdir(argument):
- if (f.endswith("-verification.json")):
- print("Verifying file:", f)
- files += 1
- verifyHashes(os.path.join(argument, f))
-
- if files == 0:
- print("No verification files in folder:", argument)
+ files = 0
+ for f in os.listdir(args.path):
+ if (f.endswith("-verification.json")):
+ print("Verifying file:", f)
+ files += 1
+ verifyHashes(os.path.join(args.path, f), args.quiet)
+ if files == 0:
+ print("No verification files in folder:", args.path)