Migrate Grafana & Prometheus's Docker volume
Over the past few weeks, I migrated the services that I had deployed on my Chromebook Pixel and old Celeron NUC to my newly purchased NUC 13. The only thing worth mentioning is that Docker volumes require some caution when being migrated. Hence, I have taken a brief note of the process here.
The Grafana & Prometheus service deployed using docker stack from this repo.
Procedure
The data volumes of Grafana & Prometheus are prom_grafana_data
and prom_prometheus_data
:
$ docker volume ls
DRIVER VOLUME NAME
...
local prom_grafana_data
local prom_prometheus_data
The main idea is to using a docker image to run backup and restore like this question in StackOverflow.
- Stop the service to prevent writing while backup.
$ docker stack rm prom # the service stack is prom
- Dump docker volume.
$ docker run --rm --volume prom_grafana_data:<the-mount-path-in-docker> --volume $(pwd):<the-backup-path-in-docker> ubuntu tar cvf <the-path-in-docker>/prom_grafana_data.tar <the-mount-path-in-docker>/prom_grafana_data --strip 1 $ docker run --rm --volume prom_prometheus_data:<the-mount-path-in-docker> --volume $(pwd):<the-backup-path-in-docker> ubuntu tar cvf <the-path-in-docker>/prom_prometheus_data.tar <the-mount-path-in-docker>/prom_prometheus_data --strip 1
- Transfer dumped volume into new machine.
- Start services on new machine to create named volumes (
docker-compose.yaml
will createprom_grafana_data
andprom_prometheus_data
with proper label & privilege, I tried manually edit resource labels but feel quite complicate then gave up).$ docker stack deploy prom -c docker-compose.yml
- Stop service on new machine.
$ docker stack rm prom
- Restore data on new machine (In this step I started a shell to manually do the decompress & copy operations).
# remove data in new created named volume and decompress the backup data into the named volume docker run -it --rm --volume <prom_prometheus_data|prom_grafana_data>:/home/scarlet/<prom_prometheus_data|prom_grafana_data> --volume $(pwd):/home/scarlet/backup ubuntu /bin/bash
- Start service on new machine with
docker stack deploy prom -c docker-compose.yml
.
Done!