当前位置:网站首页>Linux scheduled database backup script
Linux scheduled database backup script
2022-07-23 14:52:00 【Gerald pick Xie】
inux Scheduled database backup script
Create script
- Create script ( There are notes in the document )
vim dbName.sh
- vim Use
iInsert:Enter the command
#!/bin/bash
# Backup directory
BACKUP=/home/mysqlBackup/db_name
# Get the current time
DATATIME=$(date +'%Y-%m-%d_%H%M%S')
# Print time
echo $DATATIME
# Database address
HOST=localhost
# Database user name
DB_USER=root
# Database password
DB_PW=123456
# Backup database name
DATABASE=db_name
# Create backup directory , If it doesn't exist, create it
[ ! -d "${BACKUP}/${DATATIME}/${DATATIME}" ] && mkdir -p "${BACKUP}/${DATATIME}"
# Backup database
mysqldump -u${
DB_USER} -p${
DB_PW} --host=${
HOST} -q -R --databases ${
DATABASE} | gzip > ${
BACKUP}/${
DATETIME}/$DATABASE.sql.gz
# Process files into tar.gz
cd ${
BACKUP}
tar -zcvf $DATABASE.tar.gz ${
DATATIME}
# Delete the corresponding backup directory
rm -rf ${
BACKUP}/${
DATATIME}
# Delete 10 Days ago backup files
find ${
BACKUP} -atime +30 -name "+.tar.gz" -exec rm -rf {
} \;
echo " Backup database ${DATABASE} success ~"
Set the timing
- Enter the command
crontab -e/ Path address
1. Expressed as a number Time information
00 02 * * * Backup file
2. Use special symbols to represent time information
* * * * * Backup file
/ minute / Hours / God / month / Zhou
=========================================
PS: The shortest execution cycle of a scheduled task is Every minute
*/5 */ 6 */3 */1 */2
every other 5 minute every other 6 Hours every other 3 Japan every other 1 month every other 2 Zhou
=========================================
Other How to write it :
01-05 02 * * * Every time 2 Japanese 01、02、03、04、05 Do it again
Specify a discontinuous time range :
00 14,20 * * * * Every day 14 spot ,20 Click to execute once
边栏推荐
- First acquaintance and search set
- Zhongwang CAD professional 2022 software installation package download and installation tutorial
- 【无标题】
- 【软件测试】盘一盘工作中遇到的 MQ 异常测试
- (heavy chain dissection) Magic Tree
- 【我可以做你的第一个项目吗?】GZIP的细节简介和模拟实现
- Introduction and mechanism of Aptos
- 数字相加的精度问题
- Right click to create a new TXT. The new text file is missing. You can solve it by adding a registry. Find the ultimate solution that can't be solved
- R语言实战应用案例:绘图篇(三)-多种组合图型绘制
猜你喜欢

Sword finger offer 46. translate numbers into strings
![[WinForm] desktop program implementation scheme for screenshot recognition and calculation](/img/9f/e67af4386cff9febf0fb5203da03f0.jpg)
[WinForm] desktop program implementation scheme for screenshot recognition and calculation

对象使用过程中背后调用了哪些方法

【测试平台开发】二十、完成编辑页发送接口请求功能

After using vscode to format the code, save and find that the code is messy again. What should I do? Vs remove formatting
It is suggested that Siyuan notes can be compatible with third-party sync disks

Right click to create a new TXT. The new text file is missing. You can solve it by adding a registry. Find the ultimate solution that can't be solved

104 maximum depth of binary tree and 543 diameter of binary tree and 124 maximum path sum of binary tree
![[test platform development] 21. complete sending interface request and display response header information](/img/53/42411ceb6e0e304355ddc396ea2922.png)
[test platform development] 21. complete sending interface request and display response header information

R language practical application case: drawing part (III) - drawing of multiple combination patterns
随机推荐
C thread lock and single multithreading are simple to use
【无标题】测试【无标题】测试
LeetCode-227-基本计算器||
webstrom ERROR in [eslint] ESLint is not a constructor
Introduction and mechanism of Aptos
直播课堂系统02-搭建项目环境
C语言项目实战:24点游戏计算器(基于结构体、指针、函数、数组、循环等知识点)
【C语言】猜数字小游戏+关机小程序
生成订单号
Program design of dot matrix Chinese character display of basic 51 single chip microcomputer
Advanced operation and maintenance 03
Transferred from Yuxi information disclosure: products such as mRNA covid-19 vaccine and Jiuzhou horse tetanus immunoglobulin are expected to be on the market within this year.
Zhongwang CAD professional 2022 software installation package download and installation tutorial
Can bus quick understanding
第2章 基礎查詢與排序
linux定时备份数据库脚本
[test platform development] XVII. The interface editing page realizes the drop-down cascade selection, and binds the module to which the interface belongs
固定资产管理系统哪家好?固定资产管理平台有哪些?
直播课堂系统03补充-model类及实体
Qt文档阅读笔记-Audio Example解析