From 14c45d2b340a91b7838c811ad471d44beedf2be4 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Sun, 20 Feb 2022 17:39:17 +0100 Subject: [PATCH] zfs check initial version (wip) --- zfs_autobackup/ZfsCheck.py | 14 ++++++++------ zfs_autobackup/util.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/zfs_autobackup/ZfsCheck.py b/zfs_autobackup/ZfsCheck.py index 3f4264f..6b47dd6 100644 --- a/zfs_autobackup/ZfsCheck.py +++ b/zfs_autobackup/ZfsCheck.py @@ -39,8 +39,8 @@ class ZfsCheck(CliBase): return args - def hash_filesystem(self, snapshot): - """ + def hash_filesystem(self, snapshot, count, bs): + """ recursively hash all files in this snapshot, using block_hash_tree() :type snapshot: ZfsDataset.ZfsDataset """ @@ -54,14 +54,16 @@ class ZfsCheck(CliBase): self.debug("Hashing tree: {}".format(mnt)) if not self.args.test: - for (file, block, hash) in block_hash_tree(mnt): + for (file, block, hash) in block_hash_tree(mnt, count, bs): print("{}\t{}\t{}".format(file, block, hash)) finally: - self.debug("Cleaning up temporary mount point") snapshot.unmount() + self.debug("Cleaning up temporary mount point") self.node.run(["rmdir", mnt], hide_errors=True, valid_exitcodes=[]) + # def hash_volume(self, snapshot): + def run(self): @@ -78,9 +80,9 @@ class ZfsCheck(CliBase): dataset_type=snapshot.parent.properties['type'] if dataset_type=='volume': - self.checksum_volume(snapshot) + self.checksum_volume(snapshot, self.args.count, self.args.block_size) elif dataset_type=='filesystem': - self.hash_filesystem(snapshot) + self.hash_filesystem(snapshot, self.args.count, self.args.block_size) else: raise Exception("huh?") diff --git a/zfs_autobackup/util.py b/zfs_autobackup/util.py index e18c8fc..82cfbea 100644 --- a/zfs_autobackup/util.py +++ b/zfs_autobackup/util.py @@ -36,7 +36,7 @@ def block_hash(fname, count=10000, bs=4006): hash = hashlib.sha1() block_nr = 0 chunk_nr = 0 - for block in iter(lambda: f.read(4096), b""): + for block in iter(lambda: f.read(bs), b""): hash.update(block) block_nr = block_nr + 1 if block_nr % count == 0: