当前位置:网站首页>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 ~
边栏推荐
- Grafana 9 is officially released, which is easier to use and more cool!
- About selenium starting Chrome browser flash back
- DataGridView scroll bar positioning in C WinForm
- 【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符
- Spark calculation operator and some small details in liunx
- EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
- 应用服务配置器(定时,数据库备份,文件备份,异地备份)
- 学 SQL 必须了解的 10 个高级概念
- 05 personal R & D products and promotion - data synchronization tool
- TCP连接不止用TCP协议沟通
猜你喜欢
Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
07 personal R & D products and promotion - human resources information management system
Establishment of graphical monitoring grafana
Interpretation of Flink source code (II): Interpretation of jobgraph source code
【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
虚拟机启动提示Probing EDD (edd=off to disable)错误
Deploy flask project based on LNMP
SAP UI5 框架的 manifest.json
Solr appears write Lock, solrexception: could not get leader props in the log
Vscode matches and replaces the brackets
随机推荐
07 personal R & D products and promotion - human resources information management system
The solution that flutterweb browser cannot be rolled back after refreshing
[reverse primary] Unique
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
C#WinForm中的dataGridView滚动条定位
Grafana 9 正式发布,更易用,更酷炫了!
FlutterWeb瀏覽器刷新後無法回退的解决方案
Development and practice of lightweight planning service tools
Final review of information and network security (full version)
[ciscn 2021 South China]rsa writeup
The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
pip install pyodbc : ERROR: Command errored out with exit status 1
MySQL报错解决
[translation] principle analysis of X Window Manager (I)
MySQL error reporting solution
07个人研发的产品及推广-人力资源信息管理系统
Openharmony developer documentation open source project
遠程代碼執行滲透測試——B模塊測試