Documentation

在InfluxDB Cloud 组织之间迁移数据

要将数据从一个 InfluxDB Cloud 组织迁移到另一个组织,请根据时间批次查询数据,并将查询到的数据写入另一个 InfluxDB Cloud 组织的存储桶中。由于完整的数据迁移可能会超出您组织的限制和可调整的配额,因此请分批迁移您的数据。

以下指南提供了在InfluxDB中设置任务的说明,该任务以基于时间的批次从InfluxDB Cloud存储桶查询数据,并将每个批次写入另一个组织的另一个InfluxDB Cloud存储桶。

所有查询和写入请求都受限于您 InfluxDB Cloud 组织的 速率限制和可调整配额

设置迁移

迁移过程需要在您的目标 InfluxDB 组织中创建两个存储桶——一个用于存储迁移的数据,另一个用于存储迁移元数据。如果目标组织使用 InfluxDB Cloud Free Plan,那么除了这两个存储桶之外的任何存储桶将超过您计划的存储桶限制。

  1. 在您要迁移数据的 InfluxDB Cloud 组织中 , 创建一个 API 令牌 具有读取访问权限到您想要迁移的桶。

  2. 在您正在迁移数据的 InfluxDB Cloud 组织中 :

    1. 源组织的 InfluxDB Cloud API 令牌 作为秘密使用密钥 INFLUXDB_CLOUD_TOKEN 添加。

      有关更多信息,请参见 添加秘密
    2. 创建一个桶 以迁移数据到.

    3. 创建一个桶 用于存储临时迁移元数据

    4. 创建一个新任务 使用提供的 迁移任务。 更新必要的 迁移配置选项

    5. (可选) 设置迁移监控

    6. 保存任务。

      新创建的任务默认启用,因此当您保存任务时,数据迁移开始。

迁移完成后,每个后续的迁移任务执行将失败,并出现以下错误:

error exhausting result iterator: error calling function "die" @41:9-41:86:
Batch range is beyond the migration range. Migration is complete.

迁移任务

配置迁移

  1. 指定您希望任务运行的频率,使用 task.every 选项。 请参见 确定您的任务间隔

  2. migration record 中定义以下属性:

    迁移
    • start: 包含在迁移中的最早时间。 参见 确定您的迁移开始时间.
    • stop: 迁移中要包含的最新时间。
    • batchInterval: 每个基于时间的批次的持续时间。 查看 确定你的批次间隔
    • batchBucket: InfluxDB 桶,用于存储迁移批次元数据。
    • sourceHost: InfluxDB Cloud 区域 URL 以迁移数据。
    • sourceOrg: 要从中迁移数据的 InfluxDB Cloud 组织。
    • sourceToken: InfluxDB Cloud API 令牌。为保持 API 令牌的安全,应该将其作为秘密存储在 InfluxDB OSS 中。
    • sourceBucket: 从中迁移数据的InfluxDB Cloud桶。
    • destinationBucket: 要迁移数据的 InfluxDB OSS 存储桶。

迁移 Flux 脚本

import "array"
import "experimental"
import "influxdata/influxdb/secrets"

// Configure the task
option task = {every: 5m, name: "Migrate data from InfluxDB Cloud"}

// Configure the migration
migration = {
    start: 2022-01-01T00:00:00Z,
    stop: 2022-02-01T00:00:00Z,
    batchInterval: 1h,
    batchBucket: "migration",
    sourceHost: "https://cloud2.influxdata.com",
    sourceOrg: "example-cloud-org",
    sourceToken: secrets.get(key: "INFLUXDB_CLOUD_TOKEN"),
    sourceBucket: "example-cloud-bucket",
    destinationBucket: "example-oss-bucket",
}

// batchRange dynamically returns a record with start and stop properties for
// the current batch. It queries migration metadata stored in the
// `migration.batchBucket` to determine the stop time of the previous batch.
// It uses the previous stop time as the new start time for the current batch
// and adds the `migration.batchInterval` to determine the current batch stop time.
batchRange = () => {
    _lastBatchStop =
        (from(bucket: migration.batchBucket)
            |> range(start: migration.start)
            |> filter(fn: (r) => r._field == "batch_stop")
            |> filter(fn: (r) => r.srcOrg == migration.sourceOrg)
            |> filter(fn: (r) => r.srcBucket == migration.sourceBucket)
            |> last()
            |> findRecord(fn: (key) => true, idx: 0))._value
    _batchStart =
        if exists _lastBatchStop then
            time(v: _lastBatchStop)
        else
            migration.start

    return {start: _batchStart, stop: experimental.addDuration(d: migration.batchInterval, to: _batchStart)}
}

// Define a static record with batch start and stop time properties
batch = {start: batchRange().start, stop: batchRange().stop}

// Check to see if the current batch start time is beyond the migration.stop
// time and exit with an error if it is.
finished =
    if batch.start >= migration.stop then
        die(msg: "Batch range is beyond the migration range. Migration is complete.")
    else
        "Migration in progress"

// Query all data from the specified source bucket within the batch-defined time
// range. To limit migrated data by measurement, tag, or field, add a `filter()`
// function after `range()` with the appropriate predicate fn.
data = () =>
    from(host: migration.sourceHost, org: migration.sourceOrg, token: migration.sourceToken, bucket: migration.sourceBucket)
        |> range(start: batch.start, stop: batch.stop)

