Compare commits

...

6 commits

Author SHA1 Message Date
Martin Sekera
83bac5876d simplify shapshot naming 2023-01-15 18:53:52 +01:00
Martin Sekera
bbd568260a fix unpack.sh chmod 2021-08-01 10:14:40 +02:00
Martin Sekera
63906d328f fix unpack.sh directory 2021-08-01 09:56:32 +02:00
Martin Sekera
831d9ae9a2 add unpack script to every snapshot 2021-08-01 09:36:19 +02:00
Martin Sekera
8345eb3217 chmod dirs rwx instead of r-x so they can be moved 2021-05-31 12:08:53 +02:00
Martin Sekera
71886bee68 chmod rank2 dir as well 2021-05-30 23:53:47 +02:00
2 changed files with 33 additions and 3 deletions

12
btv
View file

@ -8,6 +8,7 @@ import datetime
import json
import os
import shlex
import shutil
import sys
import time
import socket
@ -198,9 +199,9 @@ def serialize(snap, outdir, key, snap_from=None):
## prepare directories
##
if snap_from:
name = "%s diff from %s" %(snap.name, snap_from.name)
name = "%s to %s" %(snap_from.name, snap.name)
else:
name = "%s full" %(snap.name)
name = snap.name
directory = os.path.join(outdir, name)
os.makedirs(directory)
@ -246,14 +247,19 @@ def serialize(snap, outdir, key, snap_from=None):
## final touches
##
## add a self-check executable
## add self-check and unpack executables
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, 0o500)
unpack_path = os.path.join(directory, "unpack.sh")
shutil.copy("/usr/share/btv/unpack.sh", unpack_path)
os.chmod(unpack_path, 0o500)
## fix permissions and ownership of created objects
outdir_stat = os.stat(outdir)
os.chown(directory, outdir_stat.st_uid, outdir_stat.st_gid)
os.chmod(directory, 0o700)
for file in os.listdir(directory):
path = os.path.join(directory, file)

24
unpack.sh Normal file
View file

@ -0,0 +1,24 @@
#! /bin/zsh
TIMESTAMP=($(basename "$(pwd)"))
OUTDIR="$1"
KEYFILE="$2"
function die {
>&2 echo "$2"
exit $1
}
[[ "$0" != "./unpack.sh" ]] && die 1 "This can only be executed from the snapshot directory itself."
[[ ! -d "$OUTDIR" ]] && die 1 "The first argument must be a directory to unpack subvolumes into."
[[ ! -f "$KEYFILE" ]] && die 1 "The second argument must be a readable keyfile."
./check-integrity.sh || die 2 "This snapshot failed integrity checks."
### end of checks
for ARCHIVE in *btrfs.zst.aes
do
openssl enc -d -aes-256-cbc -pbkdf2 -salt -pass "file:$KEYFILE" < "$ARCHIVE" | zstd -d | btrfs receive "$OUTDIR" || die 3 "Failed to unpack subvolume."
SUBVOL_NAME=${ARCHIVE%%.btrfs.zst.aes}
mv "${OUTDIR}/${SUBVOL_NAME}" "${OUTDIR}/${SUBVOL_NAME}.${TIMESTAMP[1]}" || die 4 "Failed to rename subvolume."
done