基于gocron定时任务建设
-
基础环境配置
golang安装
下载
wget https://dl.google.com/go/go1.21.6.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
-
下载gocron组件
wget https://github.com/ouqiang/gocron/releases/download/v1.5.3/gocron-v1.5.3-linux-amd64.tar.gz
wget https://github.com/ouqiang/gocron/releases/download/v1.5.3/gocron-node-v1.5.3-linux-amd64.tar.gz
[root@filebackup software]# tar -zxvf gocron-v1.5.3-linux-amd64.tar.gz
gocron-linux-amd64/
gocron-linux-amd64/gocron
[root@filebackup software]# tar -zxvf gocron-node-v1.5.3-linux-amd64.tar.gz
gocron-node-linux-amd64/
gocron-node-linux-amd64/gocron-node
[root@filebackup software]#
-
gocron配置
创建数据库和用户
创建数据库
CREATE DATABASE gocron DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;
创建用户
CREATE USER 'gocron'@'%' IDENTIFIED WITH mysql_native_password BY 'TNAYNCSfKK5oLl0H';
GRANT ALL PRIVILEGES ON gocron.* to 'gocron'@'%';
-
配置节点
nohup /data/myapp/gocron/gocron-node -allow-root > /tmp/gocron-node.log 2>&1 &
-
配置数据
-
配置告警webhook
https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=3b3bdb5e-8cad-4398-9757-8559dd7a4315
{
"msgtype": "text",
"text": {
"content" : "任务ID:{{.TaskId}}\n任务名称:{{.TaskName}}\n任务执行结果:{{.Status}}\n任务执行输出{{.Result}}"
}
}
-
添加节点
节点名称: Filebackup
主机名:ip地址
端口:5921
-
备份配置
MySQL 5:
/data/scripts/mysql57_backup.sh -I 12312-P 3306
MySQL 8:
/data/scripts/mysql8_backup.sh -I 123 -P 3320
postgres:
/data/scripts/pg_backup.sh -I 10.123 -P 5432 -D /data/myapp/postgres13
Mongodb:
/bin/bash /data/scripts/mongodb_yapi.sh -I 123 -P 27017 -U 123 -C 123
归档日志备份