您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關怎么理解定時任務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就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。