Skip to content

Volume Backups

Matt Mayer edited this page Jan 13, 2020 · 1 revision

Copy and Move Volume

As root in the host running the Docker Volume you wish to clone. This assumes that the host machine that you are copying from is a Linux machine running Docker natively

cd /var/lib/docker/volumes
tar zcvf backup_volume.tar.gz <volume_name> # eg: onc-healthit_pgdata
mv backup_volume.tar.gz <your home directory>

This will tar up the volume so that it can be copied to another machine.

Copy the backup volume tar to the host you would like to use the volume on and un-tar it.

scp <username>@<remote_host>:backup_volume.tar.gz .
tar zxvf backup_volume.tar.gz

Move Volume Into Docker Volumes Location

Make sure that any local containers that use the volume you are about to replace are stopped.

If on a Mac

Copy the volume into the Docker VM (The VM that is running Docker itself on your Mac)

docker run --rm -it -v /:/docker -v <location of backup_volume>/:/host alpine

This will open a shell to a small docker container that has the location of the backup_volume mounted at /host and the root of your host machine mounted at docker. From within this container you will be able to access /docker/var/lib/docker whereas on your host machine you would not be able to access /var/lib/docker.

cp -r /host/<volume_name> /docker/var/lib/docker/volumes

If on Linux

If not on a Mac and are on a Linux machine running Docker natively you should be able to just put the docker volume directly in place and follow the permission changing instructions using /var/lib/docker/volumes/<volume_name/_data for the data location.

cp -r /<unzipped_volume_location>/<volume_name> /var/lib/docker/volumes

Change Volume Permissions

Change the permissions of the data in /docker/var/lib/docker/volumes/<volume_name/_data. There will be several files in _data whose owner and group have been changed to root. Change them to match the rest of the files in _data

chown -R <owner>:<group> /docker/var/lib/docker/volumes/<volume_name>/_data