Migrate InfluxDB databases to Docker

I have plenty of machine which running on old ways of Virtual Machine. Recently i’m interested to looking for a simpler, more automated approach to installation rather than install one by one each machine.

Currently i would like to migrate 1 set of Grafana, Influxdb, Prometheus to Docker. I will post more detail about docker later, but for this article i would like to write more specific to migrate from InfluxDB database to Docker.

InfluxDB Databases

First, let’s take a look at the InfluxDB databases. In this example, we are using version 1.8.10, and we have two databases that we want to back up: telegraf and librenms.

To see a list of the available databases, run the following command in the InfluxDB shell:

# influx -host -port 8086
Connected to version 1.8.10
InfluxDB shell version: 1.8.10
name: databases
> exit

Backup Databases

Once we’ve identified the databases that want to back up, run the following commands:

# influxd backup -portable -database telegraf ./influxdb-backup/telegraf
# influxd backup -portable -database librenms ./influxdb-backup/librenms

These commands will create portable backups of the databases in the specified directories. After required database backed up, then we can copy the directory using scp to destined docker host.

scp -r /root/influxdb-backup/ root@destination_docker_host:/home/

Restoring Databases

I have built several service related grafana monitoring using docker compose to provision these container.

    image: influxdb:1.8.10
    container_name: influxdb
      - "8086:8086"
      - /opt/appdata/influxdb:/var/lib/influxdb
    restart: unless-stopped

After container up then we stop the services using docker stop influxdb. Then we create intermediate container that maps the data volume and our backup directory and then enter the container’s shell:

# docker run --rm --detach -v /opt/appdata/influxdb:/var/lib/influxdb -v /home/influxdb-backup/:/backups -p 8086 influxdb:1.8.10
# docker exec -it blissful_cori /bin/bash
root@b87c1e0dcfbd:/# influxd version
InfluxDB v1.8.10 (git: 1.8 688e697c51fd)
# influxd restore -portable -database telegraf /backups/telegraf
# influxd restore -portable -database librenms /backups/librenms
# exit

Then stop intermediate container and remove then start influxdb container.

docker stop blissful_cori

Now you can log in to the InfluxDB console and verify that the databases have been restored:

root@bb0711aa705e:/# influx -host -port 8086
Connected to version 1.8.10
InfluxDB shell version: 1.8.10
name: databases

Note that you should also check the InfluxDB version on the existing and new systems to ensure compatibility.

References :


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.