乐趣区

关于influxdb:InfluxDB-数据的导入导出

influxdb 反对将时序数据导出到文件,而后再将文件导入到数据库中,以此实现数据的迁徙。

导出

导出命令的语法格局:

# influx_inspect export --help
Exports TSM files into InfluxDB line protocol format.

Usage: influx_inspect export [flags]
  -compress
        Compress the output
  -database string
        Optional: the database to export
  -datadir string
        Data storage path (default "/root/.influxdb/data")
  -end string
        Optional: the end time to export (RFC3339 format)
  -out string
        Destination file to export to (default "/root/.influxdb/export")
  -retention string
        Optional: the retention policy to export (requires -database)
  -start string
        Optional: the start time to export (RFC3339 format)
  -waldir string
        WAL storage path (default "/root/.influxdb/wal")

数据导出 demo:

influx_inspect export -datadir "/var/lib/influxdb/data" -waldir "/var/lib/influxdb/wal" -out "influxdb_dump_out" -database "opsultra" -start "2021-09-10T00:00:00Z"
其中:datadir: influxdb 的数据寄存地位
  waldir: influxdb 的 wal 目录
  out: 输入文件
  database: 导出的 db 名称
  start: 从什么工夫导出 

导入

导入的命令语法:

# influx -import --help
Usage of influx:
  -version
       Display the version and exit.
  -host 'host name'
       Host to connect to.
  -port 'port #'
       Port to connect to.
  -socket 'unix domain socket'
       Unix socket to connect to.
  -database 'database name'
       Database to connect to the server.
  -password 'password'
      Password to connect to the server.  Leaving blank will prompt for password (--password '').
  -username 'username'
       Username to connect to the server.
  -ssl
        Use https for requests.
  -unsafeSsl
        Set this when connecting to the cluster using https and not use SSL verification.
  -execute 'command'
       Execute command and quit.
  -format 'json|csv|column'
       Format specifies the format of the server responses:  json, csv, or column.
  -precision 'rfc3339|h|m|s|ms|u|ns'
       Precision specifies the format of the timestamp:  rfc3339, h, m, s, ms, u or ns.
  -consistency 'any|one|quorum|all'
       Set write consistency level: any, one, quorum, or all
  -pretty
       Turns on pretty print for the json format.
  -import
       Import a previous database export from file
  -pps
       How many points per second the import will allow.  By default it is zero and will not throttle importing.
  -path
       Path to file to import
  -compressed
       Set to true if the import file is compressed

Examples:
    # Use influx in a non-interactive mode to query the database "metrics" and pretty print json:
    $ influx -database 'metrics' -execute 'select * from cpu' -format 'json' -pretty

    # Connect to a specific database on startup and set database context:
    $ influx -database 'metrics' -host 'localhost' -port '8086'

将下面导出的文件导入:

# influx -import -path=/root/influxdb_dump_out -precision=ns

其中:import: 标识导入
  path: 导入文件
  precision: 导入的数据工夫精度 
退出移动版