<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>数据库 on Zayn's Blog</title><link>https://blog.treesir.pub/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/</link><description>Recent content in 数据库 on Zayn's Blog</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><managingEditor>yangzun@treesir.pub (Zayn)</managingEditor><webMaster>yangzun@treesir.pub (Zayn)</webMaster><copyright>2021-2026 Zayn</copyright><lastBuildDate>Mon, 24 Jul 2023 16:14:42 +0800</lastBuildDate><atom:link href="https://blog.treesir.pub/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/index.xml" rel="self" type="application/rss+xml"/><item><title>使用 Kubernetes CronJob 自动备份 MySQL 数据到 MinIO</title><link>https://blog.treesir.pub/posts/k8s-cronjob-backup-mysql/</link><pubDate>Mon, 24 Jul 2023 16:14:42 +0800</pubDate><author>yangzun@treesir.pub (Zayn)</author><guid>https://blog.treesir.pub/posts/k8s-cronjob-backup-mysql/</guid><description>&lt;p>随着 Kubernetes 在生产环境中的广泛应用，越来越多的有状态应用（如 MySQL 数据库）也开始部署在 K8s 集群中。数据安全是生产环境的重中之重，本文将详细介绍如何使用 Kubernetes CronJob 实现 MySQL 数据库的自动化备份，并将备份文件安全地存储到 MinIO 对象存储中。&lt;/p>
&lt;h2 class="relative group">方案概述
&lt;div id="方案概述" class="anchor">&lt;/div>
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100">
&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700 !no-underline" href="#%e6%96%b9%e6%a1%88%e6%a6%82%e8%bf%b0" aria-label="锚点">#&lt;/a>
&lt;/span>
&lt;/h2>
&lt;h3 class="relative group">备份架构
&lt;div id="备份架构" class="anchor">&lt;/div>
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100">
&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700 !no-underline" href="#%e5%a4%87%e4%bb%bd%e6%9e%b6%e6%9e%84" aria-label="锚点">#&lt;/a>
&lt;/span>
&lt;/h3>
&lt;div class="mermaid" align="center">
&lt;pre>
flowchart LR
MySQL[MySQL Pod&lt;br/>Database] -->|导出数据| CronJob[CronJob Pod&lt;br/>mysqldump]
CronJob -->|上传备份| MinIO[MinIO Server&lt;br/>Bucket]
&lt;/pre>
&lt;/div>
&lt;h3 class="relative group">方案优势
&lt;div id="方案优势" class="anchor">&lt;/div>
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100">
&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700 !no-underline" href="#%e6%96%b9%e6%a1%88%e4%bc%98%e5%8a%bf" aria-label="锚点">#&lt;/a>
&lt;/span>
&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>自动化&lt;/strong>: 使用 CronJob 实现定时自动备份，无需人工干预&lt;/li>
&lt;li>&lt;strong>可靠性&lt;/strong>: 备份文件存储在独立的对象存储中，提高数据安全性&lt;/li>
&lt;li>&lt;strong>可扩展&lt;/strong>: 支持多数据库实例的备份，易于扩展&lt;/li>
&lt;li>&lt;strong>监控友好&lt;/strong>: 可以通过 Kubernetes 原生监控查看备份任务状态&lt;/li>
&lt;li>&lt;strong>成本效益&lt;/strong>: 使用开源的 MinIO 作为存储后端，降低成本&lt;/li>
&lt;/ul>
&lt;h2 class="relative group">环境准备
&lt;div id="环境准备" class="anchor">&lt;/div>
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100">
&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700 !no-underline" href="#%e7%8e%af%e5%a2%83%e5%87%86%e5%a4%87" aria-label="锚点">#&lt;/a>
&lt;/span>
&lt;/h2>
&lt;h3 class="relative group">前置条件
&lt;div id="前置条件" class="anchor">&lt;/div>
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100">
&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700 !no-underline" href="#%e5%89%8d%e7%bd%ae%e6%9d%a1%e4%bb%b6" aria-label="锚点">#&lt;/a>
&lt;/span>
&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>组件&lt;/th>
&lt;th>版本要求&lt;/th>
&lt;th>说明&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Kubernetes&lt;/td>
&lt;td>v1.18+&lt;/td>
&lt;td>支持 CronJob v1 API&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>MySQL&lt;/td>
&lt;td>5.7+ / 8.0+&lt;/td>
&lt;td>运行在 K8s 集群中&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>MinIO&lt;/td>
&lt;td>任意版本&lt;/td>
&lt;td>对象存储服务&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>网络连通性&lt;/td>
&lt;td>-&lt;/td>
&lt;td>CronJob Pod 能访问 MySQL 和 MinIO&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 class="relative group">自定义镜像
&lt;div id="自定义镜像" class="anchor">&lt;/div>
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100">
&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700 !no-underline" href="#%e8%87%aa%e5%ae%9a%e4%b9%89%e9%95%9c%e5%83%8f" aria-label="锚点">#&lt;/a>
&lt;/span>
&lt;/h3>
&lt;p>本方案使用了专门构建的备份镜像，包含了 mysqldump 和 MinIO 客户端工具。&lt;/p></description></item></channel></rss>