LINUX上RMAN自动备份脚本
1. 建备份目录 oradataback,2级目录archback(放归档日志)、rmanscripts(备份脚本),
在rmanscripts下面建 rmanlevel0.sh rmanlevel1.sh rmanlevel2.sh 文件:
mkdir oradataback
--home/oracle/app/oradataback
chmod 775 oradataback
chown -R oracle:oinstall /home/oracle/app/oradataback
touch rmanlevel0.sh rmanlevel1.sh rmanlevel2.sh
赋权同上
2. vi 编辑3个文件:
0级备份文件:
--rmanlevel0.sh--
#!/bin/sh
# set porfile_env
export ORACLE_SID=eytdbs # rman level0 backup
rman log='/home/oracle/app/oradataback/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/oradataback/db_level0_%T_%U' tag='level0';
sql 'alter system archive log current';
backup archivelog all format '/home/oracle/app/oradataback/archback/db_arch_%T_%U' delete input;
release channel c1;
}
EOF
1级备份文件:
--rmanlevel1.sh--
#!/bin/sh
# set porfile_env
export ORACLE_SID=eytdbs # rman level0 backup
rman log='/home/oracle/app/oradataback/db_rman1.log' append <<EOF
connect target /;
run
{
allocate channel c1 type disk;
backup incremental level=1 database format '/home/oracle/app/oradataback/db_level1_%T_%U' tag='level1';
sql 'alter system archive log current';
backup archivelog all format '/home/oracle/app/oradataback/archback/db_arch_%T_%U' delete input;
release channel c1;
}
EOF
2级备份文件:
--rmanlevel2.sh--
#!/bin/sh
# set porfile_env
export ORACLE_SID=eytdbs # rman level0 backup
rman log='/home/oracle/app/oradataback/db_rman2.log' append <<EOF
connect target /;
run
{
allocate channel c1 type disk;
backup incremental level=2 database format '/home/oracle/app/oradataback/db_level2_%T_%U' tag='level2';
sql 'alter system archive log current';
backup archivelog all format '/home/oracle/app/oradataback/archback/db_arch_%T_%U' delete input;
release channel c1;
}
EOF
#说明:在oracle用户下手动运行脚本的命令:sh rmanlevel2.sh
3. 加自动运行任务:
在root下设置,用vi编辑: #crontab -e
0 2 1 * * su – oracle -c /home/oracle/app/oradataback/rmanscripts/rmanlevel0.sh //每月1日2:00运行 0级备份
0 2 * * 0 su – oracle -c /home/oracle/app/oradataback/rmanscripts/rmanlevel1.sh //每周日2:00运行 1级备份
0 2 * * 1-6 su – oracle -c /home/oracle/app/oradataback/rmanscripts/rmanlevel2.sh //每周一周六2:00运行 2级增量备份
--查看添加的任务: crontab -l
--crontab的格式:
minutes|hours|day of month|month|day of week|
--启动crond:
/sbin/service crond start //启动服务
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置
4. 测试结果:
可以自动运行,能成功的备份数据, 但有点小问题,
一是rman备份格式 %F 一直都用这个格式,但今天既然不认识了,只能改为_%T_%U',不知道什么原因。
二是报了几个错误:
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "identifier": expecting one of: "...... {, "
RMAN-01008: the bad identifier was: EOF
RMAN-01007: at line 1 column 1 file: standard input
找了半天也没找到毛病,以后再慢慢的研究吧。
相关新闻>>
- 发表评论
-
- 最新评论 更多>>