InfluxDB Backup Database

It makes sense to periodically backup InfluxDB to an external drive in-case of corruption of onboard memory. I am using a USB memory stick.

A simple cronjob can take care of this (every night 2am), open Crontab:

crontab -e

and insert the below line: (change for your storage device)

0 2 * * * influxd backup -portable /media/pi/16GB/

Backup names start with the date it was generated but it can get messy after a few weeks. Long term I plan to put this in a script to put in individual directories and catch errors etc but it works well for me so far.

I keep an eye on the USB memory stick size by the below snip of script which can be logged to InfluxDB. A Grafana alarm keeps an eye on the size and alerts if getting close to capacity.

DIRECTORY="/media/pi/16GB"
if [ -d "$DIRECTORY" ]; then
    usb_mem_usage=$(du -s $DIRECTORY | awk 'NR==1{print $1}')
else
    usb_mem_usage="-1"
fi
echo $usb_mem_usage

All done!

Leave a Reply

Your email address will not be published. Required fields are marked *