当前位置:网站首页>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 ~
边栏推荐
- [translation] principle analysis of X Window Manager (I)
- Spark accumulator and broadcast variables and beginners of sparksql
- 03 products and promotion developed by individuals - plan service configurator v3.0
- 集成开发管理平台
- 【ASM】字节码操作 ClassWriter 类介绍与使用
- 面试突击62:group by 有哪些注意事项?
- 07 personal R & D products and promotion - human resources information management system
- 自动化运维利器-Ansible-Playbook
- Deploy flask project based on LNMP
- Integrated development management platform
猜你喜欢

node の SQLite

学 SQL 必须了解的 10 个高级概念

面试突击63:MySQL 中如何去重?

FlutterWeb浏览器刷新后无法回退的解决方案

C version selenium operation chrome full screen mode display (F11)

C WinForm series button easy to use

yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本

2022年大厂Android面试题汇总(二)(含答案)

集成开发管理平台

Huawei certified cloud computing hica
随机推荐
pip install pyodbc : ERROR: Command errored out with exit status 1
Sqoop I have everything you want
Redis quick start
Xin'an Second Edition: Chapter 25 mobile application security requirements analysis and security protection engineering learning notes
面试突击62:group by 有哪些注意事项?
Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)
Distributed (consistency protocol) leader election (dotnext.net.cluster implements raft election)
PyTorch 提取中间层特征?
Single responsibility principle
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
Flink analysis (II): analysis of backpressure mechanism
Vscode matches and replaces the brackets
02 personal developed products and promotion - SMS platform
Run xv6 system
C# NanoFramework 点灯和按键 之 ESP32
Final review of information and network security (based on the key points given by the teacher)
Essai de pénétration du Code à distance - essai du module b
CTF reverse entry question - dice
Re signal writeup
node の SQLite