如何使用 kubernetes 从 mysqldump 恢复转储文件? [英] How do I restore a dump file from mysqldump using kubernetes?

查看:22
本文介绍了如何使用 kubernetes 从 mysqldump 恢复转储文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何从 mysqldump 恢复转储文件.现在,我正在尝试使用 kubernetes 和 docker 容器来做到这一点.数据库文件处于持久 (nfs) 挂载状态.docker 不能在集群外部被访问,因为不需要任何外部的东西来触摸它.

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.

我试过了:

kubectl run -i -t dbtest --image=mariadb --restart=Never --rm=true --command -- mysql -uroot -ps3kr37 < dump.sql

kubectl exec mariadb-deployment-3614069618-mn524 -i -t -- mysql -u root -p=s3kr37 < dump.sql

但是这两个命令都不起作用——关于 TTY、套接字和其他东西的错误暗示我在这里遗漏了一些重要的东西.

But neither commands worked -- errors about TTY, sockets, and other things hinting that I am missing something vital here.

我在这里不明白什么?

可以停止部署,对数据库文件进行 scp,然后重新启动容器并希望一切顺利.但是,什么可以做对呢?

I could just stop the deployment, scp the database files, and restart the container and hope for the best. However, what can go right?

使用 mariaDB 将 sql 转储文件安装到 docker 容器的问题确实看起来像重复但不是:首先,我在 Linux 而不是 Windows 上,更重要的是,答案都是关于使用转储进行初始化.我希望能够丢弃数据并恢复到转储数据.这是一个最终将成为实时"的测试系统,因此我需要从许多潜在的转储中恢复.

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.

推荐答案

我做的是这样的:

  • 使用两个子目录创建 NFS 挂载:mysqlinitd.
  • initd中,我添加了几个,sql文件,包括dump.
  • 在部署中将 initd 挂载为 /docker-entrypoint-initdb.d.这会导致在初始化时读取所有文件如果它是我们第一次运行.
  • mysql 目录挂载为 /var/lib/mysql 并包含所有 mariaDB 文件.
  • Create an NFS mount with two sub0drectories: mysql and initd.
  • In initd, I added several ,sql files, including the dump.
  • Mount 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.
  • The mysql directory is mounted as /var/lib/mysql and contains all the mariaDB files.

如果我需要还原,我会删除 mysql 目录的所有内容并重新创建部署.

If I need to revert, I trash all the contents of the mysql directory and re-create the deployment.

这篇关于如何使用 kubernetes 从 mysqldump 恢复转储文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