使用cronjob备份mysql
source link: https://www.bboy.app/2021/06/28/%E4%BD%BF%E7%94%A8cronjob%E5%A4%87%E4%BB%BDmysql/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
使用cronjob备份mysql
发表于
2021-06-28 分类于 kubernetes
越来越觉得Kubernetes的cronjob无敌好吧,用来做定时任务管理的话,这次要解决的是使用cronjob去备份我们的mysql,这里的备份使用的是mysqldump,因为数据量不大,如果大数据量的话推荐使用xtrabacup
思路就是往mysql容器里面挂载备份的volume,然后执行备份脚本这样
首先编写备份脚本
#!/bin/bash
date=`date +%Y%m%d-%s`
mysqldump -uroot -p'你的密码' -h mysql.bboysoul.cn --all-databases >/backup/$date.sql
echo "备份完成"
之后编写yaml文件
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: mariadb-backup
namespace: cronjob
spec:
schedule: "0 3 * * *"
successfulJobsHistoryLimit: 5
failedJobsHistoryLimit: 5
jobTemplate:
spec:
template:
spec:
containers:
- name: mariadb-backup
image: registry.bboysoul.cn/mariadb:10.3.27
imagePullPolicy: IfNotPresent
command: ['bash','/backup/backup.sh']
volumeMounts:
- name: mariadb-backup
mountPath: "/backup"
restartPolicy: Never
volumes:
- name: mariadb-backup
nfs:
server: 10.10.100.244
path: /data/backup/mariadb
其他的貌似也没啥可以说的
欢迎关注我的博客www.bboy.app
Have Fun
欢迎关注我的其它发布渠道
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK