OH3 migration without data loss

oh3 Moving the data to another directory. For example from /volume1/docker/openhab to /opt/openhab3.

Is this possible on a Synology NAS?

with docker, I assume you do a volume mapping when starting the container. If you change the volume mapping to the new location and start the container, this generally should work. Depends a bit on how you map the volumes, though :slight_smile:

rfuh

Can it work in such a way that I create another Openhab container in a Docker-Compose and set the storage location for the data I have created to “/opt/openhab3”? Then I would copy the files I created from /volume1/docker/openhab to /opt/openhab.

Is there anything else I should take into account?

Here is how I do it…

  1. Create backup of current system using the Openhab backup script.

  2. Rename it to restore.zip

  3. Move it into the restore directory specified in the docker-compose.yml file (./restore) that is mapped to /openhab/restore/

  4. Move the restore.sh shell script to the directory specified in the docker-compose file (./cont-init.d) that is mapped to /etc/cont-init.d. This is the location that Openhab will look for scripts to run at startup.

  5. Run docker-compose up

As the container is starting, Openhab will execute the shell script (restore.sh ) from the cont-init.d directory. The script runs the Openhab restore program to restore the configuration located in the restore directory. It then renames the restore.zip file to prevent restoring on every startup.

Be sure you have all the proper permissions on the files (e.g. owner: openhab:openhab and permission on the script: 755).

restore.sh

#!/bin/bash -x
 if [ -e /openhab/restore/restore.zip ] ; 
 then echo y | 
   /openhab/runtime/bin/restore /openhab/restore/restore.zip; 
   DATE=`date | sed -e "s/ /_/g"`
   echo $DATE
mv /openhab/restore/restore.zip /openhab/restore/restore_$DATE.zip
fi

docker-compose.yml

version: '3.8'
services:
  openhab:
    container_name: openhab 
    image: "openhab/openhab:3.3.0.M5"
    restart: always
    network_mode: host
    volumes:
      - type: bind                                                      # volume for Openhab optional user startup script(s)    
        source: ./cont-init.d                                           # Openhab will run the script(s) as it starts up
        target: /etc/cont-init.d                                        #       
      - type: bind                                                      # Location of backup file created in Openhabian backup. 
        source: ./restore                                               # It needs to be named restore.zip. will be restored on
        target: /openhab/restore                                        # after the restore the file is renamed to avoid loop
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/setc/timezone:ro"
      - "./data/openhab-addons:/openhab/addons"
      - "./data/openhab-conf:/openhab/conf"
      - "./data/openhab-userdata:/openhab/userdata"
    ports:  
      - 8001:8001
    environment:
      OPENHAB_HTTP_PORT: "8080"
      OPENHAB_HTTPS_PORT: "8443"
      EXTRA_JAVA_OPTS: "-Duser.timezone=America/Denver -Xms512m -Xmx1024m"

I hope this helps.

OK, so far I have always backed up data completely using Synology Hyper Backup. How do I make an Openhab System Backup Script? My work files are in the Docker container.

The Openhab backup script is: /openhab/runtime/bin/backup in the docker container. You should be able to run it on your Synology station then move to the new system.

Not familiar with Hyper Backup or how to “map” it into what the Openhab restore would expect.