Skip to content

Commit

Permalink
Add openhab-cli backup/restore to menu 50 (#910)
Browse files Browse the repository at this point in the history
* added openhab-cli backup/restore implementation to 50 menu

Signed-off-by: Markus Storm <[email protected]>
  • Loading branch information
mstormi authored May 25, 2020
1 parent f9e1939 commit 71cb38d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
27 changes: 27 additions & 0 deletions functions/backup.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
#!/usr/bin/env bash

filebrowser() {
bkppath=/var/lib/openhab2/backups
# shellcheck disable=SC2164,SC2012
bkpfile=$(cd ${bkppath}; ls -lthp openhab2-backup-* 2>/dev/null | head -20 | awk -F ' ' '{ print $9 " " $5 }')
}

backup_openhab_config() {
infotext="You have successfully created a backup of your openHAB configuration."
out=$(openhab-cli backup | tail -2 | head -1 | awk -F ' ' '{print $NF}')
msg="${infotext}\\n\\nFile is ${out}"
whiptail --title "Created openHAB config backup" --msgbox "$msg" 11 78
}

restore_openhab_config() {
filebrowser
if [[ -z "$bkpfile" ]]; then whiptail --title "Could not find backup" --msgbox "We could not find any configuration backup file in the storage dir ${bkppath}" 8 80; return 0; fi
# shellcheck disable=SC2086
if ! fileselect=$(whiptail --title "Restore openHAB config" --cancel-button Cancel --ok-button Select --menu "\\nSelect your backup from most current 20 files below:" 30 60 20 $bkpfile 3>&1 1>&2 2>&3); then return 0; fi
cond_redirect systemctl stop openhab2
if echo "y" | openhab-cli restore "${bkppath}/${fileselect}"; then
whiptail --msgbox "Your selected openHAB configuration was successfully restored." 8 70
else
whiptail --msgbox "Sadly, there was a problem restoring your selected openHAB configuration." 8 70
fi
cond_redirect systemctl start openhab2
}

create_backup_config() {
local config=$1
local confdir=/etc/amanda/${config}
Expand Down
15 changes: 8 additions & 7 deletions functions/menu.bash
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,17 @@ show_main_menu() {

elif [[ "$choice" == "50"* ]]; then
choice2=$(whiptail --title "Welcome to the openHABian Configuration Tool $(get_git_revision)" --menu "Setup Options" 10 116 3 --cancel-button Back --ok-button Execute \
"50 | Amanda Backup documentation " "Read this before installing the Amanda backup software" \
"51 | Amanda Backup" "Set up Amanda to backup your openHAB config and openHABian box" \
"50 | Backup openHAB config" "Backup the current active openHAB configuration" \
"51 | Restore an openHAB config" "Restore a previous openHAB configuration from backup" \
"52 | Amanda System Backup" "Set up Amanda to comprehensively backup your complete openHABian box" \
3>&1 1>&2 2>&3)
if [ $? -eq 1 ] || [ $? -eq 255 ]; then return 0; fi
wait_for_apt_to_finish_update
case "$choice2" in
50\ *) whiptail --textbox /opt/openhabian/docs/openhabian-amanda.md --scrolltext 25 116 ;;
51\ *) amanda_setup ;;
50\ *) backup_openhab_config ;;
51\ *) restore_openhab_config ;;
52\ *) wait_for_apt_to_finish_update && amanda_setup ;;
"") return 0 ;;
*) whiptail --msgbox "A not supported option was selected (probably a programming error):\\n \"$choice2\"" 8 80 ;;
*) whiptail --msgbox "A non supported option was selected (probably a programming error):\\n \"$choice2\"" 8 80 ;;
esac

elif [[ "$choice" == "60"* ]]; then
Expand Down Expand Up @@ -213,5 +214,5 @@ show_main_menu() {
fi

# shellcheck disable=SC2154,SC2181
if [ $? -ne 0 ]; then whiptail --msgbox "There was an error or interruption during the execution of:\\n \"$choice\"\\n\\nPlease try again. If the error persists, please read /opt/openhabian/docs/openhabian-DEBUG.md or $repositoryurl/docs/openhabian-DEBUG.md how to proceed." 12 60; return 0; fi
if [ $? -ne 0 ]; then whiptail --msgbox "There was an error or interruption during the execution of:\\n \"$choice\"\\n\\nPlease try again. If the error persists, please read /opt/openhabian/docs/openhabian-DEBUG.md or https://github.com/openhab/openhabian/blob/master/docs/openhabian-DEBUG.md how to proceed." 12 70; return 0; fi
}

0 comments on commit 71cb38d

Please sign in to comment.