diff --git a/btrbk b/btrbk index 48a021f..ce2a65d 100755 --- a/btrbk +++ b/btrbk @@ -35,7 +35,7 @@ function bkRun { btrfs subvolume delete $SNAPDIR${oldSnaps[$snap]} done done - rclone copy /etc/btrbk.conf $RCLONEDIR"config/" + rclone sync /etc/btrbk.conf $RCLONEDIR"config/" end } @@ -102,7 +102,7 @@ function runFullRestore { *) echo "Enter gpg Passphrase" while true; do - read -e -r -p "Passphrase: " gpgPass + read -e -s -r -p "Passphrase: " gpgPass echo | gpg --local-user "$PUBKEY" --pinentry-mode=loopback --passphrase "$gpgPass" -as > /dev/null 2>&1 && echo "Passphrase correct" && break echo "Wrong Passphrase" done;; @@ -120,11 +120,17 @@ function runFullRestore { newestSnap=$(ls -a $restoreDir"restore" | grep ${VOLNAME[$i]}.\....-..- | tail -n -1 ) btrfs subvolume snapshot $restoreDir"restore/"$newestSnap $restoreDir${VOLNAME[$i]} done - mapfile -t delVol < <(ls $restoreDir"restore") - for i in ${!delVol[@]}; do - btrfs subvolume delete $restoreDir"restore/"${delVol[$i]} - done - btrfs subvolume delete $restoreDir"restore" + read -e -r -p "Delete restore subvolume?[Y/n]: " delOldVol + case $delOldVol in + [nN]) ;; + *) + mapfile -t delVol < <(ls $restoreDir"restore") + for i in ${!delVol[@]}; do + btrfs subvolume delete $restoreDir"restore/"${delVol[$i]} + done + btrfs subvolume delete $restoreDir"restore";; + esac + btrfs subvolume create $restoreDir"snapshots" end } @@ -153,13 +159,14 @@ function testConf { testDate fi else - echo "pubkey wrong or not found exit code: $?" + echo "pubkey wrong or not found" exit 1 fi else - echo "rclone dir wrong or not found exit code: $?" + echo "rclone dir wrong or not found" exit 1 fi + exit 1 } function testDate { @@ -172,7 +179,7 @@ function testDate { function end { echo "finished in $(( ($(date +%s) - startDate) / 60 )) min" - exit 1 + exit 0 } function echoHelp { @@ -191,14 +198,14 @@ function echoHelp { options=$(getopt -l "backup,force,date::,restore::,full-restore::,help" -o "bfd::r::x::h" -- "$@") eval set -- "$options" -while true; do +for i in ${!options[@]}; do case $1 in -b|--backup) backup=true; shift;; -f|--force) force=true; shift;; --date) rDate="$2"; shift;; --restore) restore=true; restoreVol=$2; shift;; --full-restore) fullRestore=true; restoreDir=$2; shift;; - -h|--help) Help; shift; break;; + -h|--help) echoHelp; shift; break;; --) shift; break;; \?) echo "error"; exit 1;; esac @@ -207,8 +214,6 @@ done if [ "$fullRestore" = true ]; then runFullRestore -elif [ "$backup" = true ]; then - testConf else - echoHelp + testConf fi