InfluxDB in docker - restrictive file permissions

I’m running InfluxDB in a docker container on my server. The problem is, all of the files (database files) created in /var/lib/infludb have very restrictive permissions (-rwx------).

root@9df4d0ab807a:/var/lib/influxdb/data# ls -l
total 1
drwx------ 4 root root 4 May 28 21:38 _internal
drwx------ 4 root root 4 May 28 21:41 home_assistant

The problem with this is that it is non-trivial to write any sort of backup script without giving it root permissions.

Is there a way to get influxdb to write the database files with broader permission? I’ve exhausted my Google-fu (umask, file permissions, …) and have not found an answer.

Stupid question: why would you want to backup a databse relying on filesystem access? Why not simply leverage its own tools to create a stable backup and include that into your scripts?

<smackforehead> I hadn’t even considered that.</smackforehead>


Hi @Juggler , I had the same problem. Can you give a little detail on how you did the backup in the end, without changing the file permissions? @CaptainCrunch says “leverage its own tools” and “include that into your scripts”. What does it refer to exactly?

I use the influxdb backup command to create the backup. Here is my script that is running on the host machine:

juggler@docker:~$ cat 

DAY=$(date +%d)

docker exec influxdb2 influx backup /var/lib/influxdb2/backup -t <root-token>
tar -czvf /hdd12tbpool/encrypted/data/influxdb2/db_backup_$DAY.tar.gz -C /hdd12tbpool/encrypted/data/influxdb2/backup .
rm /hdd12tbpool/encrypted/data/influxdb2/backup/*

The first line creates the backup, the second compresses it and moves it to a directory. The final line cleans the files up.

1 Like

Hi @Juggler , Thank you for providing this, it is very helpful. Forgive my inexperience, but when you say “running on the host machine”, do you mean you have somehow set it up to run periodically?

Yes. I have setup a cron job to run the script I included every evening. I’m running HA and InfluxDB in Docker containers, which is why the script looks the way it does.

1 Like