当前位置:网站首页>MySQL 8 sub database and table backup database shell script
MySQL 8 sub database and table backup database shell script
2022-07-06 17:44:00 【Oh, no, I forgot my paper】
Don't bullshit Directly upload script content
Type of operating system :Linux centos7.6
Database version :MySQL8.0.21
The script is as follows
vim mysqldump.sh
#!/bin/bash
date=`date +'%Y-%m-%d'`
/usr/bin/expect <<-EOF
spawn sh -c "/usr/bin/mysql -h 192.168.74.4 -ushilu -p -e 'show databases' > /data/database.txt"
expect "Enter password:"
send "Shilu2021!\r"
expect EOF
EOF
Db=`cat /data/database.txt|grep -v Database`
for data in $Db
do
[ -d /data/$date/ ] || mkdir -pv /data/$date
/usr/bin/expect <<-EOF
spawn sh -c "/usr/bin/mysqldump -h 192.168.74.4 -ushilu -p $data > /data/$date/${data}.sql"
expect "Enter password:"
send "Shilu2021!\r"
expect EOF
EOF
/usr/bin/expect <<-EOF
spawn sh -c "/usr/bin/mysql -h 192.168.74.4 -ushilu -p -e 'show tables from $data' > /data/table_list"
expect "Enter password:"
send "Shilu2021!\r"
expect EOF
EOF
Tb=`cat /data/table_list|grep -v Tables`
[ -d /data/$date/$data/ ] || mkdir -pv /data/$date/$data/
for tb in $Tb
do
/usr/bin/expect <<-EOF
spawn sh -c "/usr/bin/mysqldump -h 192.168.74.4 -ushilu -p $data $tb > /data/$date/$data/$tb.sql"
expect "Enter password:"
send "Shilu2021!\r"
expect EOF
EOF
done
done
Then give the script execution permission and add it to crontab Just in the scheduled task ~
Script is not optimized , It may be rough ~
边栏推荐
- C# NanoFramework 点灯和按键 之 ESP32
- 【ASM】字节码操作 ClassWriter 类介绍与使用
- Unity小技巧 - 绘制瞄准准心
- 06个人研发的产品及推广-代码统计工具
- BearPi-HM_ Nano development board "flower protector" case
- 微信小程序获取手机号
- FlutterWeb浏览器刷新后无法回退的解决方案
- The most complete tcpdump and Wireshark packet capturing practice in the whole network
- 学 SQL 必须了解的 10 个高级概念
- Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
猜你喜欢

Flink parsing (VII): time window

Solr appears write Lock, solrexception: could not get leader props in the log

Deploy flask project based on LNMP

基于LNMP部署flask项目

07个人研发的产品及推广-人力资源信息管理系统

Final review of information and network security (full version)

中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障

面试突击62:group by 有哪些注意事项?

EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?

2022年大厂Android面试题汇总(一)(含答案)
随机推荐
04个人研发的产品及推广-数据推送工具
PySpark算子处理空间数据全解析(5): 如何在PySpark里面使用空间运算接口
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障
How to use scroll bars to dynamically adjust parameters in opencv
MySQL error reporting solution
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
遠程代碼執行滲透測試——B模塊測試
2022年大厂Android面试题汇总(一)(含答案)
Pytorch extract middle layer features?
Debug xv6
MySQL basic addition, deletion, modification and query of SQL statements
EasyRE WriteUp
connection reset by peer
Basic configuration and use of spark
05 personal R & D products and promotion - data synchronization tool
The solution to the left-right sliding conflict caused by nesting Baidu MapView in the fragment of viewpager
Example of batch update statement combining update and inner join in SQL Server
Based on infragistics Document. Excel export table class
面试突击63:MySQL 中如何去重?