当前位置:网站首页>Linux MySQL data timing dump
Linux MySQL data timing dump
2022-04-23 16:49:00 【A coir boat in the broken white clouds】
One 、 Back up the database script file
#!/bin/sh
# Database account information
DB_USER="root"
DB_PWD="123456"
DB_HOST="192.168.110.195"
DB_PORT="3305"
# MYSQL In the directory
MYSQL_DIR="/usr/local/mysql"
# Backup file storage directory
BAK_DIR="/data/backups"
# Time format , Such as 20200902
DATE=`date +%Y%m%d`
# The number of days the backup script is saved
DEL_DAY=10
# Database to back up , The blank space to separate
DATABASES=("sales_release")
# Create date directory
mkdir $BAK_DIR/$DATE
echo "-------------------$(date +%F_%T) start ---------------" >>${BAK_DIR}/aggrega
te_backup.log
for database in "${DATABASES[@]}"
do
# Execute backup command
$MYSQL_DIR/bin/mysqldump --opt -u$DB_USER -p$DB_PWD -h$DB_HOST -P$DB_PORT ${database} > $BAK_DIR/$DATE/${database}.sql
done
echo "--- backup file created: $BAK_DIR/aggregate_backup_$DATE.tar.gz" >>${BAK_DIR}/aggregate_backup.log
# Back up the good sql The script is compressed to aggregate_backup_yyyyMMdd.tar.gz
tar -czf $BAK_DIR/aggregate_backup_$DATE.tar.gz $BAK_DIR/$DATE
# After the compression , Delete backup files and directories before compression
rm -f $BAK_DIR/$DATE/*
rmdir $BAK_DIR/$DATE
# So far, the backup operation has been completed , The following script command is used to clean up the old files backed up before , To free up disk space
# Traverse the compressed files in the backup directory
LIST=$(ls ${
BAK_DIR}/aggregate_backup_*)
# obtain 10 The day before , Used for comparison , Files older than this time will be deleted
SECONDS=$(date -d "$(date +%F) -${DEL_DAY} days" +%s) for index in ${LIST} do # Format the file name , Take the time at the end of the name , The format is as follows 20200902 timeString=$(echo ${
index} | egrep -o "?[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]") if [ -n "$timeString" ]
then
indexDate=${timeString//./-}
indexSecond=$( date -d ${
indexDate} +%s )
# Compare with the time of the day , Earlier than 10 Days of backup file deletion
if [ $(( $SECONDS- $indexSecond )) -gt 0 ]
then
rm -f $index
echo "---- deleted old backup file : $index " >>${BAK_DIR}/aggregate_backup.log
fi
fi
done
echo "-------------------$(date +%F_%T) end ---------------" >>${BAK_DIR}/aggregate_backup.log
Be careful : If it is Windows The document was sent directly to Linux Need to convert the format
sed -i 's/\r$//' aggregateBak.sh
Two 、 Give the script permission to execute
chmod 777 aggregateBak.sh
3、 ... and 、 utilize Linux Systematic crontab Timing task , To automatically execute scripts at a fixed time
crontab -e # edit
# Enter the following code
00 03 * * * /data/mysql_aggregate/aggregateBak.sh# stay 03:00 a.m function
:wq # Save and exit
service crond restart # Restart the service , If it is ubuntu System , It is cron
Backup is a good habit , A habit that won't make you lose money
版权声明
本文为[A coir boat in the broken white clouds]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231400068254.html
边栏推荐
- Phpstudy V8, a commonly used software for station construction 1 graphic installation tutorial (Windows version) super detailed
- Creation of RAID disk array and RAID5
- 网络安全之渗透靶场实战详解
- Do you really understand the principle of code scanning login?
- ◰GL-阴影贴图核心步骤
- DanceNN:字节自研千亿级规模文件元数据存储系统概述
- The font of the soft cell changes color
- Pytorch: the pit between train mode and eval mode
- Nacos detailed explanation, something
- The first line and the last two lines are frozen when paging
猜你喜欢
Detailed explanation of information abstract, digital signature, digital certificate, symmetric encryption and asymmetric encryption
Query the data from 2013 to 2021, and only query the data from 2020. The solution to this problem is carried out
Do you really understand the principle of code scanning login?
LVM and disk quota
English | day15, 16 x sentence true research daily sentence (clause disconnection, modification)
扫码登录的原理你真的了解吗?
Use case labeling mechanism of robot framework
Real time operation of vim editor
RTKLIB 2.4.3源码笔记
Loggie source code analysis source file module backbone analysis
随机推荐
Introduction to how to set up LAN
Calculate pie chart percentage
5-minute NLP: text to text transfer transformer (T5) unified text to text task model
ByteVCharts可视化图表库,你想要的我都有
批量制造测试数据的思路,附源码
Gartner 发布新兴技术研究:深入洞悉元宇宙
Kunteng full duplex digital wireless transceiver chip kt1605 / kt1606 / kt1607 / kt1608 is suitable for interphone scheme
Use case labeling mechanism of robot framework
vim编辑器的实时操作
Use case execution of robot framework
TypeError: set_ figure_ params() got an unexpected keyword argument ‘figsize‘
Deepinv20 installation MariaDB
Pseudo Distributed installation spark
Set the color change of interlaced lines in cells in the sail software and the font becomes larger and red when the number is greater than 100
如何用Redis实现分布式锁?
磁盘管理与文件系统
Sail soft calls the method of dynamic parameter transfer and sets parameters in the title
Zhimeng dedecms security setup Guide
安装及管理程序
How magical is the unsafe class used by all major frameworks?