Exporting settings

Leif Neland4 years ago

Is there a nice way to export configuration, users, zones to a new (dockerized) installation?

Anton Tananaev4 years ago

Make a database backup and restore it on your new installation.

docker cp traccar:/opt/traccar/data/atabase.trace.db /home/admin/traccar_db/
docker cp traccar:/opt/traccar/data/database.mv.db /home/admin/traccar_db/

docker cp /home/admin/traccar_db/database.trace.db traccar2020:/opt/traccar/data/
docker cp /home/admin/traccar_db/database.mv.db traccar2020:/opt/traccar/data/

I start new container with 4.10. But seems its hangs.
log has this and nothing more
2020-10-26 21:18:18 INFO: HikariPool-1 - Starting...

PS: Seems that database.trace.db is tooo big 7 472 336 896 - but it works fine in previous version

Anton Tananaev4 years ago

You shouldn't use H2 for any production databases.

After 2 years of use I understand this :)
Is there a way to save (or export) users/ priveleges/ devices from this H2?

Anton Tananaev4 years ago

Search forum. Some people did a migration from H2 and provided details.

Unfortunately I did not find any info on the forum. But I found the solution.

We have traccar in a docker container.

To export H2 db to SQL:

  1. log into the container
    docker exec -t -i traccar /bin/sh

  2. Inside make a temp folder to make a copy of DB
    mkdir /opt/traccar/data/backup
    then
    exit

  3. stop the container
    docker stop traccar

  4. copy db files from the container to the host
    mkdir /home/admin/traccar_db
    docker cp traccar:/opt/traccar/data/database.trace.db /home/admin/traccar_db/
    docker cp traccar:/opt/traccar/data/database.mv.db /home/admin/traccar_db/

  5. copy db files from the host back to the container.
    Direct copy inside the container is not possible because DB is locked and could be partially in RAM; Without making a copy you can't export because DB is locked!
    docker cp /home/admin/traccar_db/database.trace.db traccar:/opt/traccar/data/backup/
    docker cp /home/admin/traccar_db/database.mv.db traccar:/opt/traccar/data/backup/

  6. start the container & go in
    docker stop traccar
    docker exec -t -i traccar /bin/sh
    cd /opt/traccar/data/backup/

  7. make script
    echo "SCRIPT TO 'db-dump.sql'" > query.sql

  8. Let's export!
    Very important note: h2 version (h2-1.4.197.jar) should be the same as used in the container. If you download latest h2 version there would be errors (no reverse compatibility!!!) Look into /opt/traccar/lib/ and use h2-******.jar file you have in this folder.

java -cp /opt/traccar/lib/h2-1.4.197.jar org.h2.tools.RunScript -url "jdbc:h2:/opt/traccar/data/backup/database" -user sa -script query.sql -showResults

So as a result we have db-dump.sql which we can copy the host machine and import / edit / ...