Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Backup and restore a Docker volume on Mac OS X
- This is a rough draft for backing up and restoring data contained in a Docker volume. I
- can't say that this is a "best practice". For my limited testing at the moment, it seems
- sufficient.
- ## Example `docker-compose.yml`
- ```yml
- version: '3'
- services:
- db:
- image: mysql:5.7
- environment:
- MYSQL_ROOT_PASSWORD: secret
- MYSQL_DATABASE: tacos
- MYSQL_USER: tacos
- MYSQL_PASSWORD: secret
- volumes:
- - databasedata:/var/lib/mysql
- volumes:
- databasedata:
- driver: 'local'
- ```
- To start:
- ```
- docker-compose up
- ```
- ## Login and interact with MySQL
- From the host machine, where `DEADBEEF0123` is the ID of the running container.
- ```
- docker exec -it DEADBEEF0123 bash
- ```
- In the container:
- ```
- mysql -u tacos -p
- ```
- ## Backup MySQL
- From the host machine:
- ```
- CONTAINER='DEADBEEF0123'
- DIR_TO_BACKUP='/var/lib/mysql'
- BACKUP_NAME='backup.tar'
- docker run --rm --volumes-from "${CONTAINER}" -v $(pwd):/backup alpine:3.8 tar cvf "/backup/${BACKUP_NAME}" "${DIR_TO_BACKUP}"
- ```
- ## Restore MySQL
- From the host machine:
- ```
- CONTAINER='DEADBEEF0123'
- BACKUP_NAME='backup.tar'
- docker run --rm --volumes-from "${CONTAINER}" -v $(pwd):/backup alpine:3.8 tar xvf "/backup/${BACKUP_NAME}"
- ```
Add Comment
Please, Sign In to add comment