怎么理解定时任务crontab

这篇文章将为大家详细讲解有关怎么理解定时任务crontab,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

网站的建设成都创新互联专注网站定制,经验丰富,不做模板,主营网站定制开发.小程序定制开发,H5页面制作!给你焕然一新的设计体验!已为成都活动板房等企业提供专业服务。

脚本目录:

  • [oracle@tangjian ~]$ mkdir -p /u01/app/oracle/rman/scripts/

归档目录:

  • [oracle@tangjian ~]$ mkdir -p /u01/app/oracle/rman/arch/

创建脚本:(每月一次0级增量)

  • [oracle@tangjian ~]$ vi /u01/app/oracle/rman/scripts/full_backup_run.sh

#!/bin/bash

#Usage:test database hot full backup !

export PATH

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1

export ORACLE_SID=test

export PATH=$PATH:$ORACLE_HOME/bin

DATE=$(date +%Y%m%d)

mkdir -p /u01/app/oracle/rman/$DATE

rman target / <

run{

allocate channel c1 type disk;

allocate channel c2 type disk;

sql'alter system switch logfile';

crosscheck archivelog all;

delete noprompt expired archivelog all;

backup incremental level 0 database format '/u01/app/oracle/rman/$DATE/test_%U.bk' include current controlfile plus archivelog delete input format '/u01/app/oracle/rman/arch/arch_test_%U.arch';

crosscheck archivelog all;

delete noprompt obsolete;

delete noprompt backup of database completed before 'sysdate - 32';

release channel c1;

release channel c2; }

exit;

EOF

  • [root@tangjian ~]# chmod -R 775 /u01/app/oracle/rman/scripts/full_backup_run.sh

添加定时任务:

  • [oracle@tangjian 20180730]$ crontab -e

#rman backup full database shell

52 14 * * * /u01/app/oracle/rman/scripts/full_backup_run.sh 1>/u01/app/oracle/rman/rman_backup_full.log 2>&1

查看任务列表:

  • [oracle@tangjian 20180730]$ crontab -l

创建脚本:(每星期一次1级差异增量)

  • [oracle@tangjian ~]$ vi /u01/app/oracle/rman/scripts/level_backup_run.sh

#!/bin/bash

#Usage:test database hot full backup !

export PATH

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1

export ORACLE_SID=test

export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin

DATE=$(date +%Y%m%d)

mkdir -p /u01/app/oracle/rman/level/$DATE

rman target / <

run{

allocate channel a1 device type disk;

allocate channel a2 device type disk;

sql'alter system switch logfile';

crosscheck archivelog all;

delete noprompt expired archivelog all;

backup incremental level 1 database format '/u01/app/oracle/rman/level/$DATE/test_%U.bk' include current controlfile plus archivelog delete input format '/u01/app/oracle/rman/arch/arch_test_%U.arch';

crosscheck archivelog all;

delete noprompt obsolete;

delete noprompt backup of database completed before 'sysdate -32';

release channel a1;

release channel a2;

}

exit;

EOF

  • [root@tangjian ~]# chmod -R 775 /u01/app/oracle/rman/scripts/level_backup_run.sh

添加定时任务:

  • [oracle@tangjian 20180730]$ crontab -e

#rman backup full database shell

00 1 1 * * /u01/app/oracle/rman/scripts/full_backup_run.sh 1>/tmp/rman_backup_full.log 2>&1

#rman backup level database shell

00 1 * * 7 /u01/app/oracle/rman/scripts/level_backup_run.sh 1>/tmp/rman_backup_full.log 2>&1

验证脚本可用性:

  • [oracle@tangjian scripts]$ sh full_backup_run.sh

  • [oracle@tangjian scripts]$ sh level_backup_run.sh

常用命令:
/sbin/service crond start           启动服务

/sbin/service crond stop            关闭服务

/sbin/service crond restart       重启服务

/sbin/service crond reload        重新载入配置

在/etc/rc.d/rc.local这个脚本的末尾加上(开机自启):

/sbin/service crond start

crontab -u        设定某个用户的cron服务,一般root用户在执行这个命令的时候需要此参数

crontab -l         列出某个用户cron服务的详细内容

crontab -r        删除某个用户的cron服务

crontab -e        编辑某个用户的cron服务

关于怎么理解定时任务crontab就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


分享题目:怎么理解定时任务crontab
本文来源:http://azwzsj.com/article/jopeod.html