forked from third-party-mirrors/zfs_autobackup
zfs-check fixes and tests
This commit is contained in:
parent
f397e7be59
commit
ed61f03b4b
@ -85,6 +85,16 @@ class TestZfsCheck(unittest2.TestCase):
|
|||||||
prepare_zpools()
|
prepare_zpools()
|
||||||
|
|
||||||
shelltest("cp tests/data/whole /test_source1/testfile")
|
shelltest("cp tests/data/whole /test_source1/testfile")
|
||||||
|
shelltest("mkdir /test_source1/emptydir")
|
||||||
|
shelltest("mkdir /test_source1/dir")
|
||||||
|
shelltest("cp tests/data/whole2 /test_source1/dir/testfile")
|
||||||
|
|
||||||
|
#it should ignore these:
|
||||||
|
shelltest("ln -s / /test_source1/symlink")
|
||||||
|
shelltest("mknod /test_source1/c c 1 1")
|
||||||
|
shelltest("mknod /test_source1/b b 1 1")
|
||||||
|
shelltest("mkfifo /test_source1/f")
|
||||||
|
|
||||||
shelltest("zfs snapshot test_source1@test")
|
shelltest("zfs snapshot test_source1@test")
|
||||||
|
|
||||||
with OutputIO() as buf:
|
with OutputIO() as buf:
|
||||||
@ -93,5 +103,11 @@ class TestZfsCheck(unittest2.TestCase):
|
|||||||
|
|
||||||
print(buf.getvalue())
|
print(buf.getvalue())
|
||||||
self.assertEqual("""testfile 0 3c0bf91170d873b8e327d3bafb6bc074580d11b7
|
self.assertEqual("""testfile 0 3c0bf91170d873b8e327d3bafb6bc074580d11b7
|
||||||
|
dir/testfile 0 2e863f1fcccd6642e4e28453eba10d2d3f74d798
|
||||||
""", buf.getvalue())
|
""", buf.getvalue())
|
||||||
|
|
||||||
|
|
||||||
|
# def test_brokenpipe_cleanup_filesystem(self):
|
||||||
|
# """test if stuff is cleaned up correctly, in debugging mode , when a pipe breaks. """
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
from signal import signal, SIGPIPE
|
||||||
|
from .util import output_redir
|
||||||
|
|
||||||
from .ZfsAuto import ZfsAuto
|
from .ZfsAuto import ZfsAuto
|
||||||
|
|
||||||
from . import compressors
|
from . import compressors
|
||||||
@ -489,6 +492,8 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
def cli():
|
def cli():
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
signal(SIGPIPE, output_redir)
|
||||||
|
|
||||||
sys.exit(ZfsAutobackup(sys.argv[1:], False).run())
|
sys.exit(ZfsAutobackup(sys.argv[1:], False).run())
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
# from util import activate_volume_snapshot, create_mountpoints, cleanup_mountpoint
|
# from util import activate_volume_snapshot, create_mountpoints, cleanup_mountpoint
|
||||||
|
from signal import signal, SIGPIPE
|
||||||
|
from .util import output_redir
|
||||||
|
|
||||||
from .ZfsAuto import ZfsAuto
|
from .ZfsAuto import ZfsAuto
|
||||||
from .ZfsNode import ZfsNode
|
from .ZfsNode import ZfsNode
|
||||||
import sys
|
import sys
|
||||||
@ -302,6 +305,8 @@ class ZfsAutoverify(ZfsAuto):
|
|||||||
def cli():
|
def cli():
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
signal(SIGPIPE, output_redir)
|
||||||
|
|
||||||
sys.exit(ZfsAutoverify(sys.argv[1:], False).run())
|
sys.exit(ZfsAutoverify(sys.argv[1:], False).run())
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from signal import signal, SIGPIPE
|
||||||
|
|
||||||
|
|
||||||
from .ZfsNode import ZfsNode
|
from .ZfsNode import ZfsNode
|
||||||
from .util import *
|
from .util import *
|
||||||
from .CliBase import CliBase
|
from .CliBase import CliBase
|
||||||
@ -62,8 +65,6 @@ class ZfsCheck(CliBase):
|
|||||||
print("{}\t{}\t{}".format(file, block, hash))
|
print("{}\t{}\t{}".format(file, block, hash))
|
||||||
sys.stdout.flush() #important, to generate SIGPIPES on ssh disconnect
|
sys.stdout.flush() #important, to generate SIGPIPES on ssh disconnect
|
||||||
|
|
||||||
# except BrokenPipeError:
|
|
||||||
# output_redir()
|
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
snapshot.unmount()
|
snapshot.unmount()
|
||||||
@ -89,7 +90,7 @@ class ZfsCheck(CliBase):
|
|||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
while time.time() - start_time < 10:
|
while time.time() - start_time < 10:
|
||||||
for location in locations:
|
for location in locations:
|
||||||
if pathlib.Path(location).is_block_device():
|
if os.path.exists(location):
|
||||||
return location
|
return location
|
||||||
|
|
||||||
# fake it in testmode
|
# fake it in testmode
|
||||||
@ -116,15 +117,12 @@ class ZfsCheck(CliBase):
|
|||||||
print("{}\t{}".format(block, hash))
|
print("{}\t{}".format(block, hash))
|
||||||
sys.stdout.flush() #important, to generate SIGPIPES on ssh disconnect
|
sys.stdout.flush() #important, to generate SIGPIPES on ssh disconnect
|
||||||
|
|
||||||
except BrokenPipeError:
|
|
||||||
output_redir()
|
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
self.deacitvate_volume_snapshot(snapshot)
|
self.deacitvate_volume_snapshot(snapshot)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
|
|
||||||
snapshot = self.node.get_dataset(self.args.snapshot)
|
snapshot = self.node.get_dataset(self.args.snapshot)
|
||||||
|
|
||||||
if not snapshot.exists:
|
if not snapshot.exists:
|
||||||
@ -150,6 +148,8 @@ class ZfsCheck(CliBase):
|
|||||||
def cli():
|
def cli():
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
signal(SIGPIPE, output_redir)
|
||||||
|
|
||||||
sys.exit(ZfsCheck(sys.argv[1:], False).run())
|
sys.exit(ZfsCheck(sys.argv[1:], False).run())
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ def block_hash_tree(start_path, count=10000, bs=4096):
|
|||||||
try:
|
try:
|
||||||
for (dirpath, dirnames, filenames) in os.walk(".", onerror=walkerror):
|
for (dirpath, dirnames, filenames) in os.walk(".", onerror=walkerror):
|
||||||
for f in filenames:
|
for f in filenames:
|
||||||
file_path=os.path.join(dirpath, f)
|
file_path=os.path.join(dirpath, f)[2:]
|
||||||
|
|
||||||
if (not os.path.islink(file_path)) and os.path.isfile(file_path):
|
if (not os.path.islink(file_path)) and os.path.isfile(file_path):
|
||||||
for (chunk_nr, hash) in block_hash(file_path, count, bs):
|
for (chunk_nr, hash) in block_hash(file_path, count, bs):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user