Skip to content

Commit dec72ed

Browse files
committed
Add tutorial for exporting data from InfluxDB and importing into CrateDB
1 parent dffe8c8 commit dec72ed

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

spikes/influxdb-to-cratedb/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.venv*
2+
*.wireproto
3+
*.py
4+
influxdb-write-to-postgresql

spikes/influxdb-to-cratedb/README.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# About
2+
Tutorial about migrating data from InfluxDB to CrateDB.
3+
4+
# Status
5+
This is a work in progress.
6+
7+
# Plan
8+
9+
- Create data
10+
https://github.com/influxdata/influxdb-python/blob/master/examples/tutorial_sine_wave.py
11+
12+
- Export data
13+
https://github.com/daq-tools/influxdb-fetcher
14+
15+
- Import data
16+
https://github.com/eras/influxdb-write-to-postgresql
17+
18+
19+
# Setup
20+
```sh
21+
# Install sine wave generator
22+
python3 -m venv .venv
23+
source .venv/bin/activate
24+
pip install influxdb
25+
wget https://raw.githubusercontent.com/influxdata/influxdb-python/master/examples/tutorial_sine_wave.py
26+
# Comment out the line `client.drop_database(DBNAME)` at line 60/61.
27+
28+
# Install InfluxDB Fetcher
29+
wget --no-clobber --output-document=/usr/local/bin/influxdb-fetcher https://raw.githubusercontent.com/daq-tools/influxdb-fetcher/develop/bin/influxdb-fetcher
30+
chmod +x /usr/local/bin/influxdb-fetcher
31+
32+
# Install iw2pg: Build Docker image
33+
git clone https://github.com/eras/influxdb-write-to-postgresql
34+
cd influxdb-write-to-postgresql; docker build --tag iw2pg .; cd ..
35+
```
36+
37+
38+
# Run with PostgreSQL
39+
```sh
40+
# Run databases and iw2pg side by side
41+
docker run -it --rm --publish 8086:8086 influxdb:1.8.3
42+
docker run -it --rm --env "POSTGRES_HOST_AUTH_METHOD=trust" --publish 5432:5432 --name postgresql postgres:13.1
43+
docker run -it --rm --publish 8087:8086 --link postgresql --volume $PWD/iw2pg-config-postgresql.yaml:/app/config.yaml iw2pg --verbosity=info
44+
45+
# Create data
46+
python tutorial_sine_wave.py
47+
48+
# Export data
49+
influxdb-fetcher http://localhost:8086 root root tutorial "SELECT * FROM foobar" > foobar.wireproto
50+
51+
# Import data
52+
psql postgres://postgres:postgres@localhost --command='CREATE DATABASE tutorial;'
53+
cat foobar.wireproto | http http://localhost:8087/write?db=tutorial
54+
55+
# Verify data
56+
psql postgres://postgres:postgres@localhost/tutorial --command='SELECT * FROM foobar;'
57+
```
58+
59+
# Run with CrateDB
60+
```sh
61+
# Run databases and iw2pg side by side
62+
docker run -it --rm --publish 8086:8086 influxdb:1.8.3
63+
docker run -it --rm --publish 5432:5432 --name cratedb crate/crate:nightly
64+
docker run -it --rm --publish 8087:8086 --link cratedb --volume $PWD/iw2pg-config-cratedb.yaml:/app/config.yaml iw2pg --verbosity=info
65+
66+
# Create data
67+
python tutorial_sine_wave.py
68+
69+
# Export data
70+
influxdb-fetcher http://localhost:8086 root root tutorial "SELECT * FROM foobar" > foobar.wireproto
71+
72+
# Import data
73+
cat foobar.wireproto | http http://localhost:8087/write?db=tutorial
74+
```
75+
76+
77+
## Bummer
78+
```text
79+
Result status PGRES_FATAL_ERROR unexpected (expected status:PGRES_TUPLES_OK); ERROR: Relation 'pg_indexes' unknown
80+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
databases:
2+
tutorial:
3+
db_host: cratedb
4+
db_port: 5432
5+
db_name: tutorial
6+
db_user: crate
7+
db_password: crate
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
databases:
2+
tutorial:
3+
db_host: postgresql
4+
db_port: 5432
5+
db_name: tutorial
6+
db_user: postgres
7+
db_password: postgres
8+
9+
#create_table:
10+
# regexp: /.+/
11+
# method: create_table
12+
13+
fields_jsonb_column: null
14+
tags_jsonb_column: null
15+
16+
#field_columns:
17+
# - value
18+
# - field2

0 commit comments

Comments
 (0)