// rowCount is a stream of tables that contains the number of rows returned in
// the batch and is used to generate batch metadata.
rowCount =
    data()
        |> count()
        |> group(columns: ["_start", "_stop"])
        |> sum()

// emptyRange is a stream of tables that acts as filler data if the batch is
// empty. This is used to generate batch metadata for empty batches and is
// necessary to correctly increment the time range for the next batch.
emptyRange = array.from(rows: [{_start: batch.start, _stop: batch.stop, _value: 0}])

// metadata returns a stream of tables representing batch metadata.
metadata = () => {
    _input =
        if exists (rowCount |> findRecord(fn: (key) => true, idx: 0))._value then
            rowCount
        else
            emptyRange

    return
        _input
            |> map(
                fn: (r) =>
                    ({
                        _time: now(),
                        _measurement: "batches",
                        srcOrg: migration.sourceOrg,
                        srcBucket: migration.sourceBucket,
                        dstBucket: migration.destinationBucket,
                        batch_start: string(v: batch.start),
                        batch_stop: string(v: batch.stop),
                        rows: r._value,
                        percent_complete:
                            float(v: int(v: r._stop) - int(v: migration.start)) / float(
                                    v: int(v: migration.stop) - int(v: migration.start),
                                ) * 100.0,
                    }),
            )
            |> group(columns: ["_measurement", "srcOrg", "srcBucket", "dstBucket"])
}

// Write the queried data to the specified InfluxDB OSS bucket.
data()
    |> to(bucket: migration.destinationBucket)

// Generate and store batch metadata in the migration.batchBucket.
metadata()
    |> experimental.to(bucket: migration.batchBucket)

配置帮助

确定您的任务间隔

确定您的迁移开始时间

确定您的批处理间隔

监控迁移进度

InfluxDB Cloud Migration Community template 安装本指南中列出的迁移任务以及一个用于监控运行数据迁移的仪表板。

InfluxDB Cloud migration dashboard

安装 InfluxDB Cloud 迁移模板

排查迁移任务失败

如果迁移任务失败,查看您的任务日志以识别具体错误。以下是迁移任务失败的常见原因。

超出速率限制

如果您的数据迁移导致您超出 InfluxDB Cloud 组织的限制和配额,该任务将返回类似于以下的错误:

too many requests

可能的解决方案:

  • 更新您的迁移任务中的 migration.batchInterval 设置,以使用更小的间隔。每个批次将查询更少的数据。

无效的API令牌

如果您添加的 API 令牌作为 INFLUXDB_CLOUD_SECRET 没有读取您 InfluxDB Cloud 存储桶的权限,则任务将返回类似以下的错误:

unauthorized access

可能的解决方案:

  • 确保API令牌对您的InfluxDB Cloud存储桶具有读取权限。
  • 生成一个新的 InfluxDB Cloud API 令牌,具备对您要迁移的存储桶的读取权限。然后,使用新的令牌更新您 InfluxDB OSS 实例中的 INFLUXDB_CLOUD_TOKEN 秘密。

查询超时

InfluxDB Cloud 查询超时时间为 90 秒。如果从批处理间隔返回数据所花费的时间超过此时间,查询将超时,任务将失败。

可能的解决方案:

  • 在你的迁移任务中更新 migration.batchInterval 设置,以使用更小的时间间隔。每个批次将查询更少的数据,并花费更少的时间返回结果。

批量大小太大

如果您的批处理大小太大,任务将返回类似于以下的错误:

internal error: error calling function "metadata" @97:1-97:11: error calling function "findRecord" @67:32-67:69: wrong number of fields

可能的解决方案:

  • 在您的迁移任务中更新migration.batchInterval设置,使用更小的间隔并每个批次检索更少的数据。

迁移到 InfluxDB 云无服务器

要解锁InfluxDB 3存储引擎的好处,包括无限基数和SQL,将您的数据迁移到InfluxDB Cloud Serverless组织

所有通过 cloud2.influxdata.com 创建的 InfluxDB Cloud 账户组织,在2023年1月31日及之后,均在 InfluxDB Cloud Serverless 上,并由 InfluxDB 3 存储引擎提供支持。

要查看您的组织使用哪个存储引擎,请在您的 InfluxDB Cloud 组织主页 版本信息中找到 由 InfluxDB Cloud 提供支持的 链接。如果您的组织使用 TSM,您会看到 TSM 后面跟着版本号。如果是 Serverless,您会看到 InfluxDB Cloud Serverless 后面跟着版本号。



Flux的未来

Flux 正在进入维护模式。您可以像现在一样继续使用它,而无需对您的代码进行任何更改。

阅读更多

InfluxDB 3 开源版本现已公开Alpha测试

InfluxDB 3 Open Source is now available for alpha testing, licensed under MIT or Apache 2 licensing.

我们将发布两个产品作为测试版的一部分。

InfluxDB 3 核心,是我们新的开源产品。 它是一个用于时间序列和事件数据的实时数据引擎。 InfluxDB 3 企业版是建立在核心基础之上的商业版本,增加了历史查询能力、读取副本、高可用性、可扩展性和细粒度安全性。

有关如何开始的更多信息,请查看:

由TSM驱动的InfluxDB Cloud