I know how to restore a dump file from mysqldump. Now, I am attempting to do that using kubernetes and a docker container. The database files are in persistent (nfs) mount. The docker cannot be accessed outside of the cluster as there is no need for anything external to touch it.
I tried:
kubectl run -i -t dbtest --image=mariadb --restart=Never --rm=true --command -- mysql -uroot -ps3kr37 < dump.sql
and
kubectl exec mariadb-deployment-3614069618-mn524 -i -t -- mysql -u root -p=s3kr37 < dump.sql
But neither commands worked -- errors about TTY, sockets, and other things hinting that I am missing something vital here.
What am I not understanding here?
I could just stop the deployment, scp the database files, and restart the container and hope for the best. However, what can go right?
The question Install an sql dump file to a docker container with mariaDB sure looks like a duplicate but is not: first, I am on Linux not Windows and more importantly the answers all are about initialising with a dump. I want to be able to trash the data and revert to the dump data. This is a test system that will eventually be the "live" so I need to restore from many potential dumps.
This should work:
kubeconfig is optional, digitalocean for examples provides that so you can run your commands from your local.
To see if everything looks good:
After which you'll have a terminal inside mysql.
What I did was this:
mysql
andinitd
.initd
, I added several,sql
files, including the dump.initd
as/docker-entrypoint-initdb.d
in the deployment.This causes all the files to be read at initialisation time provided that it is the first time we run.mysql
directory is mounted as/var/lib/mysql
and contains all the mariaDB files.If I need to revert, I trash all the contents of the
mysql
directory and re-create the deployment.