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

推荐订阅源

Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
P
Proofpoint News Feed
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
The Last Watchdog
The Last Watchdog
F
Fortinet All Blogs
S
Schneier on Security
Help Net Security
Help Net Security
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
I
InfoQ
T
The Blog of Author Tim Ferriss
Cisco Talos Blog
Cisco Talos Blog
Stack Overflow Blog
Stack Overflow Blog
T
Troy Hunt's Blog
人人都是产品经理
人人都是产品经理
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cyber Attacks, Cyber Crime and Cyber Security
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
Forbes - Security
Forbes - Security
Vercel News
Vercel News
S
Security Affairs
美团技术团队
P
Privacy & Cybersecurity Law Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Spread Privacy
Spread Privacy
Attack and Defense Labs
Attack and Defense Labs
IT之家
IT之家
U
Unit 42
Recorded Future
Recorded Future
W
WeLiveSecurity
PCI Perspectives
PCI Perspectives
P
Palo Alto Networks Blog
H
Hacker News: Front Page
S
Security @ Cisco Blogs
博客园 - 【当耐特】

博客园 - timseng

ai辅助升级前端安全更新(贼快!hh openclaw的token又耗完了,先不冲了,记录下折腾踩坑过程 (如果需要协助安装500,帮忙卸载250[doge]) VS Code我的配置(持续更新) 推广:flowable工作流引擎就是高级版本的数据库而已(一) springboot升级3x导致邮件发送失败:错误1 jakarta.mail.NoSuchProviderException: smtp nice du更好的du分析文件占用工具ncdu 使用MITMProxy转发https请求到本地、保存鉴权给本地请求(二) 前端发布shell脚本 virtualBox环境Ubuntu升级后太卡,转debian很丝滑 收藏:加不加「/」?Nginx location 路径与 proxy_pass 的规律 使用visjs分析flowable流程数据 浏览器标签页多行显示:使用Floorp浏览器 最先进的跨平台 Firefox 衍生品 开源之光 开源WAF:ModSecurity探究与部署 动态条件实现java 使用MITMProxy转发请求到本地、保存鉴权给本地请求 这款Ubuntu的默认壁纸水母是真漂亮啊 笑死!'m not going to tell you who, but I know someone who recently locked himself out of the system he was using for an article covering iptables by forgetting the SSH rule. itext的PdfPCell中设置行间距失败的问题 Java递归函数计算递归次数出错
mysql备份恢复云端之核心:更新扫描MySQL库里的所有表的UPDATE_TIME,若发生变动就mysqldump
timseng · 2024-07-12 · via 博客园 - timseng

背景

#!/bin/bash

# MySQL连接信息
MYSQL_USER="root"
MYSQL_PASSWORD="123!"
MYSQL_DATABASE="dev_flow_table"
# 记录上次查询的更新时间的文件
LAST_RESULT_FILE="last_result.txt"
CURRENT_RESULT_FILE="current_result.txt"
DUMP_FILE="database_dump.sql"


# 初始化当前结果文件
> $CURRENT_RESULT_FILE

# 如果上次检查时间文件不存在,则创建一个新的文件
if [ ! -f "$LAST_RESULT_FILE" ]; then
    touch "$LAST_RESULT_FILE"
fi

# 获取当前时间戳
CURRENT_TIME=$(date +%s)

# 获取所有表名
TABLES=$(mysql -h 127.0.0.1 -u"$MYSQL_USER" --password="$MYSQL_PASSWORD" -D "$MYSQL_DATABASE" -e "SHOW TABLES;"  2>/dev/null | tail -n +2)

# 遍历每个表
for TABLE in $TABLES; do
    echo "check Table $TABLE"

    # 获取表的最近更新时间
    mysql -h 127.0.0.1 -u"$MYSQL_USER" --password="$MYSQL_PASSWORD" -D "$MYSQL_DATABASE" -e "ANALYZE TABLE $MYSQL_DATABASE.$TABLE ;"   >/dev/null 2>&1
    UPDATE_TIME=$(mysql -h 127.0.0.1 -u"$MYSQL_USER" --password="$MYSQL_PASSWORD" -D "$MYSQL_DATABASE" -e "SELECT UPDATE_TIME FROM information_schema.TABLES WHERE TABLE_SCHEMA='$MYSQL_DATABASE' AND TABLE_NAME='$TABLE';"  2>/dev/null | tail -n +2)
    
    # 从上次查询的更新时间文件中读取上次更新时间
    LAST_UPDATE_TIME=$(grep "^$TABLE  "  "$LAST_RESULT_FILE" | awk -F '  ' '{print $2}')

    # 如果表的更新时间大于上次查询的更新时间,则备份数据
    if [ "$UPDATE_TIME" != "$LAST_UPDATE_TIME" ]; then
        echo "Table $TABLE has been updated. $LAST_UPDATE_TIME to $UPDATE_TIME Performing backup....................."
        
        # 更新上次查询的更新时间文件(追加方式)
        # echo "$TABLE  $UPDATE_TIME" >> "$CURRENT_RESULT_FILE"
    fi
    # 记录 之后对比用
    echo "$TABLE  $UPDATE_TIME" >> "$CURRENT_RESULT_FILE"
done

# 比较当前结果和上次结果
if ! cmp -s $CURRENT_RESULT_FILE $LAST_RESULT_FILE; then
  # 结果不同,执行 mysqldump
  # mysqldump -u$DB_USER --password=$DB_PASSWORD $DB_NAME  2>/dev/null > $DUMP_FILE
  echo "Database dumped to $DUMP_FILE"

  # 更新上次结果文件
  cp $CURRENT_RESULT_FILE $LAST_RESULT_FILE
else
  echo "No changes detected."
fi

# 清理当前结果文件
# rm $CURRENT_RESULT_FILE
echo "Table update check and backup process completed."

posted @ 2024-07-12 19:59  timseng  阅读(37)  评论()    收藏  举报