一、新建备份目录并授权:
[oracle@TAIXIN-HR ~]$ mkdir -p /home/oracle/app/hr_back (备份目录)
mkdir -p /home/oracle/app/hr_back/archback
mkdir -p /home/oracle/app/hr_back/rmanscripts
[oracle@TAIXIN-HR ~]$ chmod 755 /home/oracle/app/hr_back (授权)
chown -R oracle:oinstall /home/oracle/app/oradataback
touch rmanlevel0.sh rmanlevel1.sh rmanlevel2.sh(创建脚本文件)二、vi 编辑3个文件:
0级备份文件:
#rmanlevel0.sh #!/bin/sh export ORACLE_SID=实例名 # rman level0 backup rman log='/home/oracle/app/hr_back/db_rman0.log' append <<EOF connect target /; run { allocate channel c1 type disk; backup as compressed backupset incremental level=0 database format '/home/oracle/app/hr_back/db_level0_%T_%U' tag='level0'; sql 'alter system archive log current'; backup archivelog all format '/home/oracle/app/hr_back/archback/db_arch_%T_%U' delete input; release channel c1; } exit 1级备份文件: #rmanlevel1.sh #!/bin/sh export ORACLE_SID=实例名 # rman level0 backup rman log='/home/oracle/app/hr_back/db_rman1.log' append <<EOF connect target /; run { allocate channel c1 type disk; backup incremental level=1 database format '/home/oracle/app/hr_back/db_level1_%T_%U' tag='level1'; sql 'alter system archive log current'; backup archivelog all format '/home/oracle/app/hr_back/archback/db_arch_%T_%U' delete input; release channel c1; } exit2级备份文件: #rmanlevel2.sh #!/bin/sh export ORACLE_SID=实例名 # rman level0 backup rman log='/home/oracle/app/hr_back/db_rman2.log' append <<EOF connect target /; run { allocate channel c1 type disk; backup incremental level=2 database format '/home/oracle/app/hr_back/db_level2_%T_%U' tag='level2'; sql 'alter system archive log current'; backup archivelog all format '/home/oracle/app/hr_back/archback/db_arch_%T_%U' delete input; release channel c1; } exit
三、将脚本设置定时运行
在root用户下输入crontab -e
0 2 1 * * su – oracle -c /home/oracle/app/hr_back/rmanscripts/rmanlevel0.sh //每月1日2:00运行 0级备份
0 2 * * 0 su – oracle -c /home/oracle/app/hr_back/rmanscripts/rmanlevel1.sh //每周日2:00运行 1级备份 0 2 * * 1-6 su – oracle -c /home/oracle/app/hr_back/rmanscripts/rmanlevel2.sh //每周一周六2:00运行 2级增量备份 --查看添加的任务: crontab -l --crontab的格式: minutes|hours|day of month|month|day of week|四、将数据库备份的文件夹再备份到LAN共享
1、映射windows共享
Mount –t cifs –o username=,password= //ip/dir /dir
2、利用linux cp 命令把oracle 备份文件夹复制到映射的共享
mkdir /home/oracle/app/move_back/$(date +%Y%m%d)(创建以日期命名的文件夹)
cp -R /home/oracle/app/hr_back/* /home/oracle/app/move_back/$(date +%Y%m%d)(复制)
exit