This is batch task to dump only user databases from MySQL.
In some case like upgrading MySQL version, When dump includes system databases, importing dump may fail.
There are also several way to back up MySQL databases:
- "Creating database dumps" and "Restoring data from dump files" in Description of MySQL Docker Official Image)
- Backup, restore, or migrate data volumes | Use volumes | Docker Documentation
However, they are the way for full backup, we need the way to dump only user databases.
1.
Prepare file to load environment variables, for example, let's name env.list
:
LOGIN_USER=root
LOGIN_PASSWORD=p@ssW0rd
LOGIN_HOST=database
* cf. Set environment variables (-e, --env, --env-file) | docker run | Docker Documentation
2.
Run following command:
docker run --env-file env.list --network some-network --rm -v $(pwd)/backup:/root/storage futureys/dump-mysql
Then, user databases are dumped in ./backup
directory on host.
1.
Assume that following docker-compose.yml
are upping:
---
version: '3.7'
services:
database:
container_name: database
environment:
MYSQL_ROOT_PASSWORD: ${DATABASE_ROOT_PASSWORD}
MYSQL_DATABASE: service
image: mysql
# ...
2.
Prepare docker-compose.dump.yml
:
---
version: '3.7'
services:
dump:
container_name: dump
image: futureys/dump-mysql
environment:
LOGIN_USER: root
LOGIN_PASSWORD: ${DATABASE_ROOT_PASSWORD}
LOGIN_HOST: database
volumes:
- ./backup:/root/storage
3.
Run following command:
docker-compose -f docker-compose.yml -f docker-compose.dump.yml run --rm dump
Then, user databases are dumped in ./backup
directory on host.
Login user name for MySQL to dump. Required.
Login user password for MySQL to dump. Required.
Host name of MySQL to dump. Optional. Default value: database
Port number of MySQL to dump. Optional. Default value: 3306
View license information for the software contained in this image.
As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).
As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.