calculate hashes on-the-fly (major speedup)
This commit is contained in:
parent
cdac2e8ab4
commit
5dda6562a6
1 changed files with 14 additions and 16 deletions
30
btv
30
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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue