From 5dda6562a6921226609ae035c73788b6f8cb1252 Mon Sep 17 00:00:00 2001 From: Martin Sekera Date: Sat, 29 Aug 2020 02:16:50 +0200 Subject: [PATCH] calculate hashes on-the-fly (major speedup) --- btv | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/btv b/btv index 113b9b4..43570ad 100755 --- a/btv +++ b/btv @@ -213,9 +213,10 @@ def serialize(snap, outdir, key, snap_from=None): return 1 + ## serialization (most expensive) + ## with lockfile(LOCKFILE): - ## serialize each subvolume or subvolume pair - ## + for subvolume in snap.subvolumes: if snap_from: btrfs_send = 'btrfs send -p "%s" "%s"' %( @@ -227,30 +228,27 @@ def serialize(snap, outdir, key, snap_from=None): os.path.join(snap.path, subvolume) ) - error = os.system('%s | zstd | openssl enc -e -aes-256-cbc -pbkdf2 -salt -pass "file:%s" > "%s.btrfs.zst.aes"' %( + error = os.system('%s | zstd | openssl enc -e -aes-256-cbc -pbkdf2 -salt -pass "file:%s" | hash-pipe sha512 "%s.btrfs.zst.aes" "%s/manifest.sha512" > "%s.btrfs.zst.aes"' %( btrfs_send, cfg.get("crypto", "keyfile"), + subvolume, + directory, os.path.join(directory, subvolume) )) if error: print(" !! failed to serialize %s" %(subvolume)) return error - - ## calculate checksums and add a self-check executable - ## FIXME calculate this on the fly, re-reading is expensive - previous_wd = os.getcwd() - os.chdir(directory) - os.system('sha512sum "%s" > manifest.sha512' %( - '" "'.join("%s.btrfs.zst.aes" %(s) for s in snap.subvolumes) - )) - - with open("check-integrity.sh", "w") as f: - f.write("#! /bin/sh\n\nsha512sum --check manifest.sha512\n") + + ## final touches + ## + + ## add a self-check executable + with open(os.path.join(directory, "check-integrity.sh"), "w") as f: + f.write("#! /bin/sh\n\nsha512sum --check manifest.sha512\n") + os.chmod(f.name, 0o555) ## fix permissions and ownership of created objects - os.chmod("check-integrity.sh", 0o555) - outdir_stat = os.stat(outdir) os.chown(directory, outdir_stat.st_uid, outdir_stat.st_gid)