53 lines
4.0 KiB
Bash
53 lines
4.0 KiB
Bash
#!/usr/bin/env bash
|
|
# R-1105: capture REAL restic outputs from 0.14.0 and 0.18.1 as test fixtures. ONE shared repo (made by 0.14.0) so
|
|
# both versions read the same snapshot set. Scratch only; paths are rewritten to /data/x; no secret is captured.
|
|
set -u
|
|
S=<scratch>
|
|
DEST=${1:?testdata dir}; W=$S/fxwork; rm -rf $W; mkdir -p $W
|
|
export RESTIC_PASSWORD_FILE=$W/pw RESTIC_CACHE_DIR=$W/cache TZ=UTC
|
|
head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n' > $RESTIC_PASSWORD_FILE
|
|
OLD=$S/bin/restic-0.14.0; REPO=$W/repo
|
|
mkdir -p $W/u/a/db-dumps $W/u/b; echo "select 1;" > $W/u/a/db-dumps/a.sql
|
|
$OLD -r $REPO init >/dev/null 2>&1
|
|
for d in $(seq 40 -1 0); do day=$(date -u -d "2026-10-16 -$d days" +%F)
|
|
for app in a b; do echo "$day" > $W/u/$app/f.txt
|
|
$OLD -r $REPO backup --host box --tag felhom-offbox --tag $app --time "$day 02:30:00" $W/u/$app >/dev/null 2>&1; done; done
|
|
head -c 40M /dev/urandom > $W/u/a/big.tar
|
|
for V in 0.14.0 0.18.1; do
|
|
R=$S/bin/restic-$V; O=$W/out/$V; mkdir -p $O
|
|
$R -r $REPO snapshots --json > $O/snapshots.json 2>&1
|
|
$R -r $REPO snapshots latest --tag a --json > $O/snapshots-latest-tag.json 2>&1
|
|
ID=$(python3 -c 'import json,sys;print(json.load(open(sys.argv[1]))[0]["short_id"])' $O/snapshots-latest-tag.json)
|
|
$R -r $REPO stats "$ID" --json > $O/stats-id.json 2>&1
|
|
$R -r $REPO stats --mode raw-data --json > $O/stats-raw.json 2>&1
|
|
# a fixed "now" is impossible for restic, so the plan is captured at the same minute for both versions
|
|
$R -r $REPO forget --group-by host,tags --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --dry-run --json > $O/forget-dryrun.json 2>&1
|
|
cp -a $REPO $W/bk-$V; $R -r $W/bk-$V backup --host box --tag felhom-offbox --tag a $W/u/a --json 2>&1 | grep '"message_type":"status"' | awk 'NR%7==1' | head -12 > $O/backup-status.jsonl
|
|
rm -rf $W/bk-$V
|
|
RESTIC_PASSWORD_FILE= RESTIC_PASSWORD=wrong $R -r $REPO cat config > $O/wrong-password.txt 2>&1 < /dev/null
|
|
$R -r $W/nothing-here cat config > $O/no-repo.txt 2>&1
|
|
$R -r $REPO init > $O/init-exists.txt 2>&1
|
|
$R -r sftp:u@127.0.0.1:/x -o sftp.command="ssh u@127.0.0.1 -p 1 -oBatchMode=yes -oConnectTimeout=3 -s sftp" cat config > $O/sftp-refused-port.txt 2>&1
|
|
ssh-keygen -q -t ed25519 -N '' -f $W/k-$V
|
|
$R -r sftp:u@127.0.0.1:/x -o sftp.command="ssh u@127.0.0.1 -p 22 -oBatchMode=yes -oConnectTimeout=3 -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oLogLevel=ERROR -oIdentitiesOnly=yes -i $W/k-$V -s sftp" cat config > $O/sftp-refused-key.txt 2>&1
|
|
$R -r sftp:u@10.255.255.1:/x -o sftp.command="ssh u@10.255.255.1 -p 22 -oBatchMode=yes -oConnectTimeout=3 -s sftp" cat config > $O/sftp-unreachable.txt 2>&1
|
|
$R -r rclone:x -o rclone.program="ssh -p 1 -oBatchMode=yes -oConnectTimeout=3 u@127.0.0.1 rclone" cat config > $O/rclone-dead-ssh.txt 2>&1
|
|
for KIND in shared exclusive; do
|
|
cp -a $REPO $W/lk;
|
|
if [ $KIND = shared ]; then ( sleep 600 | unshare --uts --map-root-user sh -c "hostname other-box; exec $R -r $W/lk backup --stdin --stdin-filename x" ) >/dev/null 2>&1 &
|
|
else ( unshare --uts --map-root-user sh -c "hostname other-box; exec $R -r $W/lk prune" ) >/dev/null 2>&1 & fi
|
|
for i in $(seq 1 400); do [ -n "$(ls $W/lk/locks 2>/dev/null)" ] && break; sleep 0.005; done
|
|
pkill -9 -f "restic-$V -r $W/lk"; pkill -f 'sleep 600'; sleep 0.5
|
|
$R -r $W/lk forget --keep-last 1 --prune > $O/locked-$KIND.txt 2>&1
|
|
rm -rf $W/lk
|
|
done
|
|
$R -r $REPO check > $O/check-ok.txt 2>&1
|
|
cp -a $REPO $W/dmg; PK=$(find $W/dmg/data -type f | head -1); chmod u+w "$PK"; printf 'XXXXXXXXXXXXXXXX' | dd of="$PK" bs=1 seek=200 conv=notrunc 2>/dev/null
|
|
$R -r $W/dmg check --read-data > $O/check-damaged.txt 2>&1; chmod -R u+w $W/dmg; rm -rf $W/dmg
|
|
done
|
|
# rewrite every local path to /data/x and the user/host names to neutral ones
|
|
for f in $W/out/*/*; do sed -i -e "s#$W#/data/x#g" -e "s#$S#/data/x#g" -e "s/$(id -un)/root/g" -e "s/$(hostname)/box/g" "$f"; done
|
|
mkdir -p $DEST; cp -r $W/out/* $DEST/
|
|
for V in 0.14.0 0.18.1; do echo "$V: $(ls $DEST/$V | wc -l) files, $(du -sh $DEST/$V | cut -f1)"; done
|
|
grep -rl "$S\|$(id -un)" $DEST && echo "LEAK" || echo "no local path left"
|