mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-04-13 22:47:12 +03:00
zfs check initial version (wip)
This commit is contained in:
parent
a115f0bd17
commit
14c45d2b34
@ -39,8 +39,8 @@ class ZfsCheck(CliBase):
|
|||||||
|
|
||||||
return args
|
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
|
:type snapshot: ZfsDataset.ZfsDataset
|
||||||
"""
|
"""
|
||||||
@ -54,14 +54,16 @@ class ZfsCheck(CliBase):
|
|||||||
|
|
||||||
self.debug("Hashing tree: {}".format(mnt))
|
self.debug("Hashing tree: {}".format(mnt))
|
||||||
if not self.args.test:
|
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))
|
print("{}\t{}\t{}".format(file, block, hash))
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
self.debug("Cleaning up temporary mount point")
|
|
||||||
snapshot.unmount()
|
snapshot.unmount()
|
||||||
|
self.debug("Cleaning up temporary mount point")
|
||||||
self.node.run(["rmdir", mnt], hide_errors=True, valid_exitcodes=[])
|
self.node.run(["rmdir", mnt], hide_errors=True, valid_exitcodes=[])
|
||||||
|
|
||||||
|
# def hash_volume(self, snapshot):
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
@ -78,9 +80,9 @@ class ZfsCheck(CliBase):
|
|||||||
dataset_type=snapshot.parent.properties['type']
|
dataset_type=snapshot.parent.properties['type']
|
||||||
|
|
||||||
if dataset_type=='volume':
|
if dataset_type=='volume':
|
||||||
self.checksum_volume(snapshot)
|
self.checksum_volume(snapshot, self.args.count, self.args.block_size)
|
||||||
elif dataset_type=='filesystem':
|
elif dataset_type=='filesystem':
|
||||||
self.hash_filesystem(snapshot)
|
self.hash_filesystem(snapshot, self.args.count, self.args.block_size)
|
||||||
else:
|
else:
|
||||||
raise Exception("huh?")
|
raise Exception("huh?")
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ def block_hash(fname, count=10000, bs=4006):
|
|||||||
hash = hashlib.sha1()
|
hash = hashlib.sha1()
|
||||||
block_nr = 0
|
block_nr = 0
|
||||||
chunk_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)
|
hash.update(block)
|
||||||
block_nr = block_nr + 1
|
block_nr = block_nr + 1
|
||||||
if block_nr % count == 0:
|
if block_nr % count == 0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user