|
| 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 | +- For creating data, use [tutorial_sine_wave.py]. |
| 10 | +- For exporting data, use [influxdb-fetcher]. |
| 11 | +- For importing data, use [influxdb-write-to-postgresql]. |
| 12 | + |
| 13 | +[tutorial_sine_wave.py]: https://github.com/influxdata/influxdb-python/blob/master/examples/tutorial_sine_wave.py |
| 14 | +[influxdb-fetcher]: https://github.com/hgomez/influxdb |
| 15 | +[influxdb-write-to-postgresql]: https://github.com/eras/influxdb-write-to-postgresql |
| 16 | + |
| 17 | + |
| 18 | +# Setup |
| 19 | +```sh |
| 20 | +# Install sine wave generator |
| 21 | +python3 -m venv .venv |
| 22 | +source .venv/bin/activate |
| 23 | +pip install influxdb |
| 24 | +wget https://raw.githubusercontent.com/influxdata/influxdb-python/master/examples/tutorial_sine_wave.py |
| 25 | +# Comment out the line `client.drop_database(DBNAME)` at line 60/61. |
| 26 | + |
| 27 | +# Install InfluxDB Fetcher |
| 28 | +wget --no-clobber --output-document=/usr/local/bin/influxdb-fetcher https://raw.githubusercontent.com/hgomez/influxdb-fetcher/develop/bin/influxdb-fetcher |
| 29 | +chmod +x /usr/local/bin/influxdb-fetcher |
| 30 | + |
| 31 | +# Install iw2pg: Build Docker image |
| 32 | +git clone https://github.com/eras/influxdb-write-to-postgresql |
| 33 | +cd influxdb-write-to-postgresql; docker build --tag iw2pg .; cd .. |
| 34 | +``` |
| 35 | + |
| 36 | + |
| 37 | +# Run with PostgreSQL |
| 38 | +```sh |
| 39 | +# Run databases and iw2pg side by side |
| 40 | +docker run -it --rm --publish 8086:8086 influxdb:1.8.3 |
| 41 | +docker run -it --rm --env "POSTGRES_HOST_AUTH_METHOD=trust" --publish 5432:5432 --name postgresql postgres:13.1 |
| 42 | +docker run -it --rm --publish 8087:8086 --link postgresql --volume $PWD/iw2pg-config-postgresql.yaml:/app/config.yaml iw2pg --verbosity=info |
| 43 | + |
| 44 | +# Create data |
| 45 | +python tutorial_sine_wave.py |
| 46 | + |
| 47 | +# Export data |
| 48 | +influxdb-fetcher http://localhost:8086 root root tutorial "SELECT * FROM foobar" > foobar.wireproto |
| 49 | + |
| 50 | +# Import data |
| 51 | +psql postgres://postgres:postgres@localhost --command='CREATE DATABASE tutorial;' |
| 52 | +cat foobar.wireproto | http http://localhost:8087/write?db=tutorial |
| 53 | + |
| 54 | +# Verify data |
| 55 | +psql postgres://postgres:postgres@localhost/tutorial --command='SELECT * FROM foobar;' |
| 56 | +``` |
| 57 | + |
| 58 | +# Run with CrateDB |
| 59 | +```sh |
| 60 | +# Run databases and iw2pg side by side |
| 61 | +docker run -it --rm --publish 8086:8086 influxdb:1.8.3 |
| 62 | +docker run -it --rm --publish 5432:5432 --name cratedb crate/crate:nightly |
| 63 | +docker run -it --rm --publish 8087:8086 --link cratedb --volume $PWD/iw2pg-config-cratedb.yaml:/app/config.yaml iw2pg --verbosity=info |
| 64 | + |
| 65 | +# Create data |
| 66 | +python tutorial_sine_wave.py |
| 67 | + |
| 68 | +# Export data |
| 69 | +influxdb-fetcher http://localhost:8086 root root tutorial "SELECT * FROM foobar" > foobar.wireproto |
| 70 | + |
| 71 | +# Import data |
| 72 | +cat foobar.wireproto | http http://localhost:8087/write?db=tutorial |
| 73 | +``` |
| 74 | + |
| 75 | + |
| 76 | +## Bummer |
| 77 | +```text |
| 78 | +Result status PGRES_FATAL_ERROR unexpected (expected status:PGRES_TUPLES_OK); ERROR: Relation 'pg_indexes' unknown |
| 79 | +``` |
0 commit comments