当前位置:网站首页>定时备份数据库脚本
定时备份数据库脚本
2022-06-24 07:03:00 【一个不靠谱的程序员】
定时任务
crontab命令用于设置周期性被执行的指令。该命令从标准输入设备读取指令,并将其存放于“crontab”文件中,以供之后读取和执行。
通常linux里都内置了crontab命令。如果没有请自行安装。
文件
crontab在/etc目录下面存在cron.hourly,cron.daily,cron.weekly,cron.monthly,cron.d五个目录和crontab,cron.deny二个文件。
cron.daily是每天执行一次的job
cron.weekly是每个星期执行一次的job
cron.monthly是每月执行一次的job
cron.hourly是每个小时执行一次的job
cron.d是系统自动定期需要做的任务
crontab是设定定时任务执行文件
cron.deny文件就是用于控制不让哪些用户使用Crontab的功能
每个用户都有自己的cron配置文件,通过crontab -e 就可以编辑,一般情况下我们编辑好用户的cron配置文件保存退出后,系统会自动就存放于/var/spool/cron/目录中,文件以用户名命名.linux的cron服务是每隔一分钟去读取一次/var/spool/cron,/etc/crontab,/etc/cron.d下面所有的内容.
一些命令
crontab –e : 修改 crontab 文件,如果文件不存在会自动创建。
crontab –l : 显示 crontab 文件。
crontab -r : 删除 crontab 文件。
crontab -ir : 删除 crontab 文件前提醒用户。
数据库定时备份脚本xtrabackup.sh
#!/bin/bash
defaults_file="/etc/my.cnf" # mysql配置文件位置
user="backup" #mysql账号
password="backup" #mysql密码
backup_dir="/path/to/backup/" #需要存档的根目录
time_dir="$(date +"%Y%m%d%H%M%S")"
shell='innobackupex --defaults-file='$defaults_file' --user='$user' --password='$password' --stream=tar /temp | ssh [email protected]远端机子 "gzip -> '$backup_dir$time_dir'.tar.gz"'
eval $shell将脚本加入计划任务
- command
minute hour day month week command
分 时 天 月 星期 命令
执行crontab –e
00 02 * * * /bin/bash /path/to/xtrabackup.sh
边栏推荐
- The article takes you to understand the security of Windows operating system and protect your computer from infringement
- 2021-06-25: a batch of strings consisting only of lowercase letters (a~z) are put
- WPS的JS宏实现图片正文在同一段落的分离方法
- Centos7安装jdk8以及mysql5.7以及Navicat连接虚拟机mysql的出错以及解决方法(附mysql下载出错解决办法)
- MAYA重新拓布
- ZUCC_ Principles of compiling language and compilation_ Big job
- Shell array
- win11在cmder中使用vim查看内容的时候空白
- The reason why the qtimer timer does not work
- pyQt 中 QMenu 响应
猜你喜欢

WCF TCP protocol transmission
![[untitled]](/img/94/792e8363dbfe67770e93b0dcdc8e72.png)
[untitled]

ZUCC_编译语言原理与编译_实验02 FSharp OCaml语言

Pat 1157: school anniversary

Synthesize video through ffmpeg according to m3u8 file of video on the network

MATLAB Camera Calibrator相机标定

How to improve the customer retention rate in the operation of independent stations? Customer segmentation is very important!

Introduction to RCNN, fast RCNN and fast RCNN

Question bank and simulation examination for operation certificate of refrigeration and air conditioning equipment in 2022

Qt导出PDF文件的两种方法
随机推荐
AUTO PWN
Detailed explanation of etcd backup and recovery principle and actual record of stepping on the pit
Final review and key points of software process and project management
Common CVM transcribes audio using virtual sound card
How to replace the web player easyplayerproactivex Key in OCX?
Cloudbase database migration scheme
貸款五級分類
Synthesize video through ffmpeg according to m3u8 file of video on the network
ZUCC_ Principles of compiling language and compilation_ Experiment 03 getting started with compiler
uniapp 热更新后台管理
OpenCV to realize the basic transformation of image
Pat 1157: school anniversary
Easynvr and easyrtc platforms use go language to manage projects. Summary of the use of govendor and gomod
List of Li Bai's 20 most classic poems
Variable declaration and some special variables in shell
Battle history between redis and me under billion level traffic
Scénarios d'utilisation de la promesse
LabVIEW finds prime numbers in an array of n elements
pyQt 常用系统的事件
2021-03-04 comp9021 class 6 notes