SO, I'm trying to restore a docker volume that I've backuped from another host.
This specific instance is a backup of a volume containing grafana data at /var/lib/grafana
The backup has been done with docker run --rm --volumes-from Grafana -v $(pwd):/backup busybox tar cvfz /backup/grafana.tar /var/lib/grafana
Where Grafana
is the name of the container where the volume is attached
On my new host, after having transferred the grafana.tar file I've run
docker run --rm --volumes-from grafana-new -v $(pwd):/backup busybox sh -c "cd /var/lib/grafana && tar xvf /backup/grafana.tar --strip 1"
Where grafana-new is the new container which has attached a volume with the same path in the container /var/lib/grafana
The issue is that, it doesn't seem to restore the data even if I'm seeing on the terminal
nicola@nicola-virtualbox:~/Documenti/volume-backup$ docker run --rm --volumes-from grafana-new -v $(pwd):/backup busybox sh -c "cd /var/lib/grafana && tar xvf /backup/grafana.tar --strip 1"
var/lib/grafana/
var/lib/grafana/png/
var/lib/grafana/csv/
var/lib/grafana/plugins/
var/lib/grafana/alerting/
var/lib/grafana/alerting/1/
var/lib/grafana/alerting/1/__default__.tmpl
var/lib/grafana/grafana.db
I'm saying that because when I'm trying to log in with the password used on the host from where I've backuped the data, it says wrong password
WHere I'm doing wrong?
So, it turned out that to backup and restore a docker volume you need
# check `docker volume ls´ for volume names
source_volume=name_of_your_source_volume
backup_date=$(date +"%Y%m%d")
docker run --tty --rm --interactive --volume ${source_volume}:/source --volume ${PWD}/archive:/backup alpine tar czvf /backup/${source_volume}_${backup_date}.tar.gz -C /source .
And restored them like this:
target_volume=name_of_your_target_volume
restore_archive=${volume}_${backup_date}.tar.gz # of course the real name without placeholders
docker run --tty --rm --interactive --volume ${target_volume}:/target --volume ${PWD}/archive:/backup alpine tar xzvf /backup/${restore_archive} -C /target
When restoring, the tar.gz must be inside an /archive/
folder