当前位置:网站首页>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 :

边栏推荐
- 1704. judge whether the two halves of a string are similar
- uniapp 开发多端项目如何配置环境变量以及区分环境打包
- 小程序云数据,数据请求一个集合数据的方法
- [pytorch basic tutorial 30] code analysis of DSSM twin tower model
- GradScaler MaxClipGradScaler
- Deep learning and neural networks: the six most noteworthy trends
- JS to find and update the specified value in the object through the key
- Qingcloud based "real estate integration" cloud solution
- [pytoch basic tutorial 31] youtubednn model analysis
- 数据中台:数据采集和抽取的技术栈详解
猜你喜欢

OpenCV每日函数 结构分析和形状描述符(7) 寻找多边形(轮廓)/旋转矩形交集

Qingcloud based "real estate integration" cloud solution

WebRTC系列-网络传输之5选择最优connection切换

Prompt code when MySQL inserts Chinese data due to character set problems: 1366

YOLOX backbone——CSPDarknet的实现

【Pytorch基础教程31】YoutubeDNN模型解析

Mysql数据(Liunx环境)定时备份

uniapp 开发多端项目如何配置环境变量以及区分环境打包

Transplantation of xuantie e906 -- fanwai 0: Construction of xuantie c906 simulation environment

数云发布2022美妆行业全域消费者数字化经营白皮书:全域增长破解营销难题
随机推荐
2022 spring recruitment interview summary
数据中台:数据采集和抽取的技术栈详解
2020中国全国各省市,三级联动数据,数据机构(数据来自国家统计局官网)
A tip to read on Medium for free
Spark - LeftOuterJoin 结果条数与左表条数不一致
[pytorch basic tutorial 30] code analysis of DSSM twin tower model
Data middle office: a collection of middle office construction architectures of large domestic factories
From the Huawei weautomate digital robot forum, we can see the "new wisdom of government affairs" in the field of government and enterprises
Scheme of alcohol concentration tester based on single chip microcomputer
阿里资深软件测试工程师推荐测试人员必学——安全测试入门介绍
【E325: ATTENTION】vim编辑时报错
4274. suffix expression
Database migration from PostgreSQL to MySQL
Opencv daily function structure analysis and shape descriptor (7) finding polygon (contour) / rotating rectangle intersection
Data midrange: analysis of full stack technical architecture of data midrange, with industry solutions
1704. judge whether the two halves of a string are similar
用VNC Viewer的方式远程连接无需显示屏的树莓派
[team management] 25 tips for testing team performance management
听说你还在花钱从网上买 PPT 模板?
Huawei Router: GRE Technology