ITPub博客

首页 > Linux操作系统 > Linux操作系统 > RMAN备份脚本

RMAN备份脚本

原创 Linux操作系统 作者:ilsyx 时间:2011-08-17 10:18:12 0 删除 编辑

1.单实例库

1.1 rman参数

$rman target /

 Recovery Manager: Release 10.2.0.4.0 - Production on Wed Feb 9 17:00:50 2011
 
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
 
connected to target database: TESTDB2 (DBID=1024880953)
 
RMAN> show all;
 
using target database control file instead of recovery catalog
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/oracle/database/backup/rman/testdb2/ctl_%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/oracle/database/product/10.2.0/db_1/dbs/snapcf_testdb2.f'; # default
 
RMAN> 

1.2 rman全库备份脚本

 $cat rman_testdb2_full.sh 
#!/bin/bash
export ORACLE_BASE=/oracle/database
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=testdb2
 
rman_backup_script=/home/oracle/db_script/rman/testdb2/
rman_backup_dir=/oracle/database/backup/rman/testdb2/
dt=`date +%F`
 
rman target / >>$rman_backup_script/rman_${ORACLE_SID}_full_${dt}.log < backup database format '$rman_backup_dir/db_%d_%T_%s_%p_%t' plus archivelog format='$rman_backup_dir/arch_%d_%T_%s_%p_%t' delete all input;
}
run{
crosscheck backup;
crosscheck backupset;
delete noprompt expired backup;
delete noprompt obsolete;
}
exit
EOF

1.3 rman level0 增备

 $cat rman_testdb2_level0.sh 
#!/bin/bash
export ORACLE_BASE=/oracle/database
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=testdb2
 
rman_backup_script=/home/oracle/db_script/rman/testdb2/
rman_backup_dir=/oracle/database/backup/rman/testdb2/
dt=`date +%F`
 
rman target / >>$rman_backup_script/rman_${ORACLE_SID}_level0_${dt}.log <
backup as compressed backupset incremental level 0 database format '$rman_backup_dir/db_%d_%T_%s_%p_%t' plus archivelog format='$rman_backup_dir/arch_%d_%T_%s_%p_%t' delete all input;
}
run{
crosscheck backup;
crosscheck backupset;
delete noprompt expired backup;
delete noprompt obsolete;
}
exit
EOF


1.3 生成备份检验

$ls /oracle/database/backup/rman/testdb2/
ctl_c-1024880953-20110209-00  db_TESTDB2_20110209_198_1_742668277  db_TESTDB2_20110209_199_1_742668625

2 RAC 两结点

2.1 环境介绍

rac环境中,归档日志放在两实例结点的本地磁盘空间上,rman备份文件放在nas上.

2.2. nfs 参数

192.168.1.1:/data/archivefor630 on /oracle/backup type nfs (rw,noexec,nosuid,nodev,noac,bg,hard,timeo=20,intr,rsize=40960,wsize=40960,addr=192.168.1.1)

2.3. rman  参数

 RMAN> show all;
 
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/oracle/backup/ccit1/rmanbackup/ctl_%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/oracle/database/10.2.0/db_1/dbs/snapcf_ccit11.f';

2,4 增量level0级压缩rman备份

 $cat ccit1_level0.sh 
#!/bin/bash
export ORACLE_SID=ccit11
export ORACLE_BASE=/oracle/database
export ORACLE_HOME=$ORACLE_BASE/10.2.0/db_1
export ORA_CRS_HOME=$ORACLE_BASE/10.2.0/crs_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$ORA_CRS_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin
dt=`date +%m%d`
 
rman target / >> /home/oracle/db_script/rman/ccit1_level0_$dt.log  << EOF
run{
allocate channel ch1 type disk connect sys/system08ccit1@ccit11;
allocate channel ch2 type disk connect sys/system08ccit1@ccit12;
backup as compressed backupset incremental level 0  database format '/oracle/backup/ccit1/rmanbackup/db_%d_%T_%s_%p_%t' plus archivelog format='/oracle/backup/ccit1/rmanbackup/arch_%d_%T_%s_%p_%t' delete all input;
backup spfile format '/oracle/backup/ccit1/rmanbackup/spf_%d_%T_%s_%c';
release channel ch1;
release channel ch2;
}
run{
allocate channel ch1 type disk connect sys/system08ccit1@ccit11;
allocate channel ch2 type disk connect sys/system08ccit1@ccit12;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
release channel ch1;
release channel ch2;
}
exit
EOF

2.5  archivelog 压缩备份

$ cat /home/oracle/db_script/rman/ccit1_archive.sh

#!/bin/bash
#this is a script. of backup oracle archive log per hours
export ORACLE_SID=ccit11
export ORACLE_BASE=/oracle/database
export ORACLE_HOME=$ORACLE_BASE/10.2.0/db_1
export ORA_CRS_HOME=$ORACLE_BASE/10.2.0/crs_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$ORA_CRS_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin
dt=`date +%m%d`
 
rman target / >> /home/oracle/db_script/rman/ccit1_archive_$dt.log  << EOF
run{
allocate channel ch1 type disk connect sys/system08ccit1@ccit11;
allocate channel ch2 type disk connect sys/system08ccit1@ccit12;
backup as compressed backupset archivelog all format='/oracle/backup/ccit1/rmanbackup/arch_%d_%T_%s_%p_%t' delete all input;
release channel ch1;
release channel ch2;
}
exit
EOF

3.formate 参考

%c:备份片的拷贝数(从1开始编号)
%d:数据库名称
%D:位于该月中的天数(DD)
%M:位于该年中的月份(MM)
%F:一个基于DBID唯一的名称,这个格式的形式为c-xxx-YYYYMMDD-QQ,     xiaoy注:此处测试未通过
其中xxx为该数据库的DBID,YYYYMMDD为日期,QQ是一个1-256的序列
%n:数据库名称,并且会在右侧用x字符进行填充,使其保持长度为8
%u:是一个由备份集编号和建立时间压缩后组成的8字符名称。可以生产唯一的名称。
%p:表示备份集中备份片段的编号,从1开始编号
%U:是%u_%p_%c的简写形式,生产唯一名称
%s:备份集的号
%t:备份集时间戳
%T:年月日格式(YYYYMMDD)

PS. rman日期格式显示,在环境变量中设置 NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'
例: export  NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'
 
官方文档参考:
Oracle? Database Backup and Recovery Reference
10g Release 2 (10.2)
Part Number B14194-03
 
formatSpec 关键字

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11780477/viewspace-705066/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 日志挖掘
请登录后发表评论 登录
全部评论

注册时间:2009-06-12

  • 博文量
    196
  • 访问量
    608601