实验:计划任务cron 定期备份

椰子ya Linux 2020-08-05

查看/etc/crontab中的内容

cat /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

以root身份打开,etc/crontab文件,插入下面这一行

vim /etc/crontab 
0 17 * * * root tar cvf /root/BF.tar.gz /root/*.txt   //添加到crontab文件中
//保存并退出,自动生效。

分钟,0表示整点;
小时,17表示下午五点;
日期,星号“*”表示一个月中的每一天;
月份,星号“*”表示一星期中的每一天;
星期,星号“*”表示一星期中的每一天;
代码含义:每天下午5点,以root身份将/root/目录下所有.txt文件打包成BF.tar.gz,并存放在/root中。

PREV
交换机基础命令
NEXT
H3C链路聚合