Linux 下crontab管理RMAN一周自动增量备份
编写各自对应的级别备份脚本 rmanbklevel_0.sh rmanbklevel_1.sh rmanbklevel_2.sh
[Oracle@oracle11gR2 scripts]$ pwd
/u01/scripts
[oracle@oracle11gR2 scripts]$ ll
total 44
-rw-r--r--. 1 oracle oinstall 102 Jul 20 04:39 audit.sql
-rwxr-xr-x. 1 oracle oinstall 398 Jul 22 03:50 coldbak.sh
-rw-r--r--. 1 oracle oinstall 829 Jul 17 02:08 deadlock.sql
-rw-r--r--. 1 oracle oinstall 126 Jul 20 04:29 fail_count.sql
-rw-r--r--. 1 oracle oinstall 327 Jul 20 04:28 fail_user.sql
-rwxr-xr-x. 1 oracle oinstall 260 Jul 22 19:45 rmanbklevel_0.sh //0级备份要有可执行权限x
-rwxr-xr-x. 1 oracle oinstall 260 Jul 22 19:46 rmanbklevel_1.sh //1级备份要有可执行权限x
-rwxr-xr-x. 1 oracle oinstall 260 Jul 22 19:47 rmanbklevel_2.sh //2级备份要有可执行权限x
-rw-r--r--. 1 oracle oinstall 116 Jul 20 00:44 spid.sql
-rw-r--r--. 1 oracle oinstall 143 Jul 17 04:59 undo.sql
-rwxr-xr-x. 1 oracle oinstall 613 Jul 22 15:00 userbak.sh
[oracle@oracle11gR2 scripts]$
[oracle@oracle11gR2 scripts]$ vi rmanbklevel_0.sh //0级备份脚本
#!/bin/sh
export ORACLE_SID=orcl
rman log='/rmanbk/bakl0.log' append <<EOF
connect target /;
run{
allocate channel cha1 type disk;
backup
incremental level 0
format '/rmanbk/incremental_level0_%u_%T'
tag backup_inc0
database;
release channel cha1;
}
EOF
exit
[oracle@oracle11gR2 scripts]$ vi rmanbklevel_1.sh //1级备份脚本
#!/bin/sh
export ORACLE_SID=orcl
rman log='/rmanbk/bakl1.log' append <<EOF
connect target /;
run{
allocate channel cha1 type disk;
backup
incremental level 1
format '/rmanbk/incremental_level1_%u_%T'
tag backup_inc1
database;
release channel cha1;
}
EOF
exit
[oracle@oracle11gR2 scripts]$ vi rmanbklevel_2.sh //2级备份脚本
#!/bin/sh
export ORACLE_SID=orcl
rman log='/rmanbk/bakl2.log' append <<EOF
connect target /;
run{
allocate channel cha1 type disk;
backup
incremental level 2
format '/rmanbk/incremental_level2_%u_%T'
tag backup_inc2
database;
release channel cha1;
}
EOF
exit
在root身份下添加crontab任务计划
[root@oracle11gR2 ~]# crontab -e
59 19 * * 0 su - oracle -c /u01/scripts/rmanbklevel_0.sh 每周日19点59分0级备份
59 19 * * 1 su - oracle -c /u01/scripts/rmanbklevel_2.sh 每周一19点59分2级备份
59 19 * * 2 su - oracle -c /u01/scripts/rmanbklevel_2.sh 每周二19点59分2级备份
59 19 * * 3 su - oracle -c /u01/scripts/rmanbklevel_1.sh 每周三19点59分1级备份
59 19 * * 4 su - oracle -c /u01/scripts/rmanbklevel_2.sh 每周四19点59分2级备份
59 19 * * 5 su - oracle -c /u01/scripts/rmanbklevel_2.sh 每周五19点59分2级备份
59 19 * * 6 su - oracle -c /u01/scripts/rmanbklevel_2.sh 每周六19点59分2级备份
保存退出
[root@oracle11gR2 ~]# service crond restart //重启任务计划
Stopping crond: [ OK ]
Starting crond: [ OK ]
一周的RMAN自动备份任务完成
推荐阅读: