当前位置:网站首页>Multi database and multi table backup and restore of MySQL under Linux
Multi database and multi table backup and restore of MySQL under Linux
2022-06-25 20:55:00 【Gem, Chaochao】
One 、 Write a bash Script files
1、 Create directory
Create a file directory in the root directory
1) The scripts directory
[[email protected] /]#mkdir scripts/
2) Backup file directory
[[email protected] /]#mkdir -p server/backup/
2、 establish bash Script files
[[email protected] /]#cd /scripts/
[[email protected] scripts]#vim mysqldump1.sh
The contents of the document are as follows :
#!bin/bash
USER=root
PASSWD=root
SOCKET=/software/mysql/mysql.sock
LOGIN="mysql -u$USER -p$PASSWD -S $SOCKET"
DUMP="mysqldump --no-defaults -u$USER -p$PASSWD -S $SOCKET"
DATABASE=$($LOGIN -e "show databases;"|egrep -v "*chema|mysql|sys"|sed '1d')
for database in $DATABASE
do
TABLE=$($LOGIN -e "use $database;show tables;"|sed '1d')
for table in $TABLE
do
[ -d /server/backup/$database ] || mkdir /server/backup/$database -p
$DUMP $database $table |gzip >/server/backup/$database/${database}_${table}_$(date +%F).sql.gz
done
done
3、 Perform backup operations
[[email protected] /]#cd /scripts/
[[email protected] scripts]#sh mysqldump1.sh
Two 、 Extract files and restore databases
[[email protected] /]# cd /server/backup/
[[email protected] backup]# ll
Total usage 0
drwxr-xr-x. 2 root root 109 4 month 30 15:29 test_interface
[[email protected] backup]# cd test_interface/
[[email protected] test_interface]# ll
Total usage 4
-rw-r--r--. 1 root root 855 4 month 30 15:29 test_interface_config_total_2021-04-30.sql.gz
[[email protected] test_interface]#gunzip <test_interface_config_total_2021-04-30.sql.gz | mysql -uroot -proot test_interface
mysql: [Warning] Using a password on the command line interface can be insecure.
边栏推荐
- Why doesn't anyone read your hard-working blog? Do you really understand the skills of framing, typesetting and drawing?
- PIP command -fatal error in launcher: unable to create process using How to resolve the error after migrating the virtual environment?
- Inventory - those automated test interview questions you can't help but know
- "Space guard soldier" based on propeller -- geosynchronous geostationary orbit space target detection system
- Lesson 3 urllib
- Lesson 4 beautifulsoup
- Understand the offline mixing technology in the industry
- Introduction to event flow, event capture, and event bubbling
- [deep learning series] - visual interpretation of neural network
- Vbpr (visual Bayesian personalized ranking) paper summary
猜你喜欢
Openocd adds third-party device support: ht32f52352 Cortex-M0+
Idea implements hot deployment
Jingxi Pinpin wechat applet -signstr parameter encryption
1.1-mq visual client preliminary practice
Flexible scale out: from file system to distributed file system
Feature Engineering in simple terms – a practice guide based on openmldb (Part 1)
Chrome plugin installation
Cvpr2020 | the latest cvpr2020 papers are the first to see, with all download links attached!
After 20 days' interview, I finally joined Ali (share the interview process)
R language quantile autoregressive QAR analysis pain index: time series of unemployment rate and inflation rate
随机推荐
Get the root directory of the package at compile time from buildreoot
Redis core principle and design idea
Shell scripts: Variables
5 minutes to learn how to install MySQL
Exploration of advanced document editor design in online Era
CSDN sign in cash reward
How to view and explain robots protocol
Nmap is simple and practical
2022 oceanbase technical essay contest officially opened | come and release your force
Analysis and cleaning of kdevtmpfsi virus content
hashlib. Md5() function to filter out duplicate system files and remove them
Cloud native 04: use envoy + open policy agent as the pre agent
OLED driver learning based on ssd1306 (I): SSD Chinese command table (handling)
How to close gracefully after using jedis
Getting started and using postman
Desktop network error display red ×, Component failed to start
Unable to connect to the server remotely locally using the Jupiter notebook
What is machine learning? (Fundamentals)
Molecular dynamics - basic characteristics of molecular force field
Live broadcast preview | front line experts invite you to talk: the value of data science enabling multiple application scenarios