Backup and restore influxdb inside Docker

A few people have had trouble using backup and restore of influxdb inside Docker, so I wrote a small script demonstrating how to back up and restore a database, in this gist. If you’ve had trouble with backup and restore inside Docker, you should be able to use that script as a reference to make backup and restore work in your setup.

Some of the issues people are running into include:

  • Trying to run influxd restore without stopping the influxd process
  • General difficulties around influxdb inside Docker, particularly:
    • Stopping the influxd process which kills the container
    • Needing to restore into a volume from an ephemeral container

We’re looking into how to make this workflow easier. Right now, it seems like the most user-friendly answer will be to allow influxd restore to run correctly without stopping the influxd process, but we are still considering whether any other approaches make sense.

3 Likes

Hi, I have the same problem.

I need to backup the influxdb from another docker container running a NodeJS application that uses data stored in influxdb and has also backup/restore functionalities. To be able to use influx cli commands inside this container I have installed influx there too but it is not started, this way I can use the influx backup command.

I have just added this lines to my nodejs container Dockerfile:

ENV INFLUXDB_VERSION 1.5.4
RUN set -ex && \
    apk add --no-cache --virtual .build-deps wget gnupg tar ca-certificates && \
    update-ca-certificates && \
    for key in \
        05CE15085FC09D18E99EFB22684A14CF2582E0C5 ; \
    do \
        gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" || \
        gpg --keyserver pgp.mit.edu --recv-keys "$key" || \
        gpg --keyserver keyserver.pgp.com --recv-keys "$key" ; \
    done && \
    wget --no-verbose https://dl.influxdata.com/influxdb/releases/influxdb-${INFLUXDB_VERSION}-static_linux_amd64.tar.gz.asc && \
    wget --no-verbose https://dl.influxdata.com/influxdb/releases/influxdb-${INFLUXDB_VERSION}-static_linux_amd64.tar.gz && \
    gpg --batch --verify influxdb-${INFLUXDB_VERSION}-static_linux_amd64.tar.gz.asc influxdb-${INFLUXDB_VERSION}-static_linux_amd64.tar.gz && \
    mkdir -p /usr/src && \
    tar -C /usr/src -xzf influxdb-${INFLUXDB_VERSION}-static_linux_amd64.tar.gz && \
    #copy just influx executable
    chmod +x /usr/src/influxdb-*/influxd && \
    cp -a /usr/src/influxdb-*/influxd /usr/bin/ && \
    rm -rf *.tar.gz* /usr/src /root/.gnupg && \
    apk del .build-deps

I can connect to InfluxDB correctly:

bash-4.4# influx -host influxdb
Connected to http://influxdb:8086 version 1.6.4
InfluxDB shell version: 1.5.4

But when I try to run the backup:

influxd backup -portable -host influxdb:8088 -retention autogen -database myDatabase ./

I’m getting this response:

2018/11/05 15:15:48 backing up metastore to meta.00
2018/11/05 15:15:48 Download shard 0 failed dial tcp 172.19.0.3:8088: getsockopt: connection refused.  Waiting 2s and retrying (0)...
2018/11/05 15:15:50 Download shard 0 failed dial tcp 172.19.0.3:8088: getsockopt: connection refused.  Waiting 2s and retrying (1)...
2018/11/05 15:15:52 Download shard 0 failed dial tcp 172.19.0.3:8088: getsockopt: connection refused.  Waiting 2s and retrying (2)...
2018/11/05 15:15:54 Download shard 0 failed dial tcp 172.19.0.3:8088: getsockopt: connection refused.  Waiting 2s and retrying (3)...

I don’t undestand why but seems the port 8088 is not exposed, I have also tried to expose it in docker-compose but nothing works. Any ideas?