full Restore should work now TM

This commit is contained in:
snaki 2022-07-07 13:48:41 +02:00
parent 805449870e
commit 3e84ea65e3

42
btrbk
View file

@ -41,6 +41,8 @@ function bkRun {
} }
function runRestore { function runRestore {
echo "not implemented yet™"
exit 1
if [ -z ${rDate+x} ]; then if [ -z ${rDate+x} ]; then
for o in ${!VOLNAME[@]}; do for o in ${!VOLNAME[@]}; do
if [[ "${VOLNAME[$o]}" = "${restoreVol}" ]]; then if [[ "${VOLNAME[$o]}" = "${restoreVol}" ]]; then
@ -55,8 +57,6 @@ function runRestore {
# mount -o subvolid=1 -U $BTRFSUUID /mnt/$BTRFSUUID # mount -o subvolid=1 -U $BTRFSUUID /mnt/$BTRFSUUID
# btrfs subvolume delete /mnt/$BTRFSUUID/ # btrfs subvolume delete /mnt/$BTRFSUUID/
fi fi
echo "not implemented yet™"
exit 1
} }
function runFullRestore { function runFullRestore {
@ -65,10 +65,10 @@ function runFullRestore {
[yY]) rclone config;; [yY]) rclone config;;
*) ;; *) ;;
esac esac
echo "specify the remote path with trailing slash [remote:/path/to/backupdir/]" echo "Specify the remote path with trailing slash [remote:/path/to/backupdir/]"
read -r -p "Dir: " rcloneDir read -r -p "Dir: " rcloneDir
rclone copy $rcloneDir"config/btrbk.conf" /etc/btrbk.conf rclone copy $rcloneDir"config/btrbk.conf" /etc/btrbk.conf
echo "Supply Path of your gpg public and secret key" echo "Enter Path of your gpg public and secret key"
read -r -p "Publickey: " gpgPub read -r -p "Publickey: " gpgPub
read -r -p "Secretkey: " gpgPriv read -r -p "Secretkey: " gpgPriv
gpg --import $gpgPub gpg --import $gpgPub
@ -76,20 +76,18 @@ function runFullRestore {
source /etc/btrbk.conf source /etc/btrbk.conf
local bkSuffix=("${INCR[0]}" "${FULL[0]}") local bkSuffix=("${INCR[0]}" "${FULL[0]}")
btrfs subvolume create $restoreDir"snapshots" btrfs subvolume create $restoreDir"restore"
lastBk=$(rclone lsf $RCLONEDIR | grep ....-..-${FULL[0]} | tail -n -1 | sed "s/\/$//") lastBkDate=$(rclone lsf "$RCLONEDIR" | grep ....-..-${FULL[0]} | tail -n -1 | sed "s/full\/$//")
if rclone lsf $RCLONEDIR$($lastBk | sed "s/${FULL[0]}/${INCR[0]}") > /dev/null 2>&1; then for i in ${!bkSuffix[@]}; do
for i in ${!bkSuffix[@]}; do mapfile -t bkFile < <(rclone lsf "$RCLONEDIR$lastBkDate${bkSuffix[$i]}" 2>/dev/null)
mapfile -t bkFile < <(rclone lsf "$RCLONEDIR$lastBk${bkSuffix[$i]}/") for o in ${!bkFile[@]}; do
for o in ${!bkFile[@]}; do rclone rcat "$RCLONEDIR$lastBkDate${bkSuffix[$i]}/${bkFile[$o]}" | gpg --batch -d $PUBKEY -o - | btrfs receive $restoreDir"restore"
rclone rcat "$RCLONEDIR$lastBk${bkSuffix[$i]}/${bkFile[$o]}" | gpg --batch -d $PUBKEY -o - | btrfs recive $restoreDir"snapshots"
done
done done
for i in ${!SUBVOLS[@]}; do
rclone rcat /mnt/bk/root-bk.gpg | gpg --batch -d --passphrase-file /mnt/bk/gpgpass -o - | btrfs receive /mnt/restore
done done
for i in ${!VOLNAME[@]}; do
newestSnap=$(ls -a $restoreDir"restore" | grep ${VOLNAME[$i]}.\....-..- | tail -n -1 )
btrfs subvolume snapshot $restoreDir"restore/"$newestSnap $restoreDir${VOLNAME[$i]}
done
} }
function getSnap { function getSnap {
@ -111,9 +109,7 @@ function testConf {
fi fi
if rclone ls $RCLONEDIR > /dev/null 2>&1; then if rclone ls $RCLONEDIR > /dev/null 2>&1; then
if gpg --list-key $PUBKEY > /dev/null 2>&1; then if gpg --list-key $PUBKEY > /dev/null 2>&1; then
if [ $fullRestore=1 ]; then if [ $restore=1 ]; then
runFullRestore
elif [ $restore=1 ]; then
runRestore runRestore
elif [ $backup=1 ]; then elif [ $backup=1 ]; then
testDate testDate
@ -156,6 +152,7 @@ function echoHelp {
options=$(getopt -l "backup,force,date:,restore:,full-restore:,help" -o "bfd:r:x:h" -- "$@") options=$(getopt -l "backup,force,date:,restore:,full-restore:,help" -o "bfd:r:x:h" -- "$@")
eval set -- "$options" eval set -- "$options"
while true; do while true; do
case $1 in case $1 in
-b|--backup) backup=1; shift;; -b|--backup) backup=1; shift;;
@ -170,4 +167,9 @@ while true; do
esac esac
shift shift
done done
testConf
if [ $fullRestore=1 ]; then
runFullRestore
else
testConf
fi