温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么理解定时任务crontab

发布时间:2021-11-09 09:52:44 来源:亿速云 阅读:119 作者:柒染 栏目:建站服务器

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

脚本目录:

  • [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 / <<EOF

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

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就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI