Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. CREATE A NETWORK
- $ docker network create mysql
- 2. CREATE A DATA CONTAINER
- $ docker create \
- --name mysql-data \
- --volume /var/lib/mysql \
- --volume /backups \
- mysql:latest
- 3. CREATE THE REAL CONTAINER TO USE
- $ docker run \
- --detach \
- --env MYSQL_ROOT_PASSWORD=<your-mysql-password> \
- --env MYSQL_DATABASE=test \
- --name mysql-server \
- --net mysql \
- --volumes-from mysql-data \
- mysql:latest
- 4. INSERT SOME DATA
- $ docker exec -it mysql-server bash
- # mysql -p
- > USE test
- > CREATE TABLE dog(age INT, name TEXT);
- > INSERT INTO dog(age, name) VALUES(5, "bolt");
- > \q
- # CTRL+D
- 5. MAKE A MYSQL BACKUP (THIS IS STILL INSIDE THE CONTAINER)
- $ docker run \
- --rm \
- --net mysql \
- --volumes-from mysql-data \
- mysql \
- bash -c "mysqldump -p<your-mysql-password> -h mysql-server --databases test > /backups/test.sql"
- 6. EXPORT THE BACKUP INSIDE TO THE OUTSIDE
- $ docker run \
- --rm \
- --volumes-from mysql-data \
- carinamarina/backup \
- backup \
- --source /backups/ \
- --stdout \
- --zip > my-local-backup.tar.gz
- 7. DELETE THOSE CONTAINERS
- $ docker stop mysql-server
- $ docker rm mysql-server mysql-data
- 8. REPEAT SETEP 2 AND 3 TO CREATE THEM AGAIN
- IF YOU WANT TO CHECK IF IT'S EMPTY USE:
- $ docker exec -it mysql-server bash
- # mysql -p
- > SHOW DATABASES
- YOU SHOULDN'T SEE test DATABASE
- 9. SEND BACK THE BACKUP (FROM OUTSIDE THE CONTAINER) TO THE CONTAINER (TO INSIDE THE CONTAINER)
- docker run \
- --rm \
- --interactive \
- --volumes-from mysql-data \
- carinamarina/backup \
- restore \
- --destination /backups/ \
- --stdin \
- --zip \
- < my-local-backup.tar.gz
- 10. IMPORT THE BACKUP DATA DO MYSQL DATABASE (IT HAPPENS INSIDE THE CONTAINER)
- docker run \
- --rm \
- --net mysql \
- --volumes-from mysql-data \
- mysql:latest \
- bash -c "mysql -p<your-mysql-password> -h mysql-server < /backups/test.sql"
- 11. CHECK IF IT'S OK
- $ docker exec -it mysql-server bash
- # mysql -p
- > SHOW DATABASES
- > USE test
- > SHOW TABLES
- > SELECT * FROM dog;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement