Last active
June 25, 2018 13:14
-
-
Save mhadidg/464bc9de0ebb5b4bf17ab8c538e8f28b to your computer and use it in GitHub Desktop.
Backup and restore Docker volumes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Backup | |
| docker run --rm --volumes-from container_id -v $(pwd):/backup ubuntu:18.04 tar cvf /backup/file.bak.tar /path/to/volume | |
| ls # file.bak.tar | |
| # Restore | |
| docker run --rm --volumes-from container_id -v $(pwd):/backup ubuntu:18.04 bash -c "cd /path/to/volume && tar xvf /backup/file.bak.tar --strip 3" | |
| # Example for MySQL database | |
| docker run --rm --volumes-from mysql -v $(pwd):/backup ubuntu:18.04 tar cvf /backup/db.bak.tar /var/lib/mysql | |
| docker run --rm --volumes-from mysql -v $(pwd):/backup ubuntu bash -c "cd /var/lib/mysql && tar xvf /backup/db.bak.tar --strip 3" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment