influx CLI修改数据保存策略时间
第一步:下载influx CLI
Download the influx CLI package.
https://docs.influxdata.com/influxdb/v2/tools/influx-cli/?t=Windows
第二步:设置influx CLI
F:\tools\influxdb2-client-2.7.5-windows-amd64> influx config create --config-name config --host-url http://localhost:8086 --org myorg --token 34j18h5hZFVE27FinsZ9rQVBka62EnnmEHL_6Lp0rzQ_IHgZavMthFAKgVrA05RsHXNQO0Ozlr3lF3ubDoCT4Q== --active
第三步:修改保留策略时间
-- 列出所有的buckets
influx bucket list
F:\tools\influxdb2-client-2.7.5-windows-amd64>influx bucket list
ID Name Retention Shard group duration Organization ID Schema Type
069af8ca95cb6687 smaple infinite 168h0m0s a17eb7759879d6e0 implicit
-- 修改保留策略为最近两年(730d)
influx bucket update --id <bucket-id> --retention 730d
如果你是在生产环境中操作,请务必小心,因为更改保留策略可能导致数据丢失。
扩展:influx CLI常用命令
管理buckets
-- 列出所有的buckets
influx bucket list
F:\tools\influxdb2-client-2.7.5-windows-amd64>influx bucket list
ID Name Retention Shard group duration Organization ID Schema Type
069af8ca95cb6687 smaple infinite 168h0m0s a17eb7759879d6e0 implicit
这里每一列代表的信息如下:
ID: Bucket 的唯一标识符。
Name: Bucket 名称。
Retention: 数据保留期限,infinite:永久。
Shard group duration: 分片组持续时间。
Organization ID: 组织 ID。
-- 创建一个新的bucket
influx bucket create -n new-bucket-name -r 7d -o your-org-name
-n 或 --name: 新 bucket 的名字。
-r 或 --retention: 数据保留时间,如 7d 表示 7 天。
-o 或 --org: 组织名。
管理org和user
-- 列出所有的组织
influx org list
-- 创建一个新组织
influx org create -n new-org-name
-- 列出所有的用户
influx user list
-- 创建一个新用户
influx user create -n new-user-name -p password -o your-org-name
查看和设置配置
-- 查看当前配置
influx config ls
-- 设置新的配置文件
influx config create -n my-config -u http://localhost:8086 -t my-token -o my-org
导入和导出数据
从文件导入数据
influx query -f import.flux
导出数据到文件
influx query 'from(bucket::"example-bucket") |> range(start: -1h)' >output.txt
其它命令
-- 显示帮助信息
influx query -h
-- 查看版本号
influx version
Influx CLI v2.7.5 (git: a79a2a1b825867421d320428538f76a4c90aa34c) build_date: 2024-04-16T14:35:09Z