数据备份和还原
备份
- 如果您使用的是teslamate盒子,可以直接在盒子的管理后台,点击备份或者恢复按钮操作。
- 其它平台可按下面的步骤操作备份数据
登录到终端
- 如果你是阿里云腾讯云之类的云服务器,推荐直接进云服务器管理后台,在网页的终端操作(简单)
- 如果你是群晖之类的nas,可以通过ssh登录到nas
进入teslamate目录
- 云服务器一般在 /opt/teslamate 下
cd /opt/teslamate
- nas一般在 /volume1/docker/teslamate 下
cd /volume1/docker/teslamate
创建备份文件
docker-compose exec -T database pg_dump -U teslamate teslamate > ./teslamate.bck
或者
docker compose exec -T database pg_dump -U teslamate teslamate > ./teslamate.bck
检查备份文件大小
ls -lh teslamate.bck
如果teslamate.bck文件的大小为0,那就出错了没有备份成功。
压缩备份文件(可选)
gzip teslamate.bck
备份文件下载到电脑(可选)
- 阿里云腾讯云之类的云服务器的web终端,都有网页直接下载云服务器文件的功能,你可以点击web终端左上角的文件夹图标,然后,点击文件夹树进入/opt/teslamate 目录,然后直接下载文件。如果提示文件过大,可以压缩文件再下载。
- nas请自行用nas的管理工具下载到电脑。
- 如果是ssh登录的,也可以用ssh工具的下载文件功能。
-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.
Restore
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 conflicts
docker-compose stop teslamate
# Drop existing data and reinitialize
docker-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 public.earth
LANGUAGE SQL
IMMUTABLE STRICT
PARALLEL SAFE
AS 'SELECT public.cube(public.cube(public.cube(public.earth()*cos(radians(\$1))*cos(radians(\$2))),public.earth()*cos(radians(\$1))*sin(radians(\$2))),public.earth()*sin(radians(\$1)))::public.earth';
.
# Restore
docker-compose exec -T database psql -U teslamate -d teslamate < teslamate.bck
# Restart the teslamate container
docker-compose start teslamate