InfluxDB数据备份与恢复
InfluxDB数据备份与恢复
一、基本命令
命令:influxd backup -database dbName backup_path
可选参数:
-retention <retention policy name>
-shard <shard ID>
-since <date>
参数解析:
retention:This flag can be used to backup a specific retention policy. For more information on retention policies, please see here. If not specified, all retention policies will be backed up.
shard:This flag can be used to backup a specific shard ID. To see which shards are available, you can run the command SHOW SHARDS using the InfluxDB query language. If not specified, all shards will be backed up.
since:This flag can be used to create a backup since a specific date, where the date must be in RFC3339 format (for example, 2015-12-24T08:12:23Z). This flag is important if you would like to take incremental backups of your database. If not specified, all timeranges within the database will be backed up.
二、数据备份(必须先备份元数据,再备份数据库中的数据)
1、本地备份
1.1 创建本地备份目录
mkdir influxdb_backup
cd ./influxdb_backup
1.2 备份元数据
influxd backup -database mydatabase -retention autogen ./
1.3 备份数据库
influxd backup -database testdb -retention autogen ./
2、远程备份:假设备份192.168.10.188的数据到192.168.10.199
注:备份192.168.10.188的数据,需要登录到192.168.10.199执行备份命令
1.1 创建备份目录
mkdir backup_188
cd ./backup_188
1.2 备份元数据
influxd backup -host 192.168.10.188:8088 ./
1.3 备份数据库
influxd backup -database testdb -host 192.168.10.188:8088 ./
三、数据恢复(必须先恢复元数据,再恢复数据库中的数据)
1、恢复元数据
在188上:
cd ./influxdb_backup
influxd restore -metadir /var/lib/influxdb/meta ./
或
在199上:
cd ./backup_188
influxd restore -metadir /var/lib/influxdb/meta ./
2、恢复数据库中的数据
在188上:
cd ./influxdb_backup
influxd restore -database testdb -datadir /var/lib/influxdb/data ./
或
在199上
cd ./backup_188
influxd restore -database testdb -datadir /var/lib/influxdb/data ./
3、修改目录权限
chown -R influxdb:influxdb /var/lib/influxdb
4、重启服务
service influxdb restart
注:上述中的/var/lib/influxdb/meta 和 /var/lib/influxdb/data 是InfluxDB执行配置文件中配置的参数,详见/etc/influxdb/influxdb.conf配置文件meta 和 data 配置。
————————————————
版权声明:本文为CSDN博主「XINCHUN2017」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qian_feifei/article/details/75139665