macOS ◆ xterm-256color ◆ zsh 4044 views

# 首先,检查 InfluxDB 和 TSDB 是否正常运行
curl -sL -I localhost:8086/ping | grep -i version
curl http://localhost:8242/api/version

# 确认版本是否支持
# InfluxDB 只保证 0.9 及以上版本是兼容的
# TSDB 只保证 2.4.x 及以上版本是兼容的

# 下载
cd /tmp/datax
wget https://tsdbtools.oss-cn-hangzhou.aliyuncs.com/datax_influxdb_2_tsdb.tar.gz
tar zxvf datax_influxdb_2_tsdb.tar.gz

# 配置任务
cd /tmp/datax
cp datax/job/job.json influxdb2tsdb.json
{
  "job": {
    "content": [
      {
        "reader": {
          "name": "influxdbreader",
          "parameter": {
            "endpoint": "http://localhost:8086",
            "database": "yuzhouwan",
            "username": "root",
            "password": "root",
            "column": [
              "blog"
            ],
            "beginDateTime": "2019-05-15T17:00:00Z",
            "endDateTime": "2019-05-15T18:00:00Z"
          }
        },
        "writer": {
          "name": "tsdbwriter",
          "parameter": {
            "endpoint": "http://localhost:8242"
          }
        }
      }
    ],
    "setting": {
      "speed": {
        "channel": 1
      }
    }
  }
}

# 启动之前,确认 InfluxDB 存在数据,而 TSDB 不存在数据
# InfluxDB
influx -host 'localhost' -port '8086'
> use yuzhouwan;
> SELECT * FROM blog WHERE time > '2019-05-15T09:00:00Z' AND time < '2019-05-15T10:00:00Z'

# TSDB
curl -X POST -H "Content-Type: application/json " localhost:8242/api/query -d '{"start":1557849600,"end":1557936000,"queries":[{"aggregator":"count","metric":"blog"}]}'




# 通过 datax.py 脚本启动任务
python datax/bin/datax.py mysql2tsdb.json
# 任务已完成
# 现在,我们来检查是否写入成功
# InfluxDB
influx -host 'localhost' -port '8086'
> use yuzhouwan;
> SELECT * FROM blog WHERE time > '2019-05-15T09:00:00Z' AND time < '2019-05-15T10:00:00Z'

# TSDB
curl -X POST -H "Content-Type: application/json " localhost:8242/api/query -d '{"start":1557849600,"end":1557936000,"queries":[{"aggregator":"count","metric":"blog"}]}'


# 恭喜!
# 数据已成功迁移!