[英]How to backup MYSQL database with kubernetes
I successfully, recreated Single-Instance Stateful Application tutorial.我成功地重新创建了单实例有状态应用程序教程。 Naturally, I'd like to create a periodic backup of all databases.
当然,我想创建所有数据库的定期备份。 I found this article that explains how to make a backup.
我发现这篇文章解释了如何进行备份。 Unfortunately, it does not work for me.
不幸的是,它对我不起作用。 The command that I am running looks like this
我正在运行的命令看起来像这样
$ kubectl exec -n <namespace> <pod> -- mysqldump -u root -p$MYSQL_ROOT_PASSWORD --all-databases > /var/lib/mysql/backup/alldbs.sql
I found error(s).我发现了错误。 Backup was not working for two reasons.
备份不起作用有两个原因。
1st, incorrect semantic .第一,不正确的语义。 Instead of using
kubectl exec -n <namespace> <pod> mysqldump -u root -p$MYSQL_ROOT_PASSWORD --all-databases > dump.sql
as article mentions.而不是使用
kubectl exec -n <namespace> <pod> mysqldump -u root -p$MYSQL_ROOT_PASSWORD --all-databases > dump.sql
作为文章提到的。 I had to use a syntax described in mysql dockerhub documentation that looks like this kubectl exec -n <namespace> <pod> -- sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > dump.sql
我不得不使用mysql dockerhub文档中描述的语法,看起来像这个
kubectl exec -n <namespace> <pod> -- sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > dump.sql
2nd, incorrect path assumption . 2、不正确的路径假设。 I assumed that
dump.sql
was created on the pod/container filesystem so, I expected to see backup file inside container.我假设
dump.sql
是在 pod/container 文件系统上创建的,所以我希望在容器内看到备份文件。 Instead backup file was created relative to your host machine filesystem not pod/container.相反,备份文件是相对于您的主机文件系统而不是 pod/容器创建的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.