当前位置:网站首页>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 ~
边栏推荐
- 06 products and promotion developed by individuals - code statistical tools
- Error: Publish of Process project to Orchestrator failed. The operation has timed out.
- EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
- Redis quick start
- 遠程代碼執行滲透測試——B模塊測試
- Application service configurator (regular, database backup, file backup, remote backup)
- Binary search strategy
- 分布式不来点网关都说不过去
- The NTFS format converter (convert.exe) is missing from the current system
- 中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障
猜你喜欢
2022年大厂Android面试题汇总(二)(含答案)
C# NanoFramework 点灯和按键 之 ESP32
Unity小技巧 - 绘制瞄准准心
Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
Spark accumulator and broadcast variables and beginners of sparksql
Development and practice of lightweight planning service tools
Selenium test of automatic answer runs directly in the browser, just like real users.
Wordcloud colormap color set and custom colors
SAP UI5 框架的 manifest.json
随机推荐
Virtual machine startup prompt probing EDD (edd=off to disable) error
Display picture of DataGridView cell in C WinForm
04个人研发的产品及推广-数据推送工具
[getting started with MySQL] fourth, explore operators in MySQL with Kiko
[ciscn 2021 South China]rsa writeup
Interpretation of Flink source code (II): Interpretation of jobgraph source code
Flink parsing (VII): time window
[ASM] introduction and use of bytecode operation classwriter class
Redis quick start
C WinForm series button easy to use
Re signal writeup
[reverse] repair IAT and close ASLR after shelling
当前系统缺少NTFS格式转换器(convert.exe)
BearPi-HM_ Nano development board "flower protector" case
微信小程序获取手机号
Single responsibility principle
pip install pyodbc : ERROR: Command errored out with exit status 1
How uipath determines that an object is null
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
The problem of "syntax error" when uipath executes insert statement is solved