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.
Cool, that's next on my to-do list for this weekend so let me know how you get on.

So close... need some help though to get this running from cron.

Script works, but when trying to run from cron nothing happens

49 * * * * /home/pi/tmbackup/tmbackup.sh > /home/pi/tmbackup/tmb.log

Output in the syslog

May 6 21:49:02 raspberrypi CRON[5456]: (root) CMD (/home/pi/tmbackup/tmbackup.sh > /home/pi/tmbackup/tmb.log)
May 6 21:49:03 raspberrypi CRON[5452]: (CRON) info (No MTA installed, discarding output)

absolutely nothing in the tmb.log file either!
 
It was going so well but then..

root@raspberrypi:/home/pi/tmbackup# ./tmbackup.sh
./tmbackup.sh: line 2: +%A: command not found

I've checked that tmbackup.sh was saved OK and is in the correct directory
I'll review in the morning...

Can you paste the script in here? Looks like it’s not read the defining ‘now’ properly

My 3AM Cron job worked :D

985A9AB8-70AE-4BB0-87BD-1C9473005002.jpeg
 
  • Like
Reactions: Roy W.
That's working now!:)
Thank you @DaveW

Excellent, glad I could contribute something of value to this thread :)

One thing worth pointing out to everyone, is that the backup script (provided by TeslaMate) is only for the data, it doesn't include any customisations to Grafana, I'd suggest if you've made a great dashboard to export it out and keep a copy locally.

Next stop, making some funky dashboards!
 
  • Like
Reactions: Roy W.
Here we go: https://www.teslaev.co.uk/how-to-perform-an-automatic-teslamate-backup-to-google-drive/

If one of you could test and make sure I've got it all written down correctly, that'd be amazing :)

Nice one, will definitely give it a follow this weekend.

Initial glance and I'd highly recommend adding a date/timestamp to the .bck filename. I already got that far on my Pi but fell short of uploading it. Unless you beat me to it I'll post the code later, but I'd recommend teslamate_unixtime_readabledate.bck, so for now/today it'd be teslamate_1588842036_2020-05-07.bck.

The unix timestamp ensures you can never have a duplicate file (if you ever wanted to do or did two backups in a day).

You may not notice if the source data gets corrupted, or if the backup file that's generated is corrupted/0kb, and if you're overwriting your backup every day you could lose everything that way.

You can then manually delete older backups every so often, or if it allows then delete backups older than 30 days as part of the cron job.
 
Best bet is to backup the whole Pi SD card with compression enabled when you have a stable system. Then when drive has a problem (as a 6+ year Pi user I can say it will happen - power glitch the most critical point so I use a UPS Hat to soft power down incase of power issue), you can just burn the image to a new SD card, reapply any updates (since taking image backup), then restore the database. I had my Pi running just shy of 2 years (and then it was manually powered down) so they are capable of reliable long term use, but make sure that you keep logging to a minimum.
 
Nice one, will definitely give it a follow this weekend.

Initial glance and I'd highly recommend adding a date/timestamp to the .bck filename. I already got that far on my Pi but fell short of uploading it. Unless you beat me to it I'll post the code later, but I'd recommend teslamate_unixtime_readabledate.bck, so for now/today it'd be teslamate_1588842036_2020-05-07.bck.

The unix timestamp ensures you can never have a duplicate file (if you ever wanted to do or did two backups in a day).

You may not notice if the source data gets corrupted, or if the backup file that's generated is corrupted/0kb, and if you're overwriting your backup every day you could lose everything that way.

You can then manually delete older backups every so often, or if it allows then delete backups older than 30 days as part of the cron job.

I personally went for the adding the weekday option, then I'll have 7 backups, so at least one should be good in the event of an issue, they also then overwrite themselves to save me having to do any housekeeping :)
 
Excellent, glad I could contribute something of value to this thread :)

One thing worth pointing out to everyone, is that the backup script (provided by TeslaMate) is only for the data, it doesn't include any customisations to Grafana, I'd suggest if you've made a great dashboard to export it out and keep a copy locally.

Next stop, making some funky dashboards!
Great work!

My Pi arrived today so I'll have a look at it later this week.
The Tesla is still in order so probably will not be able to do a lot once it's installed. But at least it's ready for when my Tesla arrived ;)
 
  • Like
Reactions: DaveW and Roy W.
@Russinating

You could amend the script I've done to look like this to make it append a date and time in before the .bck

Code:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
now='date +"%d-%m-%Y_%T"'
cd /home/pi/tmbackup
sudo /usr/local/bin/docker-compose exec -T database pg_dump -U teslamate teslamate > /home/pi/tmbackup/teslamate_${now}.bck
rclone copy --max-age 24h /home/pi/tmbackup --include 'teslamate.*' gdrive:TeslaMate
 
Ah, I didn't see you'd done that from the code as I wasn't looking for a suffix. I said I glanced!

Not a bad idea that actually. I might just amend it to be the day of the month so there's an "auto" month of backups. I don't trust myself to only have a week to spot an error... o_O
 
Ah, I didn't see you'd done that from the code as I wasn't looking for a suffix. I said I glanced!

Not a bad idea that actually. I might just amend it to be the day of the month so there's an "auto" month of backups. I don't trust myself to only have a week to spot an error... o_O

I think the autoformatting of the blog post might have also knackered up the {now} to be $$ for some reason, there's probably some 'helpful' shortcuts in place I need to look into, very confusing this morning!

@Mr Miserable - you might want to check your script, make sure the date bit is correct so you get a weeks worth of files
 
@DaveW

Well, they must be excellent instructions, because I appear to have been able to follow them!

After a copy and paste extravaganza, I think I've got it all working. After testing the cron job for a minute hence, the file I have in my Google Drive TeslaMate folder is called

teslamate.bck_date +"%A"

Is this correct?
 
  • Like
Reactions: DaveW
@DaveW

Well, they must be excellent instructions, because I appear to have been able to follow them!

After a copy and paste extravaganza, I think I've got it all working. After testing the cron job for a minute hence, the file I have in my Google Drive TeslaMate folder is called

teslamate.bck_date +"%A"

Is this correct?

Not quite @Roy W. the filename should be teslamate.bck_Thursday

Can you paste the contents of tmbackup.sh in here and we'll sort it
 
Not quite @Roy W. the filename should be teslamate.bck_Thursday

Can you paste the contents of tmbackup.sh in here and we'll sort it
I must admit that's what I was expecting... Here you go, and many thanks!

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

now='date +"%A"'

cd /home/pi/tmbackup

sudo /usr/local/bin/docker-compose exec -T database pg_dump -U teslamate teslamate > /home/pi/tmbackup/teslamate.bck_${now}

rclone copy --max-age 24h /home/pi/tmbackup --include 'teslamate.*' gdrive:TeslaMate