From 3e84ea65e373fb9a1b1a54b9320bf291af852dc6 Mon Sep 17 00:00:00 2001 From: snaki Date: Thu, 7 Jul 2022 13:48:41 +0200 Subject: [PATCH] full Restore should work now TM --- btrbk | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/btrbk b/btrbk index c1a02a2..0066e56 100755 --- a/btrbk +++ b/btrbk @@ -41,6 +41,8 @@ function bkRun { } function runRestore { + echo "not implemented yetâ„¢" + exit 1 if [ -z ${rDate+x} ]; then for o in ${!VOLNAME[@]}; do if [[ "${VOLNAME[$o]}" = "${restoreVol}" ]]; then @@ -55,8 +57,6 @@ function runRestore { # mount -o subvolid=1 -U $BTRFSUUID /mnt/$BTRFSUUID # btrfs subvolume delete /mnt/$BTRFSUUID/ fi - echo "not implemented yetâ„¢" - exit 1 } function runFullRestore { @@ -65,10 +65,10 @@ function runFullRestore { [yY]) rclone config;; *) ;; 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 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 "Secretkey: " gpgPriv gpg --import $gpgPub @@ -76,20 +76,18 @@ function runFullRestore { source /etc/btrbk.conf local bkSuffix=("${INCR[0]}" "${FULL[0]}") - btrfs subvolume create $restoreDir"snapshots" - lastBk=$(rclone lsf $RCLONEDIR | grep ....-..-${FULL[0]} | tail -n -1 | sed "s/\/$//") - if rclone lsf $RCLONEDIR$($lastBk | sed "s/${FULL[0]}/${INCR[0]}") > /dev/null 2>&1; then - for i in ${!bkSuffix[@]}; do - mapfile -t bkFile < <(rclone lsf "$RCLONEDIR$lastBk${bkSuffix[$i]}/") - for o in ${!bkFile[@]}; do - rclone rcat "$RCLONEDIR$lastBk${bkSuffix[$i]}/${bkFile[$o]}" | gpg --batch -d $PUBKEY -o - | btrfs recive $restoreDir"snapshots" - done + btrfs subvolume create $restoreDir"restore" + lastBkDate=$(rclone lsf "$RCLONEDIR" | grep ....-..-${FULL[0]} | tail -n -1 | sed "s/full\/$//") + for i in ${!bkSuffix[@]}; do + mapfile -t bkFile < <(rclone lsf "$RCLONEDIR$lastBkDate${bkSuffix[$i]}" 2>/dev/null) + for o in ${!bkFile[@]}; do + rclone rcat "$RCLONEDIR$lastBkDate${bkSuffix[$i]}/${bkFile[$o]}" | gpg --batch -d $PUBKEY -o - | btrfs receive $restoreDir"restore" 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 - + 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 { @@ -111,9 +109,7 @@ function testConf { fi if rclone ls $RCLONEDIR > /dev/null 2>&1; then if gpg --list-key $PUBKEY > /dev/null 2>&1; then - if [ $fullRestore=1 ]; then - runFullRestore - elif [ $restore=1 ]; then + if [ $restore=1 ]; then runRestore elif [ $backup=1 ]; then testDate @@ -156,6 +152,7 @@ function echoHelp { options=$(getopt -l "backup,force,date:,restore:,full-restore:,help" -o "bfd:r:x:h" -- "$@") eval set -- "$options" + while true; do case $1 in -b|--backup) backup=1; shift;; @@ -170,4 +167,9 @@ while true; do esac shift done -testConf + +if [ $fullRestore=1 ]; then + runFullRestore +else + testConf +fi