当前位置:网站首页>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
边栏推荐
- MySQL master-slave synchronization pit avoidance version tutorial
- 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
- Nifi fast installation and file synchronization
- 众昂矿业:萤石浮选工艺
- Query the data from 2013 to 2021, and only query the data from 2020. The solution to this problem is carried out
- Path environment variable
- Nodejs installation and environment configuration
- [pyGame games] how did angry birds, a mobile game that became popular all over the world 10 years ago, dominate the list? Classic return
- How vscode compares the similarities and differences between two files
- Do you really understand the principle of code scanning login?
猜你喜欢
MySql主从复制
漫画:什么是IaaS、PaaS、SaaS?
计组 | 【七 输入/输出系统】知识点与例题
Mock test using postman
org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su
人脸识别框架之dlib
How to choose the wireless gooseneck anchor microphone and handheld microphone scheme
Dlib of face recognition framework
Path environment variable
The first line and the last two lines are frozen when paging
随机推荐
Introduction notes to PHP zero Foundation (13): array related functions
Real time operation of vim editor
An essay on the classical "tear down the wall in thinking"
Encapsulating the logging module
Quick install mongodb
05 Lua 控制结构
Dlib of face recognition framework
How to build tiktok user trust and drive fan growth
100 deep learning cases | day 41 - convolutional neural network (CNN): urbansound 8K audio classification (speech recognition)
批量制造测试数据的思路,附源码
On the security of key passing and digital signature
拷贝构造函数 浅拷贝与深拷贝
Phpstudy V8, a commonly used software for station construction 1 graphic installation tutorial (Windows version) super detailed
正则过滤内网地址和网段
Construction of promtail + Loki + grafana log monitoring system
How does flash cache data in memory?
博士申请 | 厦门大学信息学院郭诗辉老师团队招收全奖博士/博后/实习生
Loggie source code analysis source file module backbone analysis
Sail soft calls the method of dynamic parameter transfer and sets parameters in the title
Detailed explanation of information abstract, digital signature, digital certificate, symmetric encryption and asymmetric encryption