-portable 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 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> Retention policy to use for the backup. Optional. If not specified, all retention policies are used by default. -shard <id> The identifier of the shard to back up. Optional. If specified, '-rp <rp_name>' is required. -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> Exclude all points after timestamp (RFC3339 format). Not compatible with '-since <timestamp>'. -since <2015-12-24T08:12:23Z> 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.
Options: -portable Required to activate the portable restore mode. If not specified, the legacy restore mode is used. -host <host:port> InfluxDB OSS host to connect to where the data will be restored. Defaults to '127.0.0.1:8088'. -db <name> Name of database to be restored from the backup (InfluxDB OSS or InfluxDB Enterprise) -newdb <name> Name of the InfluxDB OSS database into which the archived data will be imported on the target system. Optional. If not given, then the value of '-db <db_name>' is used. The new database name must be unique to the target system. -rp <name> Name of retention policy from the backup that will be restored. Optional. Requires that '-db <db_name>' is specified. -newrp <name> Name of the retention policy to be created on the target system. Optional. Requires that '-rp <rp_name>' is set. If not given, the '-rp <rp_name>' value is used. -shard <id> Identifier of the shard to be restored. Optional. If specified, then'-db <db_name>' and '-rp <rp_name>' are required. PATH Path to directory containing the backup files.
2020/12/09 03:30:56 backing up metastore to influx_db_backup/meta.00 2020/12/09 03:30:56 No database, retention policy or shard ID given. Full meta store backed up. 2020/12/09 03:30:56 backup complete: 2020/12/09 03:30:56 influx_db_backup/influx_db_backup/meta.00
Using metastore snapshot: influx_db_backup/meta.01 bash-5.0# influxd restore -database msp -datadir /var/lib/influxdb/data ./influx_db_backup 2020/12/09 03:46:48 Restoring offline from backup influx_db_backup/msp.*
这也不知道是否备份成功,我们比较下两个数据库里面的数据:
针对influx-1
1 2 3 4 5 6 7 8 9 10 11
> show measurements; name: measurements name ---- test_udp_proxy > select sum(count) from test_udp_proxy; name: test_udp_proxy time sum ---- --- 0 96100 >
针对influx-2
1 2 3 4 5 6
> show databases; name: databases name ---- monitor >
首先,是没有msp这个数据库的,说明我们备份恢复的时候,这个数据库必须要存在。
现在我们创建这个数据库后,在执行数据恢复,显示结果如下:
1
Restoring offline from backup influx_db_backup/msp.*
2020/12/09 05:27:15 error updating meta: DB metadata not changed. database may already exist restore: DB metadata not changed. database may already exist
SELECT * INTO msp..:MEASUREMENT FROM /.*/ GROUP BY *
结果如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
> SELECT * INTO msp..:MEASUREMENT FROM /.*/ GROUP BY * name: result time written ---- ------- 0 96100 > select sum(count) from test_udp_proxy; name: test_udp_proxy time sum ---- --- 0 96100 > use msp; Using database msp > select sum(count) from test_udp_proxy; name: test_udp_proxy time sum ---- --- 0 96100 >
> auth username: root password: > use msp; WARN: error authorizing query: create admin user first or disable authentication Using database msp > CREATE USER root WITH PASSWORD '123456' WITH ALL PRIVILEGES > auth username: root password: > use msp; Using database msp > show measurements; name: measurements name ---- test_udp_proxy > select sum(count) from test_udp_proxy; name: test_udp_proxy time sum ---- --- 0 96100 >
bash-5.0# influx_inspect export -help Exports TSM files into InfluxDB line protocol format.
Usage: influx_inspect export [flags]
-compress Compress the output -database string Optional: the database to export -datadir string Data storage path (default "/root/.influxdb/data") -end string Optional: the end time to export (RFC3339 format) -lponly Only export line protocol -out string Destination file to export to (default "/root/.influxdb/export") -retention string Optional: the retention policy to export (requires -database) -start string Optional: the start time to export (RFC3339 format) -waldir string WAL storage path (default "/root/.influxdb/wal")
bash-5.0# influx -import -host influx-2 -port 8086 -username root -password 123456 -path=msp -precision=ns -database msp 2020/12/09 07:36:40 Processed 100000 lines. Time elapsed: 991.6736ms. Points per second (PPS): 100839 2020/12/09 07:36:41 Processed 200000 lines. Time elapsed: 1.936923s. Points per second (PPS): 103256 2020/12/09 07:36:42 Processed 300000 lines. Time elapsed: 2.9666234s. Points per second (PPS): 101125 2020/12/09 07:36:43 Processed 400000 lines. Time elapsed: 3.9109787s. Points per second (PPS): 102276 2020/12/09 07:36:44 Processed 500000 lines. Time elapsed: 4.8662251s. Points per second (PPS): 102749 2020/12/09 07:36:45 Processed 600000 lines. Time elapsed: 5.9503395s. Points per second (PPS): 100834 2020/12/09 07:36:46 Processed 700000 lines. Time elapsed: 6.9116939s. Points per second (PPS): 101277 2020/12/09 07:36:47 Processed 800000 lines. Time elapsed: 7.9081228s. Points per second (PPS): 101161 2020/12/09 07:36:48 Processed 900000 lines. Time elapsed: 8.945495s. Points per second (PPS): 100609 2020/12/09 07:36:49 Processed 1000000 lines. Time elapsed: 9.9123997s. Points per second (PPS): 100883 2020/12/09 07:36:49 Processed 1 commands 2020/12/09 07:36:49 Processed 1057100 inserts 2020/12/09 07:36:49 Failed 0 inserts
现在查看influx-2的数据库是否正常:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
bash-5.0# influx Connected to http://localhost:8086 version 1.8.3 InfluxDB shell version: 1.8.3 > auth username: root password: > use msp Using database msp > show measurements; name: measurements name ---- test_udp_proxy > select sum(count) from test_udp_proxy; name: test_udp_proxy time sum ---- --- 0 96100 >