Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

TeslaMate [megathread]

This site may earn commission on affiliate links.
Does anyone automate the backup of Teslamate within a script?

I've got it running fine when running the script from a command line within my archlinux on Raspberry PI.

However I have added the script as a service, and when it automatically runs at midnight, the created file is 0 bytes

The relevant part of the script file is simply

echo -e "Backup Teslamate"

docker-compose exec -T database pg_dump -U teslamate teslamate > /home/alarm/teslamate.bck
 
  • Like
Reactions: cwanja
Does anyone automate the backup of Teslamate within a script?

I've got it running fine when running the script from a command line within my archlinux on Raspberry PI.

However I have added the script as a service, and when it automatically runs at midnight, the created file is 0 bytes

The relevant part of the script file is simply
Bet the docker-compose automated command / script is not running in the directory that the docker YML file is located as @init6 points out.
 
  • Like
Reactions: init6
Does anyone automate the backup of Teslamate within a script?

I've got it running fine when running the script from a command line within my archlinux on Raspberry PI.

However I have added the script as a service, and when it automatically runs at midnight, the created file is 0 bytes

The relevant part of the script file is simply
Why not run via Cron?
 
  • Like
Reactions: garylovesbeer
Does anyone automate the backup of Teslamate within a script?

I've got it running fine when running the script from a command line within my archlinux on Raspberry PI.

However I have added the script as a service, and when it automatically runs at midnight, the created file is 0 bytes

The relevant part of the script file is simply
Yeah, here's my crontab entry for my pi user, along with the script I use - I use rclone to back up a copy every night to my Google drive (I'll leave the configuration of rclone as an exercise for the reader):

Code:
PATH=/usr/local/bin:/usr/bin:/bin
0 0 * * * /home/pi/docker/teslamate/teslamate-backup.sh > /home/pi/docker/teslamate/teslamate-backup.log 2>&1

Code:
#!/bin/bash
BASEDIR=`dirname $0`
NOW=`date +"%A"`
FILE="teslamate-backup-${NOW}.sql"
FILEZ="teslamate-backup-${NOW}.sql.xz"

cd "${BASEDIR}"

docker-compose exec -T database pg_dump -U teslamate teslamate > $FILE && \
    rm -f $FILEZ && \
    nice -20 pixz $FILE && \
    rclone copy --max-age 24h "${BASEDIR}" --include 'teslamate-backup*' gdrive:backups
 
start with syslog, but adding the path command to your script will likely fix the issue.
cheers, the -f param appears to have worked.

echo -e "Backup Teslamate"

docker-compose -f /home/alarm/docker-compose.yml exec -T database pg_dump -U teslamate teslamate > /home/alarm/teslamate.bck

@bhanorthy cron would have the same issue (and the same fix of using the -f param)

@Dave EV - thanks for that,
 
