38

Is there a way (plugin or tool) to export the data from the database (or database itself) ? I'm looking for this feature as I need to migrate a DB from present host to another one.

1
  • Does anyone know solution for InfluxDB 3.x? This post is relevant and ranks high, but does not have solution for latest version of InfluxDB. Commented Jun 14 at 7:36

8 Answers 8

43

Export data:

sudo service influxdb start (Or leave this step if service is already running)
influxd backup -database grpcdb /opt/data  

grpcdb is name of DB and back up will be saved under /opt/data directory in this case.

Import Data:

sudo service influxdb stop  (Service should not be running)
influxd restore -metadir /var/lib/influxdb/meta /opt/data
influxd restore -database grpcdb -datadir /var/lib/influxdb/data /opt/data
sudo service influxdb start
Sign up to request clarification or add additional context in comments.

3 Comments

When dealing with massive databases this is really the only practical method to do it.
Yes, assuming the OP is migrating to another InfluxDB host (hopefully of the same version) rather than some other type of database
N.B.1 There is a new (and better) mechanism for backup/restoring data, see docs.influxdata.com/influxdb/v1.7/administration/… N.B.2. After importing data, ensure /var/lib/influxdb is owned by influxdb:influxdb again, i.e. by running sudo chown -R influxdb:influxdb /var/lib/influxdb
22

You could dump each table and load them through REST interface:

curl "http://hosta:8086/db/dbname/series?u=root&p=root&q=select%20*%20from%20series_name%3B" > series_name.json
curl -XPOST -d @series_name.json "http://hostb:8086/db/dbname/series?u=root&p=root"

Or, maybe you want to add new host to cluster? It's easy and you'll get master-master replica for free. Cluster Setup

3 Comments

or alternatively `curl -G 'hosta:8086/query?' --data-urlencode "db=dbname" --data-urlencode "q=SELECT * FROM series_name"
Note that json import of data does not work as of influxdb v0.9 (see github.com/influxdata/influxdb/issues/3174), Ammad's answer works better.
Also note that doing it this way may (and most likely will) timeout during import. At least Influx 1.8 has very strict time limits for these things and you have to do it in batches.
21

From 1.5 onwards, the InfluxDB OSS backup utility provides a newer option which is much more convenient:

-portable: Generates backup files in the newer InfluxDB Enterprise-compatible format. Highly recommended for all InfluxDB OSS users

Export

To back up everything:

influxd backup -portable <path-to-backup>

To backup only the myperf database:

influxd backup -portable -database myperf <path-to-backup>

Import

To restore all databases found within the backup directory:

influxd restore -portable <path-to-backup>

To restore only the myperf database (myperf database must not exist):

influxd restore -portable -db myperf <path-to-backup>

Additional options include specifying timestamp , shard etc. See all the other supported options here.

1 Comment

With newer versions 1.8, 2.x influx_inspect export seems to be a better fit.
20

If I use curl, I get timeouts, and if I use influxd backup its not in a format I can read.

I'm getting fine results like this:

influx -host influxdb.mydomain.com -database primary -format csv -execute "select time,value from \"continuous\" where channel='ch123'" > outtest.csv

Comments

18

As ezotrank says, you can dump each table. There's a missing "-d" in ezotrank's answer though. It should be:

curl "http://hosta:8086/db/dbname/series?u=root&p=root&q=select%20*%20from%20series_name%3B" > series_name.json
curl -XPOST -d @series_name.json "http://hostb:8086/db/dbname/series?u=root&p=root"

(Ezotrank, sorry, I would've just posted a comment directly on your answer, but I don't have enough reputation points to do that yet.)

1 Comment

Can't used in latest version of influxdb.
12

If You want to export in an readable format, the inspect command is to prefer. To export the database with the name HomeData the command is:

sudo influx_inspect export -waldir /var/lib/influxdb/wal -datadir /var/lib/influxdb -out "influx_backup.db" -database HomeData

The parameters for -waldir and -datdir can be found in /etc/influxdb/influxdb.conf.

To import this file again, the command is:

influx -import -path=influx_backup.db

Comments

5

If you have access to the machine running Influx db I would say use the influx_inspect command. The command is simple and very fast. It will dump your db in line protocol. You can then import this dump using influx -import command.

1 Comment

this (both dump and restore) would have to be done individually for each shard, right?
1

I did not see an answer for the influxdb cli v2 in this thread, I came up with the following command to export data from my bucket from the last two weeks into a csv file:

influx query 'from(bucket:"bucket-name") |> range(start:-2w)' --raw > dump_last_two_weeks.csv

If you have got a self-signed certificate and not trusted it (like I did), add --skip-verify to the command (in front of the redirect).

For migrating the influx db there are probably way better options out there, but I stumbled across this question searching for a way to export a bucket as csv, and other answers also described how to do that (for the influx db cli v1).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.