RMAN Incomplete Recovery Quick Reference Manual

Summary: Scenario: Server A is a normal production environment, and a set of the same environment needs to be deployed on Server B for testing. The article introduces the whole process of using RMAN to restore the database incompletely to a certain SCN and OPEN on a different machine. It is recommended to save it for backup.

 

Application scenario : Server A is a normal production environment, and a set of the same environment needs to be deployed on server B for testing.
Database environment : RHEL6.4 + Oracle 11.2.0.4.7

1. Server A backs up the database

1.1 Online backup (database runs in archive mode)

nohup /bin/bash backup_all.sh &

After the backup, transfer all the backup media to server B (if the two machines are connected to the network, consider combining the NFS service to back up to server B from the beginning).

1.2 Backup script content

#!/bin/bash
#ScriptName:backup_all.sh
#Usage: backup all files in oracle user environment.
#ex: nohup /bin/bash backup_all.sh > backup.log & 
#Author: Alfred Zhao
#Creation: 2015-09-11
#Version: 1.0.0

#Define variable <You may need to change the value of basedir.>
basedir=/u01/orabak
date=`date +%Y%m%d`

#Create pfile
sqlplus / as sysdba <<EOF
create pfile='$basedir/pfile$date.ora' from spfile;
EOF

#RMAN BACKUP
rman target / log=$basedir/backup_all_$date.log <<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup database filesperset 4 format '$basedir/full_%d_%T_%s_%p';
sql 'alter system archive log current';
sql 'alter system archive log current';
sql 'alter system archive log current';
sql 'alter system archive log current';
backup archivelog all format '$basedir/arch_%d_%T_%s_%p' delete input;
backup current controlfile format '$basedir/ctl_%d_%T_%s_%p';
release channel c1;
release channel c2;
}
EOF

2. Server B restores the database

2.1 Server B install database software

Refer to the Motian Wheel document to install the database software and previous related configurations.
Then create a password file:

orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle force=y entries=5

2.2 Start the instance to the nomount state (specify the pfile file)

Copy the $basedir/pfile$date.orafile to $ORACLE_HOME/dbs/init$ORACLE_SID.oraand modify it according to the actual situation of server B. Then start the instance to the nomount state (specify the pfile file).

startup nomount pfile='$ORACLE_HOME/dbs/init$ORACLE_SID.ora'

2.3 RMAN restores the control file to determine the validity of the backup set

2.3.1 RMAN restores the control file, starts the database to mount state, and determines the validity of the backup set

backupControlFile=/u01/orabak/backup/ctl_JINGYU_20150911_46_1
rman target / > crosscheck.log <<EOF
restore controlfile from '$backupControlFile';
alter database mount;
crosscheck backupset;
EOF

2.3.2 If the backup set is invalid, delete the invalid backup set and manually register the backup set

Generally, the backup directories of the two hosts are different. The backup set path recorded in the control file cannot find the corresponding backup set, and the status is'EXPIRED'. At this time, you should delete these expired backup sets, catalog the new backup set, and confirm again The validity of the backup set.

rman target / > catalog.log <<EOF
catalog backuppiece '/u01/orabak/backup/full_JINGYU_20150911_39_1';
catalog backuppiece '/u01/orabak/backup/full_JINGYU_20150911_40_1';
catalog backuppiece '/u01/orabak/backup/full_JINGYU_20150911_41_1';
catalog backuppiece '/u01/orabak/backup/full_JINGYU_20150911_42_1';
catalog backuppiece '/u01/orabak/backup/arch_JINGYU_20150911_43_1';
catalog backuppiece '/u01/orabak/backup/arch_JINGYU_20150911_44_1';
catalog backuppiece '/u01/orabak/backup/arch_JINGYU_20150911_45_1';
crosscheck backupset;
delete noprompt expired backupset;
EOF

2.4 RMAN recovery database

2.4.1 Restore data file

If the data file storage directory has been changed, it needs to be renamed and restored.

rman target / log=restore.log <<EOF
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
set newname for datafile 1 to '/u01/oradata02/o1_mf_system_01.dbf';
set newname for datafile 2 to '/u01/oradata02/o1_mf_sysaux_01.dbf';
set newname for datafile 3 to '/u01/oradata02/o1_mf_undotbs1_01.dbf';
set newname for datafile 4 to '/u01/oradata02/o1_mf_users_01.dbf';
set newname for datafile 5 to '/u01/oradata02/o1_mf_dbs_d_ji_01.dbf';
set newname for datafile 6 to '/u01/oradata02/o1_mf_dbs_d_lu_01.dbf';
set newname for datafile 7 to '/u01/oradata02/o1_mf_dbs_d_xx_01.dbf';
set newname for datafile 8 to '/u01/oradata02/o1_mf_dbs_i_xx_01.dbf';
restore database;   
switch datafile all;
release channel c1;
release channel c2;
}
EOF

2.4.2 recover data file

2.4.2.1 recover database;

rman target / log=recover.log <<EOF 
recover database;
EOF

2.4.2.2 recover database until scn xxxxxxx;

scn=1463689
rman target / log=recover$scn.log <<EOF
recover database until scn $scn;
EOF

This scn is obtained according to the log information in the previous step.

2.4.3 Modify the log file path

new_dest=/usr3/oradata/sysdata/redo_file
sqlplus / as sysdba > logfile.log<<EOF
set linesize 180 pagesize 100
select 'alter database rename file '''||member||''' to ''$new_dest/redoXXX.log'';' from v\$logfile;
EOF

Note: You can use the UE column editing mode to quickly process the new redo file name (that is, redoXXX.log is changed to the corresponding actual value).

2.4.4 Modify the temporary file path

new_dest=/usr3/oradata/sysdata
sqlplus / as sysdba > tempfile.log<<EOF
set linesize 180 pagesize 100
select 'alter database rename file '''||name||''' to ''$new_dest/tempXXX.dbf'';' from v\$tempfile;
EOF

 

Note: The new temp file name is also processed (that is, tempXXX.dbf is changed to the corresponding actual value).

2.4.5 Open the database (resetlogs)

sqlplus / as sysdba > dbopen.log<<EOF
alter database open resetlogs;
EOF

 

Redo files and temp files are automatically created during the startup process.

2.5 Operations after recovery

2.5.1 View basic database information

View the status of database instances and libraries, data files, temporary files, log files, control files, parameter file path information.

sqlplus / as sysdba > dbstatus.log <<EOF
select instance_name, status from v\$instance;
select dbid, open_mode from v\$database;
select file_name from dba_data_files;
select file_name from dba_temp_files;
select member from v\$logfile;
show parameter control
show parameter pfile
EOF

 

2.5.2 Create spfile file, restart the database

Create spfile file

sqlplus / as sysdba > createSpfile.log <<EOF
create spfile from pfile;
EOF

 

Close the database

sqlplus / as sysdba > shutdownDB.log <<EOF
shutdown immediate
EOF

 

Start the database

sqlplus / as sysdba > startDB.log <<EOF
startup
EOF

 

2.5.3 Monitoring configuration

Modify the listening configuration file: $ORACLE_HOME/network/admin/listener.ora

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = JY-DB02)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

 

ADR_BASE_LISTENER = /u01/app/oracle
corresponds to 3 modifications related to the server host name:

1. hostname显示正确主机名 2. /etc/sysconfig/network中HOSTNAME配置 3. /etc/hosts中IP地址和主机名的对应关系

Start monitoring and view monitoring status:

lsnrctl start
lsnrctl status

 

Guess you like

Origin blog.csdn.net/weixin_41086692/article/details/103392151