When will Backup/Restore be in openHAB GUI?

I am new to openHAB (V3.0.0). Enjoying the ride so far…

But a glaring omission from the GUI is BACKUP/RESTORE.
Just wondering if this is on the roadmap for V3.1.0?

I have seen.

  • The CLI commands to do backup/restore are well documented (on Linux at least)
  • The way to make a file available via the built in webserver is well documented (on Linux at least)
  • There is a way to use Exec Bindings (Exec - Bindings | openHAB) to run host commands

So … seems there is a workaround that I can see where

  • an item could be created that caused the backup file to be created
  • a URL could then be used to download the backup file to a local PC.
  • but it is still a workaround

Would the devs care to comment. Maybe it is harder that I am imagining?

I would not see this as a workaround. The CLI command is the standardised way to create a backup, how to call this command ( console or UI, in case of UI which? MainUI widget, sitemapp, HABPanel?) and where to externally store the backup is dependant on your system and personell preferences.

openhab-cli is the recommended interface to do backup/restore so no that is not a workaround.
It is no OH user functionality and that’s why there are no plans to put it into the GUI I know of.
If you use openHABian, it’s accessible via its text UI.

Do we not also put administrative tasks in the GUI as well as user functionality? PaperUI / Main UI has a large area dedicated to admin so it could be added if there was a desire, and I would agree that making this easier for people makes sense doesn’t it?

4 Likes

Yes I agree. Standard disclaimer applies, though: someone has to design, implement and support it.
(EDITED yes design as well, that is key)

Absolutely :slight_smile: and that’s the real point here I think… (as always :wink:)

1 Like

Won’t / couldn’t it be a problem

  • to restore files of a running system ( I assume that the UI only is available for a running system ) ?
  • in case of a non running system the UI is not available ?

Of course if this was implemented, such things would need to be looked at, but the issues you mention are relatively easy to work around and other systems out there do this from a web based UI. For example, many websites are managed through control panels - these provide functions to backup and restore everything on a site.

If the system was down, then of course the first step is always to get a basic system installed, and then recover the system from there.

As with anything - it needs to be designed - not just implemented.

1 Like

Home Assistant performs this with a separate “supervisor” with a UI. Their system is all Docker based though.

1 Like

I don’t have much to add except to say it’s not there because no one has done it. Unlike a lot of things brought up like this, I don’t think it would be all that hard to implement. It’d be a lot of work but not hard work I think, except for maybe the restore because OH probably really needs to be offline in order to restore to the JSONDB files or else what ever is in memory might be written over the restored files. A nice little pair of API calls to OH to stop writing to and then reload the JSONDB could be one way around that.

However, it is very clear to me that many users have a hard time figuring out the boundaries of what is openHAB and what is not openHAB. There will be users surprised by the fact and angry when this backup and restore feature doesn’t restore their Mosquitto configs, InfluxDB and Grafana, and anything else they may have installed through openHABian.

3 Likes

OK - I have it working as follows.
SiteMap GUI: The ON/OFF button does not go ‘ON’ when the command is running … but the OFF -> ON -> OFF events are in the events.log??
Classic UI: refuses to exec when clicking the ON/OFF button??

This is good enough for my needs. Simple backups.
If a restore is needed, happy to go CLI as that (should be) a rare event.

Screenshot 2021-01-05 145517

THING

UID: exec:command:16a22fada9
label: Backup
thingTypeUID: exec:command
configuration:
  transform: REGEX((.*))
  interval: 0
  autorun: false
  command: openhab-cli backup --web
  timeout: 20

/etc/openhab/misc/exec.whitelist

# For security reasons all commands that are used by the exec binding or transformation need to be whitelisted.
# Every command needs to be listed on a separate line below.
openhab-cli backup --web

Sitemap extract

    Frame label="Backup" item=Backup {
        Switch label="Run Backup" item=Backup_Running
        Text label="Output" item=Backup_Output
    }

Edits to /usr/share/openhab/runtime/bin/backup

