当前位置:网站首页>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 ~
边栏推荐
- yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
- 05个人研发的产品及推广-数据同步工具
- [rapid environment construction] openharmony 10 minute tutorial (cub pie)
- EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
- Xin'an Second Edition: Chapter 12 network security audit technology principle and application learning notes
- Flink analysis (II): analysis of backpressure mechanism
- 【MySQL入门】第一话 · 初入“数据库”大陆
- Application service configurator (regular, database backup, file backup, remote backup)
- Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
- Automatic operation and maintenance sharp weapon ansible Foundation
猜你喜欢

Automatic operation and maintenance sharp weapon ansible Foundation

Vscode matches and replaces the brackets

The most complete tcpdump and Wireshark packet capturing practice in the whole network

Final review of information and network security (based on the key points given by the teacher)

05个人研发的产品及推广-数据同步工具

应用服务配置器(定时,数据库备份,文件备份,异地备份)

Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘

Summary of Android interview questions of Dachang in 2022 (I) (including answers)

EasyCVR授权到期页面无法登录,该如何解决?

FlutterWeb瀏覽器刷新後無法回退的解决方案
随机推荐
05 personal R & D products and promotion - data synchronization tool
The art of Engineering (1): try to package things that do not need to be exposed
MySQL basic addition, deletion, modification and query of SQL statements
集成开发管理平台
Application service configurator (regular, database backup, file backup, remote backup)
Example of batch update statement combining update and inner join in SQL Server
全网最全tcpdump和Wireshark抓包实践
Wordcloud colormap color set and custom colors
OpenCV中如何使用滚动条动态调整参数
EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
Models used in data warehouse modeling and layered introduction
FlutterWeb浏览器刷新后无法回退的解决方案
DataGridView scroll bar positioning in C WinForm
[reverse] repair IAT and close ASLR after shelling
MySQL advanced (index, view, stored procedure, function, password modification)
Unity小技巧 - 绘制瞄准准心
06个人研发的产品及推广-代码统计工具
远程代码执行渗透测试——B模块测试
Grafana 9 正式发布,更易用,更酷炫了!
【MySQL入门】第三话 · MySQL中常见的数据类型