# Datamigration from InfluxDB to QuestDB with Telegraf

**URL:** <https://community.questdb.com/t/datamigration-from-influxdb-to-questdb-with-telegraf/182>\
**Category:** Community\
**Tags:** question\
**Created:** [September 20, 2024, 5:47pm UTC](https://community.questdb.com/t/datamigration-from-influxdb-to-questdb-with-telegraf/182 "2024-09-20T17:47:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bob3150](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@bob3150](https://community.questdb.com/u/bob3150)\
**Post date:** [September 20, 2024, 5:47pm UTC](https://community.questdb.com/t/datamigration-from-influxdb-to-questdb-with-telegraf/182/1 "2024-09-20T17:47:42Z")

</div>

@javier  
I’m fighting around with data migration from InfluxDB to QuestDB and no way I was discussing with Nick Woolmer was working really well. So he has the idea to contact you for transferring data with Telegraf vom InfluxDB to QuestDB to get the data without errors and in dens format to QuestDB.

---

<div class="post-metadata">

**Author:** ![javier](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/javier/32/29_2.png) [@javier](https://community.questdb.com/u/javier)\
**Post date:** [September 26, 2024, 10:30am UTC](https://community.questdb.com/t/datamigration-from-influxdb-to-questdb-with-telegraf/182/2 "2024-09-26T10:30:10Z")

</div>

Hi,

Sorry I didn’t reply earlier. I was travelling last week for a conference and didn’t notice this.

I have successfully converted from non-dense to dense data using telegraf using an aggregator on telegraf, so metrics with the same timestamp get merged into a single dense row.

I have an example on this repository [GitHub - questdb/opcua-questdb-telegraf: Playground for OPCUA data ingestion into QuestDB using telegraf](https://github.com/questdb/opcua-questdb-telegraf) and on this one [GitHub - javier/questdb-basic-monitoring: Basic questdb monitoring using grafana and collecting questdb metrics via telegraf](https://github.com/javier/questdb-basic-monitoring)

In both I am using the same approach.

In your case, you want to migrate from influx into questdb, so one option is to use telegraf to read from influx and write into questdb. I did that once like this.

## Telegraf.conf file

```auto
[agent]
  omit_hostname = true

# Accept metrics over InfluxDB 2.x HTTP API
[[inputs.influxdb_v2_listener]]
  ## Address and port to host InfluxDB listener on
  ## (Double check the port. Needs to be available)
  service_address = ":8099"

 # Merge metrics into multifield metrics by series key.
[[aggregators.merge]]
 period = "876000h" # Set the period to 100 years (876000 hours)
  grace = "876000h" # Set the grace period to 100 years (876000 hours)
  drop_original = true

# this is the questdb destination
 [[outputs.influxdb_v2]]
  urls = ["http://127.0.0.1:9000"]
  content_encoding = "identity" # Important to ensuring no gzip encoding

```

## Start Telegraf

```auto
telegraf --config sparse_to_dense.conf --debug

```

## Use influxdb2 to export data into the telegraf proxy

In my case, I have a dockerized influx, so I am running this directly from docker.

```auto
docker exec -it influxdb2 influx write --bucket javier --file output.lp --host http://host.docker.internal:8099

```

Hopefully this helps!

---

<div class="post-metadata">

**Author:** ![Armin\_Diehl](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/armin_diehl/32/113_2.png) [@Armin\_Diehl](https://community.questdb.com/u/Armin_Diehl)\
**Post date:** [October 20, 2024, 5:26pm UTC](https://community.questdb.com/t/datamigration-from-influxdb-to-questdb-with-telegraf/182/3 "2024-10-20T17:26:34Z")

</div>

I have tried to migrate my data from influxdb2 using telegraf today. I have more than 1 mio values per month so i had to fiddle with limits and timeouts. Finally it worked by exporting the data per month using a simple script.

my telegraf config

```auto
[agent]
  omit_hostname = true

[[inputs.influxdb_v2_listener]]
  ## Address and port to host InfluxDB listener on
  ## (Double check the port. Needs to be available)
  service_address = ":8099"

[[aggregators.merge]]
 period = "876000h" # Set the period to 100 years (876000 hours)
  grace = "876000h" # Set the grace period to 100 years (876000 hours)
  drop_original = true
  metric_buffer_limit = 2000000

 [[outputs.influxdb_v2]]
  urls = ["http://127.0.0.1:9000"]
  metric_batch_size = 10000
  metric_buffer_limit = 2000000
   timeout = "60s"
  ping_timeout = "30s"
  flush_interval = "99999s"
  content_encoding = "identity" # Important to ensuring no gzip encoding
~                                                                                

```

and the script i used

```auto
!/bin/bash
# copy all data from influxdb2 to questdb using telegraf to transform data in rows
# we have to do it month by month as we have > 140000 values per month and telegraf
# has to perform the transformation in memory
#
# AD 10/2024
# !one time script, no error checking!

if [$"$UID" != "0"]; then
        echo "Influx export requires root"
        exit 1
fi

EP=/mpeg/data/influxdb-2/engine
BID=e1cffc49bb328fea
FN=influx_export

INV="\033[7m"
NOR="\033[0m"
BLD="\033[1m"

for YEAR in 2019 2020 2021 2022 2023 2024; do
        for MONTH in 01 02 03 04 05 06 07 08 09 10 11 12; do
                LASTDAY=$(cal --months=1 1 $MONTH $YEAR | awk 'NF {DAYS = $NF}; END {print DAYS}')
                START=$YEAR-$MONTH-01T00:00:00Z
                END=$YEAR-$MONTH-${LASTDAY}T23:59:59Z
                printf "\n${INV}Exporting $MONTH/$YEAR ($START to $END)${NOR}\n"
                influxd inspect export-lp --bucket-id $BID --engine-path $EP --output-path $FN --start $START --end $END 2>&1
                FILESIZE=$(stat -c%s "$FN")
                #echo "Size of $FN = $FILESIZE bytes."
                if [$FILESIZE -le 1]; then
                        echo "No data for $MONTH/$YEAR"
                else
                        # start telegraf
                        telegraf --config sparse_to_dense.conf --debug &
                        TPID=$!
                        echo "Started telegraf with PID $TPID"
                        sleep 3
                        printf "${BLD}Sending data to telegraf${NORM}\n"
                        influx write --bucket ad --file $FN --host http://localhost:8099
                        printf "${BLD}waiting until telegraf has finished sending data to questdb, pid:${TPID}${NOR}\n"
                        kill $TPID
                        #killall telegraf
                        wait $TPID
                        printf "${BLD}-- end of processing for $MONTH/$YEAR --${NOR}\n"
                fi
        done
done

```

---

<div class="post-metadata">

**Author:** ![Armin\_Diehl](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/armin_diehl/32/113_2.png) [@Armin\_Diehl](https://community.questdb.com/u/Armin_Diehl)\
**Post date:** [October 20, 2024, 9:04pm UTC](https://community.questdb.com/t/datamigration-from-influxdb-to-questdb-with-telegraf/182/4 "2024-10-20T21:04:30Z")

</div>

Btw, the size of the database directory is nearly the same as for InfluxDB V2:  
influxdb-2 4686M  
questdb 4926M

---

<div class="post-metadata">

**Author:** ![javier](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.questdb.com/javier/32/29_2.png) [@javier](https://community.questdb.com/u/javier)\
**Post date:** [October 21, 2024, 8:13am UTC](https://community.questdb.com/t/datamigration-from-influxdb-to-questdb-with-telegraf/182/5 "2024-10-21T08:13:36Z")

</div>

Very cool! Thank you for sharing!!!
