当前位置:网站首页>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
边栏推荐
- Nodejs installation and environment configuration
- 网络安全之渗透靶场实战详解
- 面试百分百问到的进程,你究竟了解多少
- 众昂矿业:萤石浮选工艺
- Project framework of robot framework
- Introduction notes to PHP zero Foundation (13): array related functions
- MySQL master-slave synchronization pit avoidance version tutorial
- 关于局域网如何组建介绍
- 欣旺达:HEV和BEV超快充拳头产品大规模出货
- Talk about browser cache control
猜你喜欢
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
文件操作详解(2)
漫画:什么是IaaS、PaaS、SaaS?
TypeError: set_figure_params() got an unexpected keyword argument ‘figsize‘
Use case execution of robot framework
面试百分百问到的进程,你究竟了解多少
Gartner 發布新興技術研究:深入洞悉元宇宙
Smart doc + Torna generate interface document
How much do you know about the process of the interview
Nifi fast installation and file synchronization
随机推荐
On the security of key passing and digital signature
logback的配置文件加载顺序
Do you really understand the principle of code scanning login?
ByteVCharts可视化图表库,你想要的我都有
MySQL master-slave synchronization pit avoidance version tutorial
TypeError: set_figure_params() got an unexpected keyword argument ‘figsize‘
Blue Bridge Cup provincial road 06 -- the second game of the 12th provincial competition
04 Lua 运算符
JMeter installation tutorial and solutions to the problems I encountered
拷贝构造函数 浅拷贝与深拷贝
Detailed explanation of file operation (2)
Take according to the actual situation, classify and summarize once every three levels, and see the figure to know the demand
Camtasia2022软件新增功能介绍
vscode如何比较两个文件的异同
LVM and disk quota
漫画:什么是IaaS、PaaS、SaaS?
面试百分百问到的进程,你究竟了解多少
Mock test
Zhimeng dedecms security setup Guide
STM32__03—初识定时器