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

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Vulnerabilities – Threatpost
Cloudbric
Cloudbric
G
GRAHAM CLULEY
S
Securelist
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
Spread Privacy
Spread Privacy
P
Privacy International News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
T
Tailwind CSS Blog
博客园_首页
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
T
Tor Project blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Attack and Defense Labs
Attack and Defense Labs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
O
OpenAI News
J
Java Code Geeks
T
Tenable Blog
K
Kaspersky official blog
AWS News Blog
AWS News Blog
S
Security @ Cisco Blogs
The GitHub Blog
The GitHub Blog
T
Threatpost
月光博客
月光博客
H
Heimdal Security Blog
Security Latest
Security Latest
The Hacker News
The Hacker News
Y
Y Combinator Blog
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
C
CERT Recently Published Vulnerability Notes
D
Docker
Google Online Security Blog
Google Online Security Blog
D
DataBreaches.Net
V
Visual Studio Blog
H
Help Net Security

博客园 - 哈喽哈喽111111

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结尾的文件