I don't think there's anything I can do at this point but - I'm on vacation and set it up so I can remotely check in on teslamate/my Pi and it's been working so far for the past few days... but all of a sudden last night pi disappeared off the network. I can't even ping it via host name and on Eset network scanner it says poor Pi has been last seen 8 horus ago. Is there any way to remotely send reboot command or something tot he Pi? Aside from physically being at the place and hard power off /on? A bit bummed out I'll be missing out on data collection :(
 
Nope can't ping or ssh via its host name :(
Smart plug is so clever...

If I start TeslaFi (as emergency measure) and import it into TeslaMate once I get home, will it overwrite teslamate data or "pad" additional data on?
I think that the Teslafi Import scripts only allow you to import old data into a Teslamate DB. i.e. it's designed to allow you to migrate from Teslafi to Teslamate. The instructions suggest that it won't import data after existing Teslamate data:

NOTE​

If there is an overlap between the already existing TeslaMate and TeslaFi data, only the data prior to the first TeslaMate data will be imported.
 
I don't think there's anything I can do at this point but - I'm on vacation and set it up so I can remotely check in on teslamate/my Pi and it's been working so far for the past few days... but all of a sudden last night pi disappeared off the network. I can't even ping it via host name and on Eset network scanner it says poor Pi has been last seen 8 horus ago. Is there any way to remotely send reboot command or something tot he Pi? Aside from physically being at the place and hard power off /on? A bit bummed out I'll be missing out on data collection :(
Suppose this is one reason to set up on Google GCP or Amazon AWS I suppose.
 
I've an issue with my Y not sleeping. I reset the Tesla password and it slept as expected.

I've slowly been enabling things, and then last night it stopped sleeping again. I see these warnings & disconnects in the Teslamate log, could it be a communication issue that is causing the issues?

Code:
alarm-teslamate-1  | 2022-05-02 18:28:45.546 [info] GET https://owner-api.teslamotors.com/api/1/vehicles/123456789/vehicle_data -> 408 (9085.457 ms)
alarm-teslamate-1  | 2022-05-02 18:28:45.547 [warning] TeslaApi.Error / %{"error" => "{\"error\": \"timeout\"}", "error_description" => "", "response" => nil}
alarm-teslamate-1  | 2022-05-02 18:28:45.547 car_id=1 [error] Error / :unknown
alarm-teslamate-1  | 2022-05-02 18:29:15.762 car_id=1 [info] Vehicle is still online. Falling asleep for: 33 min
alarm-teslamate-1  | 2022-05-02 18:29:16.085 car_id=1 [warning] Received stale stream data: %TeslaApi.Stream.Data{elevation: 153, est_heading: 21, est_lat: xx.yy, est_lng: zz.xx, est_range: 124, heading: 21, odometer: 2103.5, power: 0, range: 135, shift_state: nil, soc: 42, speed: nil, time: ~U[2022-05-02 18:29:15.635Z]}
alarm-teslamate-1  | 2022-05-02 18:40:42.174 car_id=1 [info] Charging detected: -3 kW
alarm-teslamate-1  | 2022-05-02 18:40:42.178 car_id=1 [info] Charging detected: -4 kW
alarm-teslamate-1  | 2022-05-02 18:40:42.178 car_id=1 [info] Fetch already in progress ...
[[[GAP CUT OUT - THIS MORNING LOGS]]]
alarm-teslamate-1  | 2022-05-03 07:19:26.245 [warning] Too many disconnects from streaming API
alarm-teslamate-1  | 2022-05-03 07:19:26.245 car_id=1 [info] Creating new connection …
alarm-teslamate-1  | 2022-05-03 07:19:26.246 car_id=1 [info] Disconnecting ...
alarm-teslamate-1  | 2022-05-03 07:19:26.261 car_id=1 [info] Connecting ...
alarm-teslamate-1  | 2022-05-03 07:33:32.542 car_id=1 [info] Vehicle is still online. Falling asleep for: 3 h 3 min
alarm-teslamate-1  | 2022-05-03 07:37:13.245 [warning] Too many disconnects from streaming API
alarm-teslamate-1  | 2022-05-03 07:37:13.245 car_id=1 [info] Creating new connection …
alarm-teslamate-1  | 2022-05-03 07:37:13.245 car_id=1 [info] Disconnecting ...
alarm-teslamate-1  | 2022-05-03 07:37:13.261 car_id=1 [info] Connecting ...
alarm-teslamate-1  | 2022-05-03 07:53:29.729 [warning] Too many disconnects from streaming API
alarm-teslamate-1  | 2022-05-03 07:53:29.729 car_id=1 [info] Creating new connection …
alarm-teslamate-1  | 2022-05-03 07:53:29.729 car_id=1 [info] Disconnecting ...
alarm-teslamate-1  | 2022-05-03 07:53:29.744 car_id=1 [info] Connecting ...
alarm-teslamate-1  | 2022-05-03 08:03:33.061 car_id=1 [info] Vehicle is still online. Falling asleep for: 3 h 33 min
 
yes charging was overnight, it finished at 530am, car hasn't slept since then. Reset the password and it's slept straight away! Re-auth'd Teslamate and it's stayed asleep......only Intelligent Octopus or Watch for Tesla left as culprits now!
Intelligent Octopus polls the car regularly, it also caused mine issues where it would not sleep. When you finish charging if you hit the toggle to stop Octopus from being able to control the car it should then sleep. Just remember to enable it again before you next plug in :)
 
My teslamate account had logged me out, I tried to log back in again with new tokens and it failed.
I'd read there have been some changes to the API including the length of the API token so I upgraded Teslamate
Now it won't start, the error being

clock_gettime(CLOCK_MONOTONIC, _) failed​

I'm regressed Teslamate to a version that works, but the tokens don't work again.

EDIT: Solved with 1.25.0 (anything higher and it seems to fail with the above, anything lower and the tokens fail)