influxdb得导出与导入

转载请注明出处:

1、备份元数据

  基本语法:

influxd backup <path-to-backup>

  备份元数据,没有任何其他参数,备份将只转移当前状态的系统元数据到path-to-backuppath-to-backup为备份保存的目录,不存在会自动创建。

  该备份会备份所有数据库以及所有保存策略下得数据。

   导出常用得其他参数:

root@704be48ac1bc:/# 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
            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.
backup: flag: help requested

  具体如下:

Usage: influxd backup [options] PATH
    -portable   # 在线备份,必选
    -host <host:port> # 需要备份的influxdb服务机器地址,可选,Defaults to 127.0.0.1:8088.
    -db <name> # 需要备份的db名称,可选,若没有指定,将备份所有数据库
    -rp <name> # 备份某个保留策略的数据,未指定,则备份所有rp的数据。
    -shard <id> # 需要备份的shard id,可选,若指定了备份shard,必须先选择rp
    -start # 需要备份的数据的起始时间,timestamp (RFC3339 format). 不能和-since一起使用
    -end # 需要备份的数据的结束时间,timestamp (RFC3339 format). 不能和-since一起使用
    -since # 备份这个timestamp之后的数据,建议用-start <timestamp>代替
    -skip-errors # 可选,当备份shards时,跳过备份失败的shard,继续备份其他shard。

 

2.influxdb导入

  1.先删除数据库

                           

  2.导入备份数据:

               

   这种方式只能导入按个数据库进行导入;

  3.导入其他配置项参数:

root@704be48ac1bc:/# influxd restore -h

Uses backup copies from the specified PATH to restore databases or specific shards from InfluxDB OSS
  or InfluxDB Enterprise to an InfluxDB OSS instance.

Usage: influxd restore -portable [options] PATH

Note: Restore using the '-portable' option consumes files in an improved Enterprise-compatible
  format that includes a file manifest.

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.

restore: flag: help requested

  主要作用:

Usage: influxd restore -portable [options] PATH
Options:
    -portable #
    -host  <host:port>
    -db    <name> # 从备份数据的哪个库恢复数据Name of database to be restored from the backup
    -newdb <name>
            # 数据恢复到新库名称,若没有指定,选择-db <name>的名称。newdb必须不存在,恢复时会自动创建
    -rp    <name> # 从备份数据的哪个rp恢复数据,指定了-rp,必须指定-db
    -newrp <name> #恢复数据新的rp名称,newrp必须存在。指定了-rp,未指定-newrp则使用-rp
    -shard <id> # 需要恢复的shard,如果指定了'-db <db_name>' and '-rp <rp_name>',必须-shard<id>
    PATH #备份数据文件list

  4.第二种导入方式:

  删除influxdb数据库存储得元数据文件,将influxdb得数据库元文件目录指定为备份得目录,然后再重启influxdb数据库即可完成导入

influxd restore -metadir <path-to-meta-or-data-directory> <path-to-backup>

  从/var/lib/influxdb/ 目录下删除meta目录,即 rm -rf /var/lib/influxdb/meta,然后重启influxdbservice influxdb restart

 

 

posted @ 2024-07-13 21:40  香吧香  阅读(144)  评论(0编辑  收藏  举报