前言
到了生产环境,备份数据是不可缺少环节,下面简单介绍一下定时任务备份数据,因为不同系统定时任务有差别
- 系统:CentOS7
安装
# 安装定时任务
yum install crontabs
# 设置开机启动
$ systemctl enable crond
# 启动定时任务
$ systemctl start crond
配置定时规则
- 在
/etc/crontab文件中添加30 1 * * * /lmes/auto_shell_script/dbbackup.sh备份脚本路径
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
# 备份数据库脚本
30 1 * * * /lmes/auto_shell_script/dbbackup.sh
- 保存生效
crontab /etc/crontab
- 查看任务
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
30 1 * * * /lmes/auto_shell_script/dbbackup.sh
CentOS7系统下配置定时任务进行数据库备份

本文介绍了在CentOS7环境中如何安装和配置定时任务(crontab)来实现数据库的自动备份。首先,通过yum install crontabs安装定时任务,并设置开机启动。然后,在/etc/crontab文件中添加定时规则,指定在每天的1点30分执行位于/lmes/auto_shell_script/dbbackup.sh的备份脚本。最后,使用crontab命令使改动生效,并提供了检查任务的方法。
3万+





