前言
到了生产环境,备份数据是不可缺少环节,下面简单介绍一下定时任务备份数据,因为不同系统定时任务有差别
- 系统: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