snippets/bash/bingus-bak/restore.sh

23 lines
486 B
Bash
Raw Normal View History

2025-01-28 01:16:47 +03:00
#!/usr/bin/env bash
set -eo pipefail
if [[ -e restoration ]]; then
echo 'Error: an operation is already ongoing' >&2
exit 1
fi
mkdir restoration
echo "restoring baks/epoch" >&2
sudo btrfs receive restoration -f baks/epoch
find baks -maxdepth 1 -type f | sort | head -n-1 | while read -r file; do
echo "restoring $file" >&2
mv restoration/{current,last}
sudo btrfs receive restoration -f "$file"
sudo btrfs subvol delete restoration/last
done
echo "restoration complete" >&2