导入/导出数据到/从InfluxDB
项目描述
» 文档 | 变更日志 | PyPI | 问题 | 源代码 | 许可证
关于
您可以使用 influxio 从/到 InfluxDB 导入和导出数据。它可以用作独立程序,也可以用作库。
influxio 基于优秀的 dask, fsspec, influxdb-client, influx-line, line-protocol-parser, pandas,以及 SQLAlchemy 软件包。
请注意,influxio 是 alpha 级别的软件,仍在开发中。非常欢迎各种贡献,以使其更加稳固。在 1.0 版本发布之前,可能会出现破坏性变更,因此建议使用版本锁定,尤其是在将其用作库时。
概述
# Export from API to database.
influxio copy \
"http://example:token@localhost:8086/testdrive/demo" \
"sqlite://export.sqlite?table=demo"
# Export from data directory to line protocol format.
influxio copy \
"file:///path/to/influxdb/engine?bucket-id=372d1908eab801a6&measurement=demo" \
"file://export.lp"
快速入门
如果您急于使用 influxio 而无需安装,只需使用 Podman 或 Docker 上的 OCI 图像即可。
docker run --rm --network=host ghcr.io/daq-tools/influxio \
influxio copy \
"http://example:token@localhost:8086/testdrive/demo" \
"crate://crate@localhost:4200/testdrive/demo"
设置
从 PyPI 安装 influxio。
pip install influxio
用法
本节概述了一些 influxio 的示例调用,包括在命令行和库中使用的情况。除了来自网络的资源外,测试数据还可以从存储库的 testdata 文件夹中获取。
先决条件
要正确运行以下概述的一些示例调用,您需要一个 InfluxDB 和一个 CrateDB 服务器。启动这些实例的最简单方法是使用 Podman 或 Docker。
请访问 docs/development.rst 文档了解如何在您的台式机上启动相应的沙盒实例。
命令行使用
帮助
influxio --help
influxio info
influxio copy --help
导入
将来自不同来源的数据导入 InfluxDB 服务器。
# From test data to API.
# Choose one of dummy, mixed, dateindex, wide.
influxio copy \
"testdata://dateindex/" \
"http://example:token@localhost:8086/testdrive/demo"
# With selected amount of rows.
influxio copy \
"testdata://dateindex/?rows=42" \
"http://example:token@localhost:8086/testdrive/demo"
# With selected amount of rows and columns (only supported by certain test data sources).
influxio copy \
"testdata://wide/?rows=42&columns=42" \
"http://example:token@localhost:8086/testdrive/demo"
# From line protocol file to InfluxDB API.
influxio copy \
"file://tests/testdata/basic.lp" \
"http://example:token@localhost:8086/testdrive/demo"
# From line protocol file to InfluxDB API.
influxio copy \
"https://github.com/influxdata/influxdb2-sample-data/raw/master/air-sensor-data/air-sensor-data.lp" \
"http://example:token@localhost:8086/testdrive/demo"
从 API 导出
将数据从 InfluxDB 服务器导出到不同的目的地。
# From API to database file.
influxio copy \
"http://example:token@localhost:8086/testdrive/demo" \
"sqlite:///export.sqlite?table=demo"
# From API to database server.
influxio copy \
"http://example:token@localhost:8086/testdrive/demo" \
"crate://crate@localhost:4200/testdrive/demo"
# From API to line protocol file.
influxio copy \
"http://example:token@localhost:8086/testdrive/demo" \
"file://export.lp"
# From API to line protocol on stdout.
influxio copy \
"http://example:token@localhost:8086/testdrive/demo" \
"file://-?format=lp"
从文件加载
将 InfluxDB 文件中的数据加载到 SQLAlchemy 支持的任何 SQL 数据库。
# From local line protocol file to SQLite.
influxio copy \
"file://export.lp" \
"sqlite:///export.sqlite?table=export"
# From local line protocol file to CrateDB.
influxio copy \
"file://export.lp" \
"crate://crate@localhost:4200/testdrive/demo"
# From remote line protocol file to SQLite.
influxio copy \
"https://github.com/influxdata/influxdb2-sample-data/raw/master/air-sensor-data/air-sensor-data.lp" \
"sqlite:///export.sqlite?table=air-sensor-data"
# From remote line protocol file to CrateDB.
influxio copy \
"https://github.com/influxdata/influxdb2-sample-data/raw/master/air-sensor-data/air-sensor-data.lp" \
"crate://crate@localhost:4200/testdrive/demo"
从云到云导出
# From InfluxDB Cloud to CrateDB Cloud.
influxio copy \
"https://8e9ec869a91a3517:T268DVLDHD8AJsjzOEluu...Pic4A==@eu-central-1-1.aws.cloud2.influxdata.com/testdrive/demo" \
"crate://admin:dZ,Y18*Z...7)6LqB@green-shaak-ti.eks1.eu-west-1.aws.cratedb.net:4200/testdrive/demo?ssl=true"
crash \
--hosts 'https://admin:dZ,Y18*Z...7)6LqB@green-shaak-ti.eks1.eu-west-1.aws.cratedb.net:4200' \
--command 'SELECT * FROM testdrive.demo;'
从数据目录导出
# From InfluxDB data directory to line protocol file.
influxio copy \
"file:///path/to/influxdb/engine?bucket-id=372d1908eab801a6&measurement=demo" \
"file://export.lp"
# From InfluxDB data directory to line protocol file, compressed with gzip.
influxio copy \
"file:///path/to/influxdb/engine?bucket-id=372d1908eab801a6&measurement=demo" \
"file://export.lp.gz"
# From InfluxDB data directory to line protocol on stdout.
influxio copy \
"file:///path/to/influxdb/engine?bucket-id=372d1908eab801a6&measurement=demo" \
"file://-?format=lp"
OCI
GitHub 容器注册表 (GHCR) 上提供了 OCI 镜像。为了在 Podman 或 Docker 上运行它们,请调用
docker run --rm --network=host ghcr.io/daq-tools/influxio \
influxio copy \
"http://example:token@localhost:8086/testdrive/demo" \
"stdout://export.lp"
如果您想在文件系统上处理文件,您需要使用 --volume 选项将工作目录挂载到容器中,或者使用 --interactive 选项来消耗 STDIN,如下所示
docker run --rm --volume=$(pwd):/data ghcr.io/daq-tools/influxio \
influxio copy "file:///data/export.lp" "sqlite:///data/export.sqlite?table=export"
cat export.lp | \
docker run --rm --interactive --network=host ghcr.io/daq-tools/influxio \
influxio copy "stdin://?format=lp" "crate://crate@localhost:4200/testdrive/export"
为了始终运行最新的 nightly 开发版本,并为此创建快捷方式,本节概述了如何使用 influxio 的别名以及用于存储输入 URL 的变量。这可能在后续调用中节省一些按键。
docker pull ghcr.io/daq-tools/influxio:nightly
alias influxio="docker run --rm --interactive ghcr.io/daq-tools/influxio:nightly influxio"
SOURCE=https://github.com/daq-tools/influxio/raw/main/tests/testdata/basic.lp
TARGET=crate://crate@localhost:4200/testdrive/basic
influxio copy "${SOURCE}" "${TARGET}"
参数
if-exists
当针对 SQLAlchemy 数据库接口时,如果表不存在,则会自动创建目标表。可以使用 if-exists URL 查询参数来配置此行为。默认值是 fail。
fail: 抛出 ValueError。
replace: 在插入新值之前删除表。
append: 将新值插入到现有表中。
示例用法
influxio copy \
"http://example:token@localhost:8086/testdrive/demo" \
"crate://crate@localhost:4200/testdrive/demo?if-exists=replace"
项目信息
开发
要从源代码安装项目,请遵循 开发 文档。
现有技术
还有一些其他项目正在努力实现类似的目标。
项目详细信息
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。
源代码分发
构建分发
influxio-0.5.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | dcb07277f824639e2c4eecb7689d42c7e181690d248f828f276e3cd45172d0eb |
|
MD5 | 2860e1f5b07a3c39df07e9ed3270380e |
|
BLAKE2b-256 | 27619f39961d088e377c45202f600c8bffd8cb94598900109d5f2b830c24dda1 |
influxio-0.5.0-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | cc4b6f9ede5cc533be88401ee0c9779386c73d89cd8736d16d41341f2b73c456 |
|
MD5 | 9772814d971488465b098978224ec174 |
|
BLAKE2b-256 | 40f8df7e1dacf991e095eeaefba07859170159a1e002b4e9337f81f61abc8559 |