RMAN记录

rman备份脚本:

##======================================================================
##  
## 
##  
##  usage: db_bak_rman.sh <$ORACLE_SID> <$BACKUP_LEVEL>
##         BACKUP_LEVEL:
##                    F: full backup
##                    0: level 0
##                    1: level 1
##======================================================================
#!/bin/bash
# User specific environment and startup programs

if [ -f ~/.bash_profile ];
then
  . ~/.bash_profile
fi

ORACLE_SID=${1};                           export ORACLE_SID
RMAN_LEVEL=${2};                           export RMAN_LEVEL
TIMESTAMP=`date +%Y%m%d%H%M`;              export TIMESTAMP
DATE=`date +%Y%m%d`;                       export DATE
#RMAN_DIR=/backup_db_rman/rman;            export RMAN_DIR  #marked by elaine 160603
RMAN_DIR=/mnt/bak/${1};                         export RMAN_DIR
RMAN_DATA=${RMAN_DIR}/${DATE};             export RMAN_DATA
#RMAN_LOG=/backup_db_rman/rman/log;        export RMAN_LOG  #marked by elaine 160603
RMAN_LOG=${RMAN_DIR}/${DATE};                     export RMAN_LOG

# check rman level
#=======================================================================

if [ "$RMAN_LEVEL" == "F" ];
then
  unset INCR_LVL
  BACKUP_TYPE=full
else
  INCR_LVL="INCREMENTAL LEVEL ${RMAN_LEVEL}"
  BACKUP_TYPE=lev${RMAN_LEVEL}
fi

RMAN_FILE=${RMAN_DATA}/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP};    export RMAN_FILE
SSH_LOG=${RMAN_LOG}/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}.log;   export SSH_LOG

MAXPIECESIZE=2G;                                                     export MAXPIECESIZE

#check RMAN Backup Path
#=======================================================================

if ! test -d ${RMAN_DATA}
then
  mkdir -p ${RMAN_DATA}
fi

echo "------------------------------------" >>${SSH_LOG}
echo "      " >>${SSH_LOG}
echo "Rman Begin to Working .............." >>${SSH_LOG}
echo "Begin time at:" `date` -- `date +%Y%m%d%H%M` >>${SSH_LOG}

#Startup rman to backup
#=======================================================================
$ORACLE_HOME/bin/rman log=${RMAN_FILE}.log <<EOF

connect target /
run {
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '${RMAN_FILE}_%F';
ALLOCATE CHANNEL ch1 TYPE DISK;
ALLOCATE CHANNEL ch2 TYPE DISK;
#set limit channel ch1 readrate=10240;
#set limit channel ch1 kbytes=4096000;
#set limit channel ch2 readrate=10240;
#set limit channel ch2 kbytes=4096000;
CROSSCHECK ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
BACKUP ${INCR_LVL} DATABASE FORMAT '${RMAN_FILE}_%U' TAG '${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}';
SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
BACKUP ARCHIVELOG ALL FORMAT '${RMAN_FILE}_arc_%U' TAG '${ORACLE_SID}_arc_${TIMESTAMP}'
DELETE INPUT;
#DELETE NOPROMPT OBSOLETE;
DELETE ARCHIVELOG UNTIL TIME 'SYSDATE-7'; 
RELEASE CHANNEL ch1;
RELEASE CHANNEL ch2;
}

sql "alter database backup controlfile to ''${RMAN_DATA}/cntl_${BACKUP_TYPE}.bak''";

exit;
EOF
RC=$?

cat ${RMAN_FILE}.log >>${SSH_LOG}

echo "Rman Stop working @ time:"`date` `date +%Y%m%d%H%M` >>${SSH_LOG}

echo >>${SSH_LOG}
echo "----------------------------------------" >>${SSH_LOG}
echo "------------------ Disk Space ----------" >>${SSH_LOG}
df -h >>${SSH_LOG}

echo >>${SSH_LOG}

if [ $RC -ne "0" ]; then
  echo "-------------------- error --------------------" >>${SSH_LOG}
else
  echo "------ no error found during RMAN backup period --------" >>${SSH_LOG}
  rm -rf ${RMAN_FILE}.log
