当前位置:网站首页>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 ~
边栏推荐
- Flink parsing (III): memory management
- 06 products and promotion developed by individuals - code statistical tools
- 自动化运维利器ansible基础
- How to submit data through post
- Spark accumulator and broadcast variables and beginners of sparksql
- 灵活报表v1.0(简单版)
- Xin'an Second Edition; Chapter 11 learning notes on the principle and application of network physical isolation technology
- Wordcloud colormap color set and custom colors
- Error: Publish of Process project to Orchestrator failed. The operation has timed out.
- Xin'an Second Edition: Chapter 12 network security audit technology principle and application learning notes
猜你喜欢

How to use scroll bars to dynamically adjust parameters in opencv

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

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

RepPoints:可形变卷积的进阶

Application service configurator (regular, database backup, file backup, remote backup)

Deploy flask project based on LNMP

Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first

How does wechat prevent withdrawal come true?

07 personal R & D products and promotion - human resources information management system

【ASM】字节码操作 ClassWriter 类介绍与使用
随机推荐
OpenCV中如何使用滚动条动态调整参数
Example of batch update statement combining update and inner join in SQL Server
The art of Engineering
虚拟机启动提示Probing EDD (edd=off to disable)错误
SAP UI5 框架的 manifest.json
mysql高級(索引,視圖,存儲過程,函數,修改密碼)
[reverse primary] Unique
Automatic operation and maintenance sharp weapon ansible Foundation
About selenium starting Chrome browser flash back
Hongmeng introduction and development environment construction
Unity小技巧 - 绘制瞄准准心
【MySQL入门】第三话 · MySQL中常见的数据类型
07 personal R & D products and promotion - human resources information management system
The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
Flink analysis (I): basic concept analysis
MySQL stored procedure
Reppoints: advanced order of deformable convolution
Precipitated database operation class - version C (SQL Server)
Flink parsing (III): memory management
Grafana 9 is officially released, which is easier to use and more cool!