0、导
业务上有使用influxdb收集一些数据,想要看一下日数据增量大概多少,但是没找到什么有效的手段能够直接看到日数据增量
思索了一下选择了曲线救国的方法,
从influxdb中导出某些时间段的日数据,以此达到估算日数据增量的目的
1、壹
对influxdb不是很熟悉,从参考一看到可以使用
influx_inspect export
命令将数据导出到指定目录
# 执行时间为 9.26 日
influx_inspect export \
-datadir "/var/lib/influxdb/data" \
-waldir "/var/lib/influxdb/wal" \
-out " temporary_influxdb_data " \
-database telegraf \
-start 2021-09-25T08:00:01Z
influx_inspect export
-datadir "XXXXX" # influxdb 默认的数据存储位置
-waldir "XXXXX" # influxdb 默认的数据交换位置
-out "XXXXX" # 导出数据文件的文件名
-database XXXXX # 指定要导出数据的数据库
-start 2021-09-25T08:00:01Z # 指定要导出的数据的起始时间
执行该命令导出 9.25-9.26 的数据足足有 5G ,按理说数据量应该达不到这么大,于是又根据参考二使用了另一个命令
influxd backup
# influxd backup -h
Creates a backup copy of specified InfluxDB OSS database(s) and saves the files in an Enterprise-compatible
format to PATH (directory where backups are saved).
Usage: influxd backup [options] PATH
-portable # 以较新的InfluxDB Enterprise兼容格式生成备份文件。强烈建议所有InfluxDB OSS用户使用。
Required to generate backup files in a portable format that can be restored to InfluxDB OSS or InfluxDB
Enterprise. Use unless the legacy backup is required.
-host <host:port> # InfluxDB OSS实例的主机和端口。默认值为'127.0.0.1:8088'。远程连接所必需。例:-host 127.0.0.1:8088
InfluxDB OSS host to back up from. Optional. Defaults to 127.0.0.1:8088.
-db <name> # 要备份的数据库。如果未指定,则备份所有数据库。
InfluxDB OSS database name to back up. Optional. If not specified, all databases are backed up when
using '-portable'.
-rp <name> # 备份的保留策略。如果未指定,则默认为使用所有保留策略。如果指定,则需要使用 -database 指定数据库实例。
Retention policy to use for the backup. Optional. If not specified, all retention policies are used by
default.
-shard <id> # 要备份的分片的分片ID。如果指定,-retention <name> 则为必需。
The identifier of the shard to back up. Optional. If specified, '-rp <rp_name>' is required.
-start <2015-12-24T08:12:23Z>
# 设置备份数据的时间起点(RFC3339格式),不兼容-since。例:-start 2015-12-24T08:12:23Z
Include all points starting with specified timestamp (RFC3339 format).
Not compatible with '-since <timestamp>'.
-end <2015-12-24T08:12:23Z>
# 排除指定时间戳记(RFC3339格式)之后的所有结果,不兼容-since。如果不使用-start,则将从1970-01-01开始备份所有数据。例:-end 2015-12-31T08:12:23Z
Exclude all points after timestamp (RFC3339 format).
Not compatible with '-since <timestamp>'.
-since <2015-12-24T08:12:23Z>
# 在指定的时间戳记RFC3339格式之后执行增量备份。-start除非有旧版备份支持,否则请改用。建议使用 -start 参数。
Create an incremental backup of all points after the timestamp (RFC3339 format). Optional.
Recommend using '-start <timestamp>' instead.
-skip-errors # 跳过备份过程中发生的错误。
Optional flag to continue backing up the remaining shards when the current shard fails to backup.
influxd backup -portable -db xxxxx -start 2021-09-26T11:01:23Z -end 2021-09-27T11:01:23Z /tmp 1>/dev/null
#
执行 backup 命令会生成一定的数据,并且创建保存到指定的目录中。
如图所示:.meta文件是 metastore 副本数据,包涵用户名和密码
.tar.gz文件是分片副本数据
.manifest文件是json格式的,用于描述收集的备份数据内容说明
如上图所示,数据量大的时候压缩包也就500多MBit的数据量,实测解压后也就接近1GiB的数据。
3、对比
influx_inspect export
、influxd backup
对比之下,数据量一下少了3、4个G,主要还是不熟悉,所以我猜测可能多出来的那一部分是wal的数据,于是参考三、参考四知道了大概wal存的是什么数据。
参考:
1、https://blog.csdn.net/qq_40692113/article/details/96907645
2、https://juejin.cn/post/6844904193061289997#heading-11
3、https://blog.fatedier.com/2016/08/05/detailed-in-influxdb-tsm-storage-engine-one/
4、https://zhuanlan.zhihu.com/p/104349911
5、https://www.modb.pro/db/107200