当前位置:网站首页>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 ~
边栏推荐
- 【MySQL入门】第三话 · MySQL中常见的数据类型
- C # nanoframework lighting and key esp32
- MySQL basic addition, deletion, modification and query of SQL statements
- The problem of "syntax error" when uipath executes insert statement is solved
- Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
- EasyCVR电子地图中设备播放器loading样式的居中对齐优化
- [translation] principle analysis of X Window Manager (I)
- [elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
- The art of Engineering (1): try to package things that do not need to be exposed
- TCP connection is more than communicating with TCP protocol
猜你喜欢
04个人研发的产品及推广-数据推送工具
The most complete tcpdump and Wireshark packet capturing practice in the whole network
视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
Unity tips - draw aiming Center
About selenium starting Chrome browser flash back
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
面试突击62:group by 有哪些注意事项?
C # nanoframework lighting and key esp32
Automatic operation and maintenance sharp weapon ansible Foundation
Summary of Android interview questions of Dachang in 2022 (I) (including answers)
随机推荐
Sqoop I have everything you want
How to submit data through post
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
FlutterWeb瀏覽器刷新後無法回退的解决方案
How does wechat prevent withdrawal come true?
PySpark算子处理空间数据全解析(4): 先说说空间运算
自动化运维利器ansible基础
MySQL basic addition, deletion, modification and query of SQL statements
Remote code execution penetration test - B module test
Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
The solution to the left-right sliding conflict caused by nesting Baidu MapView in the fragment of viewpager
The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
虚拟机启动提示Probing EDD (edd=off to disable)错误
Vscode replaces commas, or specific characters with newlines
06个人研发的产品及推广-代码统计工具
[getting started with MySQL] fourth, explore operators in MySQL with Kiko
Flink parsing (IV): recovery mechanism
DataGridView scroll bar positioning in C WinForm
Final review of information and network security (full version)
FlutterWeb浏览器刷新后无法回退的解决方案