- dump and import a single or multiple databases
- dump each database into a different file
- exclude a database from dump
- Kubernetes scheduled jobs examples for automatic backup, copy and import databases
docker run --rm -v $PWD:/mysqldump -e DB_NAME=db_name -e DB_PASS=db_pass -e DB_USER=db_user -e DB_HOST=db_host camil/mysqldump
docker run --rm -v $PWD:/mysqldump -e DB_PASS=db_pass -e DB_USER=db_user -e DB_HOST=db_host -e ALL_DATABASES=true camil/mysqldump
docker run --rm -v $PWD:/mysqldump -e DB_PASS=db_pass -e DB_USER=db_user -e DB_HOST=db_host -e ALL_DATABASES=true -e IGNORE_DATABASE=some_database camil/mysqldump
docker run --rm -v $PWD:/mysqldump --entrypoint /import.sh -e DB_NAME=db_name -e DB_HOST=db_host -e DB_USER=db_user -e DB_PASS=db_pass camil/mysqldump
docker run --rm -v $PWD:/mysqldump --entrypoint /import.sh -e DB_NAME=db_name -e DB_HOST=db_host -e DB_USER=db_user -e DB_PASS=db_pass -e ALL_DATABASES=true camil/mysqldump
Notes:
- you have to label a node with
role=mysqldump
on the source cluster androle=mysqlimport
on the destination cluster. Or just remove thenodeSelector
rules from jobs. - Edit ConfigMaps and Secrets according to your environment. Values in secrets have to be base64 encoded.
- Edit the
scheduledjobs
definitions to set backup location or change the linux user:
-
If you plan to dump just some databases, use or duplicate the "mysqldump.scheduledjob.single.yaml" example
-
To dump all databases use "mysqldump.scheduledjob.all.yaml" example. Also has an option to exclude one database from backup.
-
Create secret, configmap and job(s)
kubectl create -f k8s/mysqldump/mysqldump.configmap.yaml kubectl create -f k8s/mysqldump/mysqldump.secret.yaml kubectl create -f k8s/mysqldump/mysqldump.scheduledjob.all.yaml
kubectl create -f k8s/mysqldump/transporter.configmap.yaml
kubectl create -f k8s/mysqldump/transporter.secret.yaml
kubectl create -f k8s/mysqldump/transporter.scheduledjob.yaml
kubectl create -f k8s/mysqlimport/mysqlimport.configmap.yaml
kubectl create -f k8s/mysqlimport/mysqlimport.secret.yaml
kubectl create -f k8s/mysqlimport/mysqlimport.scheduledjob.yaml