1、编写0级备份的rman脚本
vim /jobs/backup/back_0.sh
#!/bin/bash
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=orcl
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export LANG=en_US
rman target / log ‘/tmp/x.log‘ << EOF
run{
allocate channel c1 type disk;
backup incremental level 0 format "/home/oracle/inc0_%u_%T" database;
release channel c1;
}
EOF
2、编写1级备份的rman脚本
vim /jobs/backup/back_1.sh
#!/bin/bash
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=orcl
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export LANG=en_US
rman target / log ‘/tmp/y.log‘ << EOF
run{
allocate channel c1 type disk;
backup incremental level 1 format "/home/oracle/inc1_%u_%T" database;
release channel c1;
}
EOF
3、给予脚本相应的权限
chmod 755 /jobs/backup/back_0.sh
4、加入crontab
crontab -e
0 0 * * 0 /jobs/backup/back_0.sh
0 0 * * 1,2,3,4,5,6 /jobs/backup/back_1.sh
周日的0点0分做0级备份,周1~6进行1级备份
补充:
对于保存的日志,如果需要保留,可以考虑用天来命名取代固定命名。
可以将backup_0.sh改造成:
vim /jobs/backup/back_1.sh
#!/bin/bash
BKDIR=/backup/`date +%Y%m%d%H%M`
LOGFILE=/logs/`date +%Y%m%d%H%M`.log
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=orcl
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export LANG=en_US
rman target / log $LOGFILE << EOF
run{
allocate channel c1 type disk;
backup incremental level 1 format "$BKDIR" database;
release channel c1;
}
EOF
补充:
可以使用指令文件来进行控制命令。
vim backup.rmn
run {
backup database;
}
rman target / cmdfile=backup.rmn log=backup.log
利用这种方式也能进行方便的自动备份功能。
原文地址:http://7737197.blog.51cto.com/7727197/1663284