当前位置:网站首页>MySQL data (Linux Environment) scheduled backup
MySQL data (Linux Environment) scheduled backup
2022-06-24 09:00:00 【Q z1997】
One . mysqldump Command backup data
#MySQLdump Commonly used
mysqldump -u root -p --databases database 1 database 2 > xxx.sql
Two . mysqldump Common operation examples
Back up the data and structure of all databases
mysqldump -uroot -p123456 -A > /data/mysqlDump/mydb.sql
Back up the structure of all databases ( Add -d Parameters )
mysqldump -uroot -p123456 -A -d > /data/mysqlDump/mydb.sql
Back up all database data ( Add -t Parameters )
mysqldump -uroot -p123456 -A -t > /data/mysqlDump/mydb.sql
Back up the data and structure of a single database (, Database name mydb)
mysqldump -uroot-p123456 mydb > /data/mysqlDump/mydb.sql
Backing up the structure of a single database
mysqldump -uroot -p123456 mydb -d > /data/mysqlDump/mydb.sql
Backing up data from a single database
mysqldump -uroot -p123456 mydb -t > /data/mysqlDump/mydb.sql
Backing up data and structure of multiple tables ( data , The separate backup method of the structure is the same as above )
mysqldump -uroot -p123456 mydb t1 t2 > /data/mysqlDump/mydb.sql
Backing up multiple databases at a time
mysqldump -uroot -p123456 --databases db1 db2 > /data/mysqlDump/mydb.sql
3、 ... and . Restore MySQL Backup content
mysql -uroot -p123456 < /data/mysqlDump/mydb.sql
Four . Use scripts + cron Scheduled backup
Preparation script mysql_backup_script.sh
#!/bin/bash
# Save the number of backup , Backup 31 Day data
number=31
# Backup save path
backup_dir=/usr/local/mysql/dupm
# date
dd=`date +%Y-%m-%d-%H-%M-%S`
# Backup tools own mysql Installation path
tool=/usr/local/mysql/bin/mysqldump
# user name
username=root
# password
password=root0101
# The database to be backed up
database_name=test
# If the folder does not exist, create
if [ ! -d $backup_dir ];
then
mkdir -p $backup_dir;
fi
echo "$tool -u$username -p$password $database_name > $backup_dir/$database_name-$dd.sql" >> $backup_dir/log.txt
# Simple writing mysqldump -u root -p123456 users > /root/mysqlbackup/users-$filename.sql
$tool -u$username -p$password $database_name > $backup_dir/$database_name-$dd.sql
# Write create backup log
echo "create $backup_dir/$database_name-$dd.dupm" >> $backup_dir/log.txt
# Find the backup that needs to be deleted
delfile=`ls -l -crt $backup_dir/*.sql | awk '{print $9 }' | head -1` # Determine whether the current number of backups is greater than $number count=`ls -l -crt $backup_dir/*.sql | awk '{print $9 }' | wc -l` if [ $count -gt $number ] then # Delete the earliest generated backup , Only keep number Number of backups rm $delfile # Write delete file log echo "delete $delfile" >> $backup_dir/log.txt fi To write cron Script mysqlRollback.cron
*/1 * * * * /usr/local/mysql/sh/mysql_dump_script.sh
crontab mysqlRollback.cron
Execution effect :

边栏推荐
- MySQL | 视图《康师傅MySQL从入门到高级》笔记
- Leetcode -- wrong set
- Data middle office: the data middle office practice scheme of Minsheng Bank
- 216. 组合总和 III-枚举法
- [e325: attention] VIM editing error
- [noi Simulation Competition] geiguo and time chicken (structure)
- 【LeetCode】387. 字符串中的第一个唯一字符
- 随笔-反思
- [Niuke] length of the last word of HJ1 string
- linux(centos7.9)安装部署mysql-cluster 7.6
猜你喜欢

玄铁E906移植----番外0:玄铁C906仿真环境搭建

【LeetCode】387. First unique character in string

I heard that you are still spending money to buy ppt templates from the Internet?
![[Niuke] length of the last word of HJ1 string](/img/8b/6ba6506415b8112aea957ac5647121.png)
[Niuke] length of the last word of HJ1 string

听说你还在花钱从网上买 PPT 模板?
![[team management] 25 tips for testing team performance management](/img/bd/0ef55630de43efcf5aa663f3099fce.jpg)
[team management] 25 tips for testing team performance management

4275. Dijkstra sequence

"Unusual proxy initial value setting is not supported", causes and Solutions
![[MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle](/img/db/e581087e550a2e460f12047685c48f.png)
[MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle

【牛客】把字符串转换成整数
随机推荐
Leetcode -- wrong set
Solution: Nan occurs in loss during model training
“论解不了数独所以选择做个数独游戏这件事”
[noi Simulation Competition] geiguo and time chicken (structure)
216. combined summation III enumeration method
Implementation process of tcpdump packet capturing
What is the future development trend of Business Intelligence BI
1844. replace all numbers with characters
Earthly container image construction tool -- the road to dream
[pytorch basic tutorial 30] code analysis of DSSM twin tower model
2022 spring recruitment interview summary
Mysql数据(Liunx环境)定时备份
Double pointer analog
【LeetCode】415. 字符串相加
【牛客】HJ1 字符串最后一个单词的长度
【LeetCode】541. Reverse string II
216. 组合总和 III-枚举法
Sword finger offer 55 - I. depth DFS method of binary tree
随笔-反思
Idea another line shortcut