惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
爱范儿
爱范儿
L
LangChain Blog
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
G
Google Developers Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 哈喽哈喽111111

Rocky 9.6安装配置Google Authenticator AI 不仅没有减少工作,反而增加了工作 你需要知道的 AI 内存知识 firewall-cmd使用教程 minio从旧集群导出桶再上传到新集群导入桶 RockyLinux SSH 跳板转发 3389(Windows 远程桌面)完整方案 MySQL使用自带的logrotate配置日志轮转 yum方式安装redis7 nacos新加用户操作 网络运营商禁止端口信息 Linux开机启动rc.local不生效的一般解决方案 Nginx流量拷贝ngx_http_mirror_module模块使用方法详解 Adobe 修改 hosts 文件 axios 投毒与好莱坞式骗术 Linux系统在使用systemctl启动服务的失败,报错如下:Error No space left on device git submodule 的增、查、改、删 Rocky Linux 安装 Google Chrome 浏览器 “头号玩家”—— 美国技术霸权下的全球虚拟货币资产收割行动深层解析 你是第几级 AI 编程 MySQL中通过关联update将一张表的一个字段更新到另外一张表中 Linux 的 Port Knocking 端口碰撞(端口敲门) MySQL解除死锁 jar文件解压缩操作 设置Windows服务器远程桌面能使用多个桌面 禁用sentinel 在 Linux 中安装和配置 NTP 服务器和 NTP 客户端 springboot配置文件关系及加载顺序 用自带的Nginx为gitlab做白名单 Rocky9和Ubuntu使用pip安装python的库mysqlclient失败解决方式 在Spring Boot Admin中根据Nacos的命名空间来区分和管理不同的环境
20251024- 使用shell脚本分库定时备份MySQL数据
哈喽哈喽111111 · 2025-10-24 · via 博客园 - 哈喽哈喽111111
#!/bin/bash

# 注意mysql和mysqldump命令使用绝对路径

# mkdir -p /data/backup_mysql
# touch /data/backup_mysql/backup_mysql.log

host="127.0.0.1"
port="3306"
user="root"
password="password"
backdir="/data/backup_mysql"
time=`date +%Y%m%d%H%M%S`
log="/data/backup_mysql/backup_mysql.log"

mkdir -p ${backdir}/${time}

for db in `/usr/bin/mysql -h$host -u$user -P$port -p$password -e"show databases"|egrep -v "information_schema|mysql|performance_schema|sys|Database"`
do
  /usr/bin/mysqldump  -h$host -u$user -P$port -p$password --skip-opt --quick --single-transaction --order-by-primary --hex-blob --routines --events --set-gtid-purged=OFF --skip-triggers --skip-extended-insert ${db}  > ${backdir}/${time}/${db}_${time}.sql
    [[ $? == 0 ]] && echo -e "\033[32m $time mysql backup success \033[0m" >> $${log} ||  echo -e "\033[31m $time mysql backup failed \033[0m" >> ${log}
done

find ${backdir} -name "*.sql.gz" -mtime +15 -type f -exec rm -rf {} \;
[[ $? == 0 ]] && echo -e "\033[32m $time mysql rmdir success \033[0m" >> ${log} ||  echo -e "\033[31m $time mysql rmdir failed \033[0m" >> ${log}

# chmod a+x /data/backup_mysql/mysqlbackup.sh
# 00 4 * * * /usr/bin/sh /data/backup_mysql/mysqlbackup.sh > /dev/null 2>&1
# systemctl restart crond.service

# 备份文件解压缩命令:gunzip ${db}_${time}.sql.gz,此时会出现一个以sql结尾的文件