2a3
>
34,37c35,45
<   ## Ask to run as root to prevent us from running sudo in this script.
<   if [ "$(id -u)" -ne 0 ]; then
<     echo "Please run this script as root! (e.g. use sudo)" >&2
<     exit 1
---
>   if [ "$1" = "--web" ];then
>     isWeb='1'
>     OPENHAB_USERDATA="/var/lib/openhab"
>     shift
>   else
>     isWeb='0'
>     ## Ask to run as root to prevent us from running sudo in this script.
>     if [ "$(id -u)" -ne 0 ]; then
>      echo "Please run this script as root! (e.g. use sudo)" >&2
>      exit 1
>     fi
39a48
>
51a61,65
> if [ "$isWeb" = "1" ];then
>     OPENHAB_BACKUPS="$OPENHAB_USERDATA/backup_user"
>     OPENHAB_BACKUPS_TEMP="$OPENHAB_USERDATA/tmp/backup"
> fi
>
59,62c73,77
<   echo "Using '$OPENHAB_CONF' as conf folder..."
<   echo "Using '$OPENHAB_USERDATA' as userdata folder..."
<   echo "Using '$OPENHAB_RUNTIME' as runtime folder..."
<
---
>   if [ "$isWeb" = "0" ];then
>     echo "Using '$OPENHAB_CONF' as conf folder..."
>     echo "Using '$OPENHAB_USERDATA' as userdata folder..."
>     echo "Using '$OPENHAB_RUNTIME' as runtime folder..."
>   fi
67c82
<     echo "including cache"
---
>      [ "$isWeb" = "0" ] && echo "including cache"
74c89,92
<   if [ -z "$1" ]; then
---
>   if [ "$isWeb" = "1" ];then
>     OutputFile="/etc/openhab/html/latest_backup.zip"
>     [ -e "$OutputFile" ] && rm $OutputFile
>   elif [ -z "$1" ];then
80c98
<   echo "Writing to '${OutputFile}'..."
---
>   [ "$isWeb" = "0" ] && echo "Writing to '${OutputFile}'..."
102c120
<   echo "Making Temporary Directory if it is not already there"
---
>   [ "$isWeb" = "0" ] && echo "Making Temporary Directory if it is not already there"
109c127
<   echo "Using $TempDir as TempDir"
---
>   [ "$isWeb" = "0" ] && echo "Using $TempDir as TempDir"
115,119c133,139
< echo "                                         "
< echo "#########################################"
< echo "          openHAB backup script          "
< echo "#########################################"
< echo "                                         "
---
> if [ "$isWeb" = "0" ];then
>    echo "                                         "
>    echo "#########################################"
>    echo "          openHAB backup script          "
>    echo "#########################################"
>    echo "                                         "
> fi
132c152
< echo "Copying configuration to temporary folder..."
---
> [ "$isWeb"  = "0" ] && echo "Copying configuration to temporary folder..."
143c163
< echo "Removing unnecessary files..."
---
> [ "$isWeb" = "0" ] && echo "Removing unnecessary files..."
156c176
< echo "Zipping folder..."
---
> [ "$isWeb"  = "0" ] && echo "Zipping folder..."
167c187
< echo "Removing temporary files..."
---
> [ "$isWeb" = "0" ] && echo "Removing temporary files..."
170,171c190,195
< echo "Success! Backup made in $OutputFile"
< echo ""
---
> if [ "$isWeb" = "1" ];then
>   echo "Download http://$(cat /etc/hostname):$OPENHAB_HTTP_PORT/static/latest_backup.zip"
> else
>   echo "Success! Backup made in $OutputFile"
>   echo ""
> fi

4 Likes

Can you please provide your code as a PR to openhab-distro. It’s not universally applicable but can be (become) a first step. Mind CONTRIBUTING.md
Use three backticks before and after code to properly display it here.

1 Like

OK … will do. I edited the backup script so that the behaviour is unchanged unless the new --web argument is included. So should not break anything.

1 Like

Hi Rob,

I think you have a great idea.

For me the only reliable way I have found to backup is to shutdown, copy the SD card to an image file and then create new/recycled SD card and fire up again on the new SD card. Then I know the old SD card is a quick recovery option, if I break something or an upgrade goes wrong, I just put the old SD card back in move on, WAF is maintained. I keep copies of the image files on my NAS and cycle 4 SD cards through. I know this process may be a bit cumbersome but it has worked for me for a few years.
(I do need to have another go at the openhabian automated backup approach, I failed to get this one working)

I think it would be great to be able to do a backup of OH in the main UI and be able to download the file for a restore in the same place, say in a clean openhabian install. I work a bit on Moodle and they have a similar process that works really well for peace of mind, changing hardware, hosting ect.

I appreciate it needs to be created. I think it would add a lot of value to the project for automation enthusiasts who may struggle with linux.

Regards,
George

I think you have a fundamental misunderstanding what this is about just like @rlkoshak suspected would happen with some users.
There is the openHAB config. That you can backup/restore using openhab-cli or by selecting menu 51 in openhabian-config today. This thread is about making that accessible from the web GUI, no more, no less. It will not change what is backed up/restored.
If you want to backup anything beyond your pure OH config like e.g. a mosquitto config (mosquitto is not a part of OH) or any config of whatever external tool such as those you can install through openHABian then this thread will not help you.
This is right what Rich suspected would happen (see his post).

To backup your complete system (== SD card) including OH, its config, mosquitto and its config and everything else you might have installed, you can use the openHABian backup/restore tool Amanda today. No need to pull out your SD card.
Note this is not the same as the openHABian auto-backup feature.

PR created as requested.

1 Like

Hi Markus,

With all due respect I don’t think I have a misunderstanding. I understand the boundaries of OH config, add ons ect. I didn’t mention anything about mosquito or the like.

In my short experience with OH3 I have seen the large strides made, really appreciate the work by all developers. I transitioned from 2.x without much textual configuration and have really enjoyed using the new main UI, simply copied/pasted my rules in the GUI and all worked fine.
It appears to me that the main UI will suffice for many users, for many more tasks than before and may combine sitemaps/paper UI and remove the need for textual configuration for many more tasks, this will be great for OH in general.

My point and suggestion is that I think Rob has a great idea to add backup/download & restore via the main UI. Apologies if that upset you.

Regards,
George

For what it’s worth, I also read your comment and thought you might have the confusion that Markus and Rich are concerned about. I think that’s because you first mentioned your process of cloning SD cards, so if you weren’t familiar with the openhab-cli backup process you might have thought it could replace this effort. Obviously that’s not the case, but it’s worth clarifying to be sure. :wink:

I also clone my SD card regularly, largely because I also run Network UPS Tools and Mosquitto on my RPi. I might play around with the new auto-backup feature if I find the time.

So

Got the Layout page working properly :slight_smile:

  - component: oh-block
    config:
      title: Backup
    slots:
      default:
        - component: oh-grid-cells
          config: {}
          slots:
            default:
              - component: oh-label-cell
                config:
                  item: Backup_Running
                  title: Run
                  stateAsHeader: true
                  expandable: false
                  icon: oh:switch
                  action: command
                  actionCommand: ON
                  color: blue
                  actionItem: Backup_Running
              - component: oh-label-cell
                config:
                  item: Backup_Output
                  title: Output
                  stateAsHeader: true
                  expandable: false

2 posts were split to a new topic: Web UI for openHABian