开发者社区> 科技小能手> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

oracle数据库中rman备份脚本非常实用

简介:
+关注继续查看

查询字符集

SQL> select * from nls_database_parameters;


NLS_CHARACTERSET
AL32UTF8  

备份时字符集很重要,不然会出乱码

一、0级备份(全备)红色是要修改的,根据个人的存放位置。

[oracle@oracle122 script]$ cat db_bak0.rman 
run
{
    configure retention policy to recovery window of 8 days;
    configure controlfile autobackup on;
    configure controlfile autobackup format for device type disk to '/home/oracle/rmanbak/%F';
    allocate channel ch1 device type disk format '/home/oracle/rmanbak/inc0_%d_%s_%p_%u_%T';
    backup incremental level 0 tag='level 0' database skip inaccessible filesperset 10 plus archivelog filesperset 20;
    release channel ch1;
}
allocate channel for maintenance device type disk;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
delete noprompt archivelog until time 'sysdate-30';

0级运行脚本

[oracle@oracle122 script]$ cat exec_0_level.sh 
ORACLE_HOSTNAME=oracle122; export ORACLE_HOSTNAME
ORACLE_BASE=/u01/app; export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1; export ORACLE_HOME

ORACLE_SID=orcl; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
export DATE=$(date +%Y_%m_%d)
export NLS_LANG="Simplified Chinese_china".AL32UTF8

/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target sys/sys_admin cmdfile /home/oracle/rmanbak/script/db_bak0.rman log /home/oracle/rmanbak/script/log/rman_$DATE.log append

二、1级备份(增量)

[oracle@oracle122 script]$ cat db_bak1.rman 
run
{
    configure retention policy to recovery window of 8 days;
    configure controlfile autobackup on;
    configure controlfile autobackup format for device type disk to '/home/oracle/rmanbak/%F';
    allocate channel ch1 device type disk format '/home/oracle/rmanbak/inc1_%d_%s_%p_%u_%T';
    backup incremental level 1 tag='level 1' database skip inaccessible filesperset 10 plus archivelog filesperset 20;
    release channel ch1;
}
allocate channel for maintenance device type disk;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
delete noprompt archivelog until time 'sysdate-30';

1级运行脚本

[oracle@oracle122 script]$ cat exec_1_level.sh 
ORACLE_HOSTNAME=oracle122; export ORACLE_HOSTNAME
ORACLE_BASE=/u01/app; export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
export DATE=$(date +%Y_%m_%d)
export NLS_LANG="Simplified Chinese_china".AL32UTF8

/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target sys/sys_admin cmdfile /home/oracle/rmanbak/script/db_bak1.rman log /home/oracle/rmanbak/script/log/rman_$DATE.log append


三、2级备份(从0级追加到现在的备份)

[oracle@oracle122 script]$ cat db_bak2.rman 
run
{
    configure retention policy to recovery window of 8 days;
    configure controlfile autobackup on;
    configure controlfile autobackup format for device type disk to '/home/oracle/rmanbak/%F';
    allocate channel ch1 device type disk format '/home/oracle/rmanbak/inc2_%d_%s_%p_%u_%T';
    backup incremental level 2 tag='level 2' database skip inaccessible filesperset 10 plus archivelog filesperset 20 delete all input;
    release channel ch1;
}
allocate channel for maintenance device type disk;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;

2级运行脚本

[oracle@oracle122 script]$ cat exec_2_level.sh 
ORACLE_HOSTNAME=oracle122; export ORACLE_HOSTNAME
ORACLE_BASE=/u01/app; export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
export DATE=$(date +%Y_%m_%d)
export NLS_LANG="Simplified Chinese_china".AL32UTF8

/u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target sys/sys_admin cmdfile /home/oracle/rmanbak/script/db_bak2.rman log /home/oracle/rmanbak/script/log/rman_$DATE.log append


定时备份星期天为0级全备,星期三为2级备份,星期一,星期二,星期四,星期五,星期六为1级增量备份晚上11点开始备份

[oracle@oracle122 script]$ crontab -l
* 23 * *  0 /home/oracle/rmanbak/script/exec_0_level.sh 
* 23 * *  1 /home/oracle/rmanbak/script/exec_1_level.sh 
* 23 * *  2 /home/oracle/rmanbak/script/exec_1_level.sh 
* 23 * *  3 /home/oracle/rmanbak/script/exec_2_level.sh 
* 23 * *  4 /home/oracle/rmanbak/script/exec_1_level.sh 
* 23 * *  5 /home/oracle/rmanbak/script/exec_1_level.sh 
* 23 * *  6 /home/oracle/rmanbak/script/exec_1_level.sh



本文转自 jxzhfei  51CTO博客,原文链接:http://blog.51cto.com/jxzhfei/1575247

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
oracle rman备份与ORA-19504&ORA-27040&RMAN-030009
oracle rman备份路径错误导致备份报错ORA-19504&ORA-27040&RMAN-03009...
1635 0
ORACLE windows服务器断电重启后计划任务变更导致rman备份中断
    操作系统:windows 2008 R2     数据库版本:oracle 11.2.0.3     2017年1月11日巡检中,龙岩一windows oracle数据库的rman备份出现中断(rman备份检查信息如下): ***************...
857 0
Oracle 彻底停止 RMAN 备份
ps -ef|grep rman set line 200 SELECT sid, spid, client_info FROM v$process p, v$session s WHERE p.addr = s.
3131 0
Oracle rman 备份一
####------------------------------------------------------------------------------#### ##############################################################...
399 0
文章
问答
文章排行榜
最热
最新
相关电子书
更多
PostgresChina2018_刘成伟_oracle到Postgres数据库迁移工具
立即下载
Oracle 数据库笔记
立即下载
迁移 ORACLE 最佳实践
立即下载