Backup
For better protection, the created backup should be transferred off the host to an independent storage location, ensuring it cannot be overwritten or lost in the event of a host failure.
If you are using docker-compose, you are using Docker Compose v1, which has been deprecated. Docker Compose commands refer to Docker Compose v2. Consider upgrading your docker setup, see Migrate to Compose V2
Backup
Create backup file teslamate.bck:
- Docker Compose
- NixOS
docker compose exec -T database pg_dump -U teslamate teslamate > ./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 lose 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.
You can use the idiomatic backup script:
teslamate-backup teslamate_$(date +%Y%m%d-%H%M).bck