如何将数据库还原到Influxdb容器

时间:2017-05-28 11:19:51

标签: database influxdb database-restore

对不起我的无知。我有使用docker-compose在docker上运行的大量数据库,如下所示。

  influxdb:
   image: influxdb:alpine
   ports:
       - 8086:8086
   volumes:
      - ./influxdb/config/influxdb.conf:/etc/influxdb/influxdb.conf:ro
      - ./influxdb/data:/var/lib/influxdb

我需要将数据库的备份从远程服务器恢复到此Influxdb容器。我从远程服务器上获取了如下备份。

influxd backup -database tech_db /tmp/tech_db

我阅读了文档,找不到将数据库恢复到docker容器的方法。任何人都可以给我一个指向如何执行此操作的指针。

1 个答案:

答案 0 :(得分:1)

我也有同样的问题。看起来这是不可能的,因为你无法杀死容器中的涌入进程。

# Restoring a backup requires that influxd is stopped (note that stopping the process kills the container).
docker stop "$CONTAINER_ID"

# Run the restore command in an ephemeral container.
# This affects the previously mounted volume mapped to /var/lib/influxdb.
docker run --rm \
--entrypoint /bin/bash \
-v "$INFLUXDIR":/var/lib/influxdb \
-v "$BACKUPDIR":/backups \
influxdb:1.3 \
-c "influxd restore -metadir /var/lib/influxdb/meta -datadir /var/lib/influxdb/data -database foo /backups/foo.backup"

# Start the container just like before, and get the new container ID.
CONTAINER_ID=$(docker run --rm \
--detach \
-v "$INFLUXDIR":/var/lib/influxdb \
-v "$BACKUPDIR":/backups \
-p 8086 \
influxdb:1.3
)

更多信息是here