As I was about to merge two influx databases into one, I was surprised that one could not use the CLI influx to both import and export data.

export influx measurement

To export data from a influx database I used the following command: influx -database home -format csv -execute "select * from temperature" > /tmp/temperature.csv The measurement temperature from database home is exported and saved into a CSV file.

import fails

My attempt to import the data as follows failed: influx -database private -format csv -path /tmp/temperature.csv -import 2018/02/17 12:33:03 error writing batch: {"error":"unable to parse ' ... ERROR: 11397 points were not inserted I did not RTFM but instead guessed the command/parameter combination which I thought would be reasonable. How naive I was!

formatting for the import

Turns out, the data has to be formatted like a normal insert; e.g.: temperature,sensor=livingroom temperature=21 One has to convert the data from the CSV export to be able to import it again …

alternative scripts

I found several scripts on github which all convert CSV files to influx. But those where all written in programming languagues which I neither had installed nor knew (as in “created at least 10 scripts in that language”). I was looking for a Bash script but couldn’t find any. And writing Bash scripts is not fun for me. Thus I wrote the PowerShell script ConvertTo-Influxdb.

running ConvertTo-Influx.ps1

Converting a CSV file into one which can be imported using the influx CLI goes like this: ConvertTo-Influx.ps1 -Path /tmp/temperature.csv -Database private > /tmp/temperature.influx The script takes two parameters (both mandatory): Path: the path to the CSV file Database: the database name you want the data to be imported to

import data into influx database

Once converted the data can be imported using the influx CLI: influx -path /tmp/temperature.influx -import