I have both MariaDB and InfluxDB installed on HA OS on Intel NUC. Weekly backup is stored on HA OS and Synology NAS of 1 copy and 2 copies respectively. I intend to keep the sensor data for long term.
Because now I’m running out of disk (80% used of 256GB NVME). I’ve decided to keep 30 days of data on MariaDB via recorder and long term data in InfluxDB.
How does one take backup of InfluxDB?
I know, it is running inside a container so I tried docker command, but it is not installed. I tried portainer installation via HACS but it is not installed, add on seems worthless. How do one get access to docker container of InfluxDB? ChatGPT gave some command to use cli but first command itself is docker exec but docker command does not run on HA terminal, seems it is not installed as it is docker container itself.
Then InfluxDB has not a single GUI tools that can take backup or restore.
Thanks, yes, this is best way for the home assistance backup and restore.
Though I gone much deeper than that using ChatGPT. My motivation was to save this data even if I don’t want HA OS in future or restore this data on another instance of InfluxDB without HA just for backup or analyzing the data.
First enabled the HA OS root ssh using developer page at Debugging the Home Assistant Operating System | Home Assistant Developer Docs and after login in I got to know the container name using docker ps and where my NAS drive was mounted, thereafter I used the following:
#!/bin/bash
# How to Use the Script
# Save the script to a file on your Home Assistant OS host, e.g., /usr/local/bin/influxdb_backup.sh.
# Make it executable:
# bash
# chmod +x /usr/local/bin/influxdb_backup.sh
# Run the script whenever you want to take a backup:
# bash
# /usr/local/bin/influxdb_backup.sh
# Variables
CONTAINER_ID="9a5a75d7773a" # InfluxDB container ID or name; update if changed
BACKUP_FOLDER="/backup/influxdb" # Backup folder inside container
CONTAINER_SHARE="/share/influxdb" # Folder inside container mapped to persistent storage
NAS_MOUNT="/mnt/data/supervisor/mounts/DS220P/influxdb_backup" # NAS mount path on HA OS host
echo "Starting InfluxDB backup process..."
# Step 1: Create backup inside the container
echo "Creating backup inside container..."
docker exec "$CONTAINER_ID" bash -c "mkdir -p $BACKUP_FOLDER && influxd backup -portable $BACKUP_FOLDER"
# Step 2: Copy backup from container to container's share folder for persistence
echo "Copying backup to container share folder..."
docker exec "$CONTAINER_ID" bash -c "rm -rf $CONTAINER_SHARE && cp -r $BACKUP_FOLDER $CONTAINER_SHARE"
# Step 3: Copy backup from container share folder to NAS mounted folder on HA OS host
echo "Copying backup to NAS mount on host..."
docker cp "$CONTAINER_ID":"$CONTAINER_SHARE" "$NAS_MOUNT"
if [ $? -eq 0 ]; then
echo "Backup successfully copied to NAS at $NAS_MOUNT"
else
echo "Failed to copy backup to NAS. Please check paths and permissions."
fi
Restore is similar to that which I still need to be tested but at least backup was saved without any issue. I’ll test the restore of the backup data to another machine influx instance and see if all goes well.
Still have to enforce the home assistance to free up the data as I have set recorder setting to save 30 days of data and auto_purge enabled, disk use is the same but access to data older than 30 days is gone. Though in InfluxDB it is there (as expected, so the emergency to take that influxdb backup). No idea how HA is managing space.
Now, I have access to HA OS, perhaps, I can check what’s going on.
@nitin29
Is the data in the add-on on that one? Otherwise you might need the add-on directory as well. I would add it just to be sure…
That LLM doesn’t know everything…
/addon_configs
BTW… Hope you understand all that shell script stuff when it’s time to restore it…
I don’t see any addon directory inside influxdb container. I’m in the this container (from docker ps) 9937323051f5 ghcr.io/hassio-addons/influxdb/amd64:5.0.2 "/init" 8 hours ago Up 8 hours 0.0.0.0:8086->8086/tcp, [::]:8086->8086/tcp, 0.0.0.0:8088->8088/tcp, [::]:8088->8088/tcp
I thought the data reside inside the influxdb container. Where this add-on directory should be?
I must admit, I don’t understand HA much, the MariaDB shows 110GB but the backup has only 41GB. 180GB is used from total of 250GB something nvme on HA running on Intel NUC. I suppose InfluxDB backup of lots of .tar.gz files is around 6GB from this script as well as HA backup method of that addon but, yes HA created backup has 3 more files.
First InfluxDB tar.gz, I assume it to be a single influxdb tar.gz file instead of split files (shard files) that InfluxDB backup command has created when this script is used. So I assume, if I have to restore it to HA, I need these extra files as in screenshot, for non-HA the backup from the script is fine.
At this point, yes, this script without extra files should not function during restore to HA.
Another issue I found just now that once a entity is renamed inside HA, it is deleted along with its data and new entity as per rename is created but InfluxDB now has two entities. That is bad from HA, maybe I can fetch data from both old and new entities from InfluxDB and merge them as a single entity in InfluxDB or other DB for long term data retention. Need to check both MariaDB and InfluxDB for entity data for some entities. Once all important data is saved, maybe then I can purge MariaDB database and set retention to 7d or something.
And enough headache from HA today. Got viral so I will just take medicine and rest for few days and then do something about data.
Anyway, thank you both very much for important inputs!