Backup Docker Volume
- # After a bit of research, it turned out it’s actually pretty easy to back up volumes using volume mounts and a tar utility. For example to backup some_volume to /tmp/some_archive.tar.bz2, you can simply run:
- docker run --rm -v some_volume:/volume -v /tmp:/backup alpine tar -cjf /backup/some_archive.tar.bz2 -C /volume ./
- # And to restore it, just run:
- docker run --rm -v some_volume:/volume -v /tmp:/backup alpine sh -c "rm -rf /volume/* /volume/..?* /volume/.[!.]* ; tar -C /volume/ -xjf /backup/some_archive.tar.bz2"
- # Note: As a safety precaution, I advise you to stop all the containers using the volume being backed-up or restored, otherwise an inconsistent / intermediate state might be archived or recovered.
- # ... From "https://medium.com/@loomchild/backup-restore-docker-named-volumes-350397b8e362"