1.星期天晚上 -level 0 backup performed(全備份)
2.星期一晚上 -level 2 backup performed
3.星期二晚上 -level 2 backup performed
4.星期三晚上 -level 1 backup performed
5.星期四晚上 -level 2 backup performed
6.星期五晚上 -level 2 backup performed
7.星期六晚上 -level 2 backup performed
如果星期二需要恢復的話,只需要1+2,
如果星期四需要恢復的話,只需要1+4,
如果星期五需要恢復的話,只需要1+4+5,
如果星期六需要恢復的話,只需要1+4+5+6.
自動備份:備份腳本+crontab
bakl0
bakl1
bakl2
二.執行的腳本:
1.執行腳本:
rman target / msglog=bakl0.log cmdfile=bakl0 (/表示需要連接的目標數據庫,msglog表示日志文件,cmdfile表示的是腳本文件)
rman target / msglog=bakl1.log cmdfile=bakl1
rman target / msglog=bakl2.log cmdfile=bakl2
實例:rman target system/oracle@ora10g(/) msglog=/u01/rmanbak/bakl1.log cmdfile=/u01/rmanbak/bakl0
完整的命令:/u01/oracle/product/10.2.0/bin/rman target system/oracle@ora10g(/) msglog=/u01/rmanbak/bakl1.log cmdfile=/u01/rmanbak/bakl0
2.編寫rman備份腳本:
0級備份腳本:
把備份腳本放到/u01/rmanbak/script目錄下面,vi bakl0,bakl0的內容為:
run{
allocate channel cha1 type disk;
backup
incremental level 0
format '/home/oracle/rmanbackup/inc0_%u_%T'(u表示唯一的ID,大T是日期,小t是時間)
tag monday_inc0 //標簽可以順便起,沒關系
database plus archivelog delete input;
release channel cha1;
}
1級備份腳本:
run{
allocate channel cha1 type disk;
backup
incremental level 1
format '/home/oracle/rmanbackup/inc1_%u_%T'(u表示唯一的ID,大T是日期,小t是時間)
tag monday_inc1 //標簽可以順便起,沒關系
database plus archivelog delete input;
release channel cha1;
}
2級備份腳本:
run{
allocate channel cha1 type disk;
backup
incremental level 2
format '/home/oracle/rmanbackup/inc2_%u_%T'(u表示唯一的ID,大T是日期,小t是時間)
tag monday_inc2 //標簽可以順便起,沒關系
database plus archivelog delete input;
release channel cha1;
}
3.編寫調用rman腳本的shell腳本:
調用0備份的shell腳本 rmanbak0.sh為:
#!/bin/bash
source /home/oracle/.bash_profile
/u01/app/oracle/11.2.0/db_home_1/bin/rman target / nocatalog cmdfile=/home/oracle/script/bakl0 msglog=/home/oracle/bakl0.log
調用1備份的shell腳本 rmanbak0.sh為:
#!/bin/bash
source /home/oracle/.bash_profile
/u01/app/oracle/11.2.0/db_home_1/bin/rman target / nocatalog cmdfile=/home/oracle/script/bakl1 msglog=/home/oracle/bakl0.log
調用2備份的shell腳本 rmanbak0.sh為:
#!/bin/bash
source /home/oracle/.bash_profile
/u01/app/oracle/11.2.0/db_home_1/bin/rman target / nocatalog cmdfile=/home/oracle/script/bakl2 msglog=/home/oracle/bakl0.log
4.編寫Linux定時任務執行自動備份
[root@gc2 ~]#crontab -e -u oracle(該命令的意思是編輯oracle用戶的定時執行(-e,edit -u oracle,oracle用戶))
分 時 日 月 星期(0代表星期天)
45 23 * * 0 /home/oracle/script/rmanbak0.sh(星期天的23:45會以oracle用戶的身份來執行命令)
45 23 * * 1 /home/oracle/script/rmanbak2.sh
45 23 * * 2 /home/oracle/script/rmanbak2.sh
45 23 * * 3 /home/oracle/script/rmanbak1.sh
45 23 * * 4 /home/oracle/script/rmanbak2.sh
45 23 * * 5 /home/oracle/script/rmanbak2.sh45 23 * * 6 /home/oracle/script/rmanbak2.sh
或者(用于測試):
使用oracle用戶添加例行任務:
crontab -e
新打開的窗口中添加一下內容:
0 24 * * * /home/oracle/bin/rmanbak0.sh
(*/3 * * * * /home/oracle/bin/rmanbak0.sh)
注,括號內的可以是做測試的時候用的,每三分鐘執行一次備份,例為每天凌晨24點執行備份
#然后啟動crontab ,啟動crontab的命令:
[root@gc2 ~]# service crond restart
Stopping crond: [ OK ]
Starting crond: [ OK ]
#監控定時任務是否執行
[root@gc2 ~]# tail -f /var/log/cron
Mar 10 21:28:04 gc2 crond[4435]: (CRON) STARTUP (V5.0)
Mar 10 21:30:01 gc2 crond[4445]: (root) CMD (/usr/lib/sa/sa1 1 1)
Mar 10 21:39:08 gc2 crond[4486]: (CRON) STARTUP (V5.0)