当前位置:网站首页>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 ~
边栏推荐
- 03个人研发的产品及推广-计划服务配置器V3.0
- Debug and run the first xv6 program
- Remote code execution penetration test - B module test
- Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
- Detailed explanation of data types of MySQL columns
- Final review of information and network security (based on the key points given by the teacher)
- Spark calculation operator and some small details in liunx
- Hongmeng introduction and development environment construction
- 06 products and promotion developed by individuals - code statistical tools
- Summary of Android interview questions of Dachang in 2022 (I) (including answers)
猜你喜欢

How does wechat prevent withdrawal come true?

Establishment of graphical monitoring grafana

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

Unity粒子特效系列-闪星星的宝箱

Interpretation of Flink source code (II): Interpretation of jobgraph source code

EasyCVR电子地图中设备播放器loading样式的居中对齐优化

The problem of "syntax error" when uipath executes insert statement is solved

06个人研发的产品及推广-代码统计工具
![[ASM] introduction and use of bytecode operation classwriter class](/img/0b/87c9851e577df8dcf8198a272b81bd.png)
[ASM] introduction and use of bytecode operation classwriter class

The NTFS format converter (convert.exe) is missing from the current system
随机推荐
Automatic operation and maintenance sharp weapon ansible Playbook
Xin'an Second Edition: Chapter 12 network security audit technology principle and application learning notes
EasyCVR授权到期页面无法登录,该如何解决?
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
【ASM】字节码操作 ClassWriter 类介绍与使用
中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障
Flink parsing (V): state and state backend
Compile and build, from the bottom to the top
当前系统缺少NTFS格式转换器(convert.exe)
Re signal writeup
MySQL error reporting solution
Summary of Android interview questions of Dachang in 2022 (II) (including answers)
The solution that flutterweb browser cannot be rolled back after refreshing
pip install pyodbc : ERROR: Command errored out with exit status 1
Kernel link script parsing
Final review of information and network security (full version)
Concept and basic knowledge of network layering
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
The NTFS format converter (convert.exe) is missing from the current system
远程代码执行渗透测试——B模块测试