fi

#Remove old backup than 5 days
#===========================================================================================
RMDIR=${RMAN_DIR}/`/bin/date +%Y%m%d -d "7 days ago"`;        export RMDIR
echo >>${SSH_LOG}
echo -e "---------------Remove old backup than 7 days -------------\n" >>${SSH_LOG}

if test -d ${RMDIR}
then
  rm -rf ${RMDIR}
  RC=$?
fi

echo >>${SSH_LOG}

if [ $RC -ne "0" ]; then
  echo -e "----------- Remove old backup exception-------------- \n" >>${SSH_LOG}
else
  echo -e "----------- no error found during remove old backup set period------ \n" >>${SSH_LOG}
fi

exit

1.开启归档

(1)查看归档模式

没有开启归档,备份失败

1.expoer ORACLE_SID=stg
2.archive log list
3.shutdown immediate;
4.startup mount;
5.alter database archivelog;
6. alter database open;

因为没归档之前备份了一下,所以想清空一下之前的备份

2.rman操作

进入rman连接不上数据库,使用connect target /

但是仍报错 ora-06002 在没有连接至恢复目录时不允许使用命令,用命令crosscheck archivelog all使用目标数据库控制文件替代恢复目录

删除成功了,重新备份

3.测试恢复

删除所有文件

(1)恢复spfile文件

a.export ORACLE_SID=stg
b.sqlplus / as sysdba
c.startup force nomount
d.quit;
e.rman target / nocatalog
f.restore spfile to pfile '/u01/app/oracle/stg/stg/spfilestg.ora'
 from '/bak/stg/20190428/stg_lev0_201904281826_c-1124575224-20190428-04'
#此时参数文件已恢复成功,不知道是那个备份文件可以一个一个尝试
恢复成功后重启记得数据库

(2)恢复控制文件

g.restore controlfile from '/bak/stg/20190428/cntl_lev0.bak';
f.alter database mount;

(3)恢复数据文件

a.sql下  alter database open resetlogs;
b.rman下 根据报错输入restore datafile xx

记录:我将data下的数据文件全部清空后,所作的操作:

开启两个终端sql 和 ramn
sql :
export ORACLE_SID=stg;
sqlplus / as  sysdba
sql> startup force nomount;
SQL> startup mount;
ORACLE instance started.

Total System Global Area  576221184 bytes
Fixed Size		    2215464 bytes
Variable Size		  243270104 bytes
Database Buffers	  327155712 bytes
Redo Buffers		    3579904 bytes
Database mounted.


rman :
export ORACLE_SID=stg;
rman target / nocatalog
RMAN> recover database;

Starting recover at 29-APR-19
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/29/2019 15:39:46
ORA-00210: cannot open the specified control file

RMAN> restore controlfile from '//bak/stg/20190428/cntl_lev0.bak';  

Starting restore at 29-APR-19
using channel ORA_DISK_1

channel ORA_DISK_1: copied control file copy
output file name=/u01/app/oracle/stg/stg/control01.ctl
output file name=/u01/app/oracle/flash_recovery_area/stg/control02.ctl
Finished restore at 29-APR-19

RMAN> recover database;

Starting recover at 29-APR-19
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/29/2019 15:45:36
ORA-00210: cannot open the specified control file
#此时需要mount

sql :
sql>alter database mount;
SQL> alter database mount; 

Database altered.

rman :
RMAN> recover database;

Starting recover at 29-APR-19
Starting implicit crosscheck backup at 29-APR-19
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
Crosschecked 6 objects
Finished implicit crosscheck backup at 29-APR-19

Starting implicit crosscheck copy at 29-APR-19
using channel ORA_DISK_1
Crosschecked 2 objects
Finished implicit crosscheck copy at 29-APR-19

searching for all files in the recovery area
cataloging files...
no files cataloged

using channel ORA_DISK_1
RMAN-06900: WARNING: unable to generate V$RMAN_STATUS or V$RMAN_OUTPUT row
RMAN-06901: WARNING: disabling update of the V$RMAN_STATUS and V$RMAN_OUTPUT rows
ORACLE error from target database: 
ORA-19922: there is no parent row with id 0 and level 1

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/29/2019 15:47:38
RMAN-06094: datafile 1 must be restored

