Skip to main content

Backup and Restore


Create backup file teslamate.bck:

docker-compose exec -T database pg_dump -U teslamate teslamate > /backuplocation/teslamate.bck

-T is important if you add this line a crontab or the backup will not work because docker will generate this error the input device is not a TTY


Be absolutely certain to move the teslamate.bck file to another safe location, as you may loose that backup file if you use a docker-compose GUI to upgrade your teslamate configuration. Some GUIs delete the folder that holds the docker-compose.yml when updating.


If you get the error No such service: database, update your docker-compose.yml or use db instead of database in the above command.


If you changed TM_DB_USER in the .env file from one of the advanced guides, make sure to replace the first instance of teslamate to the value of TM_DB_USER in the above command.



Replace the default teslamate value below with the value defined in the .env file if you have one (TM_DB_USER and TM_DB_NAME)

# Stop the teslamate container to avoid write conflictsdocker-compose stop teslamate
# Drop existing data and reinitializedocker-compose exec -T database psql -U teslamate << .drop schema public cascade;create schema public;create extension cube;create extension earthdistance;CREATE OR REPLACE FUNCTION public.ll_to_earth(float8, float8)    RETURNS    LANGUAGE SQL    IMMUTABLE STRICT    PARALLEL SAFE    AS 'SELECT public.cube(public.cube(public.cube(*cos(radians(\$1))*cos(radians(\$2))),*cos(radians(\$1))*sin(radians(\$2))),*sin(radians(\$1)))';.
# Restoredocker-compose exec -T database psql -U teslamate -d teslamate < teslamate.bck
# Restart the teslamate containerdocker-compose start teslamate