From 2dc1d6f6652e6f59db783241244924ac5070d824 Mon Sep 17 00:00:00 2001 From: Cat Tom <linweijie2015@gmail.com> Date: Thu, 25 Jul 2024 01:50:05 +0800 Subject: [PATCH] first hand up --- ...-of-Docker-Volumes-A-Step-by-Step-Guide.md | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 docs/tech/Backup-and-Restore-of-Docker-Volumes-A-Step-by-Step-Guide.md diff --git a/docs/tech/Backup-and-Restore-of-Docker-Volumes-A-Step-by-Step-Guide.md b/docs/tech/Backup-and-Restore-of-Docker-Volumes-A-Step-by-Step-Guide.md new file mode 100644 index 0000000..b76438f --- /dev/null +++ b/docs/tech/Backup-and-Restore-of-Docker-Volumes-A-Step-by-Step-Guide.md @@ -0,0 +1,57 @@ +# 手把手教你备份和还原 Docker 卷 + +本教程将以备份 Grafana 的数据卷为例,手把手教你如何备份和还原 Docker 卷。 + +``` title="docker-compose.yml" +grafana: + image: grafana/grafana-enterprise + container_name: grafana + ports: + - 100.114.118.48:3000:3000 + volumes: + - grafana-storage:/var/lib/grafana + environment: + GF_SERVER_DOMAIN: "3-buyvm-lv.tail184fc.ts.net" + networks: + - basic_network + labels: + - "com.centurylinklabs.watchtower.enable=true" + restart: unless-stopped +``` + +## 第一步:确定准备备份的 Docker 卷 + +备份卷的第一步是确定要备份的卷。 + +我们可以通过运行以下命令来做到这一点: + +```bash +docker volume ls +``` + +这将显示 Docker 主机上当前可用的所有卷的列表,记得记下要备份的卷名称。 + +``` +DRIVER VOLUME NAME +local 3-buyvm-lv_grafana-storage +``` + +在本次演示中,`3-buyvm-lv_grafana-storage` 将是我们将要备份的卷。 + +## 第二步:创建备份 + +要创建 Docker 卷备份,可以使用 `docker run` 命令启动一个容器,挂载要备份的卷,并将备份数据写入压缩包。 + +```bash +docker run --rm \ +--mount source=<volume-name>,target=<target> \ +-v $(pwd):/backup \ +busybox \ +tar -czvf /backup/<backup-filename>.tar.gz <target> +``` + +下面是我们备份 `3-buyvm-lv_grafana-storage` 的示例命令: + +```bash + +``` \ No newline at end of file