RMAN> restore datafile 1;

Starting restore at 29-APR-19
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/stg/stg/system01.dbf
channel ORA_DISK_1: reading from backup piece /bak/stg/20190428/stg_lev0_201904281826_0ku052ao_1_1
channel ORA_DISK_1: piece handle=/bak/stg/20190428/stg_lev0_201904281826_0ku052ao_1_1 tag=STG_LEV0_201904281826
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 29-APR-19

RMAN>  restore datafile 2;

Starting restore at 29-APR-19
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/stg/stg/sysaux01.dbf
channel ORA_DISK_1: reading from backup piece /bak/stg/20190428/stg_lev0_201904281826_0ku052ao_1_1
channel ORA_DISK_1: piece handle=/bak/stg/20190428/stg_lev0_201904281826_0ku052ao_1_1 tag=STG_LEV0_201904281826
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 29-APR-19

RMAN>  restore datafile 3;

Starting restore at 29-APR-19
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/stg/stg/undotbs01.dbf
channel ORA_DISK_1: reading from backup piece /bak/stg/20190428/stg_lev0_201904281826_0ju052ao_1_1
channel ORA_DISK_1: piece handle=/bak/stg/20190428/stg_lev0_201904281826_0ju052ao_1_1 tag=STG_LEV0_201904281826
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 29-APR-19

RMAN>  restore datafile 4;

Starting restore at 29-APR-19
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/stg/stg/users01.dbf
channel ORA_DISK_1: reading from backup piece /bak/stg/20190428/stg_lev0_201904281826_0ju052ao_1_1
channel ORA_DISK_1: piece handle=/bak/stg/20190428/stg_lev0_201904281826_0ju052ao_1_1 tag=STG_LEV0_201904281826
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:05
Finished restore at 29-APR-19

RMAN> recover database;

Starting recover at 29-APR-19
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=15
channel ORA_DISK_1: reading from backup piece /bak/stg/20190428/stg_lev0_201904281826_arc_0mu052ef_1_1
channel ORA_DISK_1: piece handle=/bak/stg/20190428/stg_lev0_201904281826_arc_0mu052ef_1_1 tag=STG_ARC_201904281826
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/flash_recovery_area/STG/archivelog/2019_04_29/o1_mf_1_15_gdfc8l6b_.arc thread=1 sequence=15
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/STG/archivelog/2019_04_29/o1_mf_1_15_gdfc8l6b_.arc RECID=7 STAMP=1006876306
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=16
channel ORA_DISK_1: reading from backup piece /bak/stg/20190428/stg_lev0_201904281826_arc_0nu052ef_1_1
channel ORA_DISK_1: piece handle=/bak/stg/20190428/stg_lev0_201904281826_arc_0nu052ef_1_1 tag=STG_ARC_201904281826
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/flash_recovery_area/STG/archivelog/2019_04_29/o1_mf_1_16_gdfc8mfp_.arc thread=1 sequence=16
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/STG/archivelog/2019_04_29/o1_mf_1_16_gdfc8mfp_.arc RECID=8 STAMP=1006876307
unable to find archived log
archived log thread=1 sequence=17
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/29/2019 15:51:48
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 17 and starting SCN of 10220387304368
#此错误的原因是恢复需要的日志记录在控制文件或恢复目录中找不到。解决方法分两种情况:
#1.如果相关的日志存在且可用的话,就将此日志记录添加到控制文件或恢复目录中。
#2.如果相关的日志已经被删除了或不可用了,那么就按照错误的提示scn将数据库恢复到此scn,本案例是#10220387304368。也就是说此时数据库只能进行不完全恢复了(可能是因为我恢复的是rman level 0,增量#是今天备份的,没有恢复今天的备份),在打开数#据库时得使用resetlogs打开。
RMAN> recover database until scn 10220387304368;

Starting recover at 29-APR-19
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 29-APR-19
#此时恢复完成
sql :
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open


SQL> alter database resetlogs;
alter database resetlogs
                       *
ERROR at line 1:
ORA-02231: missing or invalid option to ALTER DATABASE


SQL> alter database open resetlogs; 

Database altered.
#此时数据库已能使用


ps:1.关于dbid,备份的文件名字包含dbid

2.在报RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 17 and starting SCN of 10220387304368错误时的另种操作方式

unable to find archived log
archived log thread=1 sequence=17
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/29/2019 16:51:46
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 17 and starting SCN of 10220387304368

RMAN> list failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
1722       CRITICAL OPEN      29-APR-19     Control file needs media recovery

RMAN> advise failure;

List of Database Failures
=========================

Failure ID Priority Status    Time Detected Summary
---------- -------- --------- ------------- -------
1722       CRITICAL OPEN      29-APR-19     Control file needs media recovery

analyzing automatic repair options; this may take some time
using channel ORA_DISK_1
analyzing automatic repair options complete

Mandatory Manual Actions
========================
no manual actions available

Optional Manual Actions
=======================
1. If you have the correct version of the control file, then shutdown the database and replace the old control file

Automated Repair Options
========================
Option Repair Description
------ ------------------
1      Perform incomplete database recovery  
  Strategy: The repair includes point-in-time recovery with some data loss
  Repair script: /u01/app/oracle/diag/rdbms/stg/stg/hm/reco_3805060484.hm

RMAN> repair failure;

Strategy: The repair includes point-in-time recovery with some data loss
Repair script: /u01/app/oracle/diag/rdbms/stg/stg/hm/reco_3805060484.hm

contents of repair script:
   # database point-in-time recovery until a missing log
   restore database until scn 10220387304368;
   recover database until scn 10220387304368;
   alter database open resetlogs;

Do you really want to execute the above repair (enter YES or NO)? yes
executing repair script

Starting restore at 29-APR-19
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/stg/stg/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/stg/stg/sysaux01.dbf
channel ORA_DISK_1: reading from backup piece /bak/stg/20190428/stg_lev0_201904281826_0ku052ao_1_1
channel ORA_DISK_1: piece handle=/bak/stg/20190428/stg_lev0_201904281826_0ku052ao_1_1 tag=STG_LEV0_201904281826
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/stg/stg/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/stg/stg/users01.dbf
channel ORA_DISK_1: reading from backup piece /bak/stg/20190428/stg_lev0_201904281826_0ju052ao_1_1
channel ORA_DISK_1: piece handle=/bak/stg/20190428/stg_lev0_201904281826_0ju052ao_1_1 tag=STG_LEV0_201904281826
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:16
Finished restore at 29-APR-19

Starting recover at 29-APR-19
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=15
channel ORA_DISK_1: reading from backup piece /bak/stg/20190428/stg_lev0_201904281826_arc_0mu052ef_1_1
channel ORA_DISK_1: piece handle=/bak/stg/20190428/stg_lev0_201904281826_arc_0mu052ef_1_1 tag=STG_ARC_201904281826
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/flash_recovery_area/STG/archivelog/2019_04_29/o1_mf_1_15_gdfh20pj_.arc thread=1 sequence=15
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/STG/archivelog/2019_04_29/o1_mf_1_15_gdfh20pj_.arc RECID=9 STAMP=1006880193
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=16
channel ORA_DISK_1: reading from backup piece /bak/stg/20190428/stg_lev0_201904281826_arc_0nu052ef_1_1
channel ORA_DISK_1: piece handle=/bak/stg/20190428/stg_lev0_201904281826_arc_0nu052ef_1_1 tag=STG_ARC_201904281826
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/app/oracle/flash_recovery_area/STG/archivelog/2019_04_29/o1_mf_1_16_gdfh21s6_.arc thread=1 sequence=16
channel default: deleting archived log(s)
archived log file name=/u01/app/oracle/flash_recovery_area/STG/archivelog/2019_04_29/o1_mf_1_16_gdfh21s6_.arc RECID=10 STAMP=1006880193
media recovery complete, elapsed time: 00:00:01
Finished recover at 29-APR-19

database opened
repair failure complete

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值