dotfiles/.bin/tarsnap-restore
2025-07-19 07:40:13 +02:00

39 lines
863 B
Bash
Executable File

#!/bin/sh
. $HOME/.bin/_config
print "Tarsnap Restore:"
if [ -z "$1" ]; then
doas tarsnap --list-archives | sort
printf "Usage: restore <key_id>\n"
exit 2
fi
_backup="$(doas tarsnap --list-archives | grep "$1")"
if [ -z "$_backup" ]; then
print "No backup with key id $1 found."
exit 1
fi
print "Found Backup: $_backup"
mkdir -p "restore_$1"
print "Extracting to: $(readlink -f $PWD/restore_$1)"
if [ -f "restore_$1/.done" ]
then
print "Skipping, because restore_$1/.done file exists."
else
doas tarsnap -tf "$_backup" \
| xargs -P 20 -n 20 -t \
doas tarsnap --humanize-numbers --resume-extract --chroot -xf "$_backup" -C "restore_$1" --
if [ $? -eq 0 ]
then
print "Data restored in $(readlink -f "restore_$1")"
touch "restore_$1/.done"
else
print "Restore aborted..."
fi
fi
print ""