【备份恢复】}异机备份恢复数据库
此实验是在B库上恢复A库,不过更改了实例名。
目标库只是按照到oracle软件为止。
源库(A库): 192.168.56.12 ORACLE_SID=DBdb DBID=3282897732
目标库(B库):192.168.56.28 ORACLE_SID=kill
源库备份(A库)联机全备:
全库备份加控制文件及归档备份;(热备)
run
{
backup database format '/home/oracle/BKdbfile_%d_%U_%T';
sql 'alter system archive log current';
#backup all archive logs
BACKUP FORMAT '/home/oracle/BKarch_%d_%U_%T'
ARCHIVELOG ALL DELETE INPUT;
BACKUP CURRENT CONTROLFILE FORMAT '/home/oracle/conbak.%u';
}
-本次只是全被数据库,没开自动控制文件备份,但是当数据库结构变化是,控制文件及spfile会自动备份
RMAN> backup database;
Starting backup at 11-DEC-17
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/DBdb/users01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/DBdb/undotbs01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/DBdb/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/DBdb/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/DBdb/example01.dbf
channel ORA_DISK_1: starting piece 1 at 11-DEC-17
channel ORA_DISK_1: finished piece 1 at 11-DEC-17
piece handle=/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_nnndf_TAG20171211T070728_f2vhkjlf_.bkp tag=TAG20171211T070728 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 11-DEC-17
channel ORA_DISK_1: finished piece 1 at 11-DEC-17
piece handle=/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp tag=TAG20171211T070728 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-DEC-17
目标库(B库操作):
[oracle@testdb ~]$ cat .bash_profile
export ORACLE_SID=kill
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export NLS_LANG="american_america.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:Mi:SS"
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
[oracle@testdb ~]$
注意:让ORACLE_BASE/ORACLE_HOME目录不一致时,可以不先设置环境变量文件,等到恢复后再设置。
1.拷贝RMAN备份文件:
创建相同目录并将源库RMAN备份文件拷贝到目标库 ,因为是用备份的控制文件进行恢复,而控制文件记录的备份位置如上。
[oracle@testdb ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/
[oracle@testdb ~]$ cd /u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/
[oracle@testdb 2017_12_11]$
[oracle@testdb 2017_12_11]$ scp oracle@192.168.56.12:/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_nnndf_TAG20171211T070728_f2vhkjlf_.bkp .
oracle@192.168.56.12's password:
o1_mf_nnndf_TAG20171211T070728_f2vhkjlf_.bkp 100% 1351MB 28.1MB/s 00:48
[oracle@testdb 2017_12_11]$
[oracle@testdb 2017_12_11]$ scp oracle@192.168.56.12:/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp .
oracle@192.168.56.12's password:
o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp 100% 10MB 9.9MB/s 00:00
[oracle@testdb 2017_12_11]$
2.配置目标数据库:
目标库设置环境变量,启动rman到nomount状态,设置dbid(即源库dbid)
[oracle@testdb 2017_12_25]$ echo $ORACLE_SID
kill
[oracle@testdb 2017_12_25]$
[oracle@testdb 2017_12_25]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Dec 25 16:29:37 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
RMAN> set dbid 3282897732
executing command: SET DBID
RMAN>
set dbid,从字面上也可以看出其就是指定数据库的ID,和controlfile里的DBID一致 。
如果用如下命令启动数据库到NOMOUNT状态
RMAN> startup nomount;
此时RMAN是可以使用一个dummy参数文件启动实例到NOMOUNT状态
即虚拟一个db name为DUMMY的DB,这个dbname在备份中是没有的
因此需要设定dbid,RMAN以此确定用哪个备份。
3.目标库启动到nomount模式:
此时会报错,原因是,目标库没有参数文件,但也是能启动到nomount模式,分配内存、启动后台进程
RMAN> startup nomount;
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initkill.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
Total System Global Area 1068937216 bytes
Fixed Size 2260088 bytes
Variable Size 281019272 bytes
Database Buffers 780140544 bytes
Redo Buffers 5517312 bytes
RMAN>
4.恢复参数文件:
RMAN> restore spfile to pfile '?/dbs/initkill.ora' from '/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp';
Starting restore at 2017-12-25 18:13:44
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 2017-12-25 18:13:46
--查看恢复的pfile文件;
[oracle@testdb ~]$ cd $ORACLE_HOME/dbs
[oracle@testdb dbs]$ ls
hc_kill.dat initkill.ora init.ora
[oracle@testdb dbs]$
5.编辑pfile参数文件:
编辑pfile参数文件并且在目标库创建相关目录,因为目标库只安装了数据库软件,所以,好多目录都未创建,或源库目录与目标库目录不同
[oracle@testdb dbs]$ vi initkill.ora
kill.__db_cache_size=394264576
kill.__java_pool_size=4194304
kill.__large_pool_size=8388608
kill.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
kill.__pga_aggregate_target=293601280
kill.__sga_target=545259520
kill.__shared_io_pool_size=0
kill.__shared_pool_size=130023424
kill.__streams_pool_size=0
*._optimizer_adaptive_cursor_sharing=FALSE
*._optimizer_extended_cursor_sharing='NONE'
*._optimizer_extended_cursor_sharing_rel='NONE'
*.audit_file_dest='/u01/app/oracle/admin/kill/adump'
*.audit_trail='DB'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/kill/control01.ctl','/u01/app/oracle/fast_recovery_area/kill/control02.ctl'#Restore Controlfile
*.db_block_size=8192
*.db_domain=''
*.db_name='DBdb'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area/kill/newback'
*.db_recovery_file_dest_size=9663676416
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=DBdbXDB)'
*.filesystemio_options='ASYNCH'
*.memory_target=838860800
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.service_names='service1,service2,service3'
*.undo_tablespace='UNDOTBS1'
[oracle@testdb dbs]$
--按照pfile参数文件创建相应目录
[oracle@testdb dbs]$ mkdir -p /u01/app/oracle/admin/kill/adump
[oracle@testdb dbs]$ mkdir -p /u01/app/oracle/oradata/kill
[oracle@testdb dbs]$ mkdir -p /u01/app/oracle/fast_recovery_area/kill
[oracle@testdb dbs]$ mkdir -p /u01/app/oracle/fast_recovery_area/kill/newback
[oracle@testdb dbs]$
6.通过pfile启动数据库到nomount模式,测试pfile是否有修改参数
[oracle@testdb dbs]$ echo $ORACLE_SID
kill
[oracle@testdb dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 25 18:18:57 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string
SQL>
SQL> create spfile from pfile;
File created.
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL>
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 549456976 bytes
Database Buffers 281018368 bytes
Redo Buffers 2371584 bytes
SQL>
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
spfile string /u01/app/oracle/product/11.2.0
/dbhome_1/dbs/spfilekill.ora
6..还原控制文件:
还原控制文件并启动到mount模式
[oracle@testdb ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Dec 25 18:21:51 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: DBDB (not mounted)
RMAN> restore controlfile from '/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp';
Starting restore at 2017-12-25 18:22:13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/kill/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/kill/control02.ctl
Finished restore at 2017-12-25 18:22:15
RMAN>
--启库到mount下:
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
7.还原数据文件(即set newname):
RMAN> run{
set newname for datafile 1 to '/u01/app/oracle/oradata/kill/system01.dbf';
set newname for datafile 2 to '/u01/app/oracle/oradata/kill/sysaux01.dbf';
set newname for datafile 3 to '/u01/app/oracle/oradata/kill/undotbs01.dbf';
set newname for datafile 4 to '/u01/app/oracle/oradata/kill/users01.dbf';
set newname for datafile 5 to '/u01/app/oracle/oradata/kill/example01.dbf';
restore database;
switch datafile all;
recover database;
}
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 2017-12-25 17:12:18
Starting implicit crosscheck backup at 2017-12-25 17:12:18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 2017-12-25 17:12:19
Starting implicit crosscheck copy at 2017-12-25 17:12:19
using channel ORA_DISK_1
Finished implicit crosscheck copy at 2017-12-25 17:12:19
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_12_25/o1_mf_ncsnf_TAG20171225T125632_f411cfmz_.bkp
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/oradata/kill/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/kill/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/kill/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/kill/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/kill/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_12_25/o1_mf_nnndf_TAG20171225T125632_f4118147_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_12_25/o1_mf_nnndf_TAG20171225T125632_f4118147_.bkp tag=TAG20171225T125632
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:45
Finished restore at 2017-12-25 17:14:05
datafile 1 switched to datafile copy
input datafile copy RECID=7 STAMP=963681246 file name=/u01/app/oracle/oradata/kill/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=963681246 file name=/u01/app/oracle/oradata/kill/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=9 STAMP=963681246 file name=/u01/app/oracle/oradata/kill/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=10 STAMP=963681247 file name=/u01/app/oracle/oradata/kill/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=11 STAMP=963681247 file name=/u01/app/oracle/oradata/kill/example01.dbf
Starting recover at 2017-12-25 17:14:07
using channel ORA_DISK_1
starting media recovery
unable to find archived log
archived log thread=1 sequence=138
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 12/25/2017 17:14:08
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 138 and starting SCN of 5021427
RMAN>
--此处我们会发现,在recover的时候,由于没有归档日志,所以,提示只能恢复到SCN 5021427
RMAN> run{
set until scn 5456222;
restore database;
switch datafile all;
recover database;
}
executing command: SET until clause
Starting restore at 2017-12-25 18:29:57
using channel ORA_DISK_1
skipping datafile 1; already restored to file /u01/app/oracle/oradata/kill/system01.dbf
skipping datafile 2; already restored to file /u01/app/oracle/oradata/kill/sysaux01.dbf
skipping datafile 3; already restored to file /u01/app/oracle/oradata/kill/undotbs01.dbf
skipping datafile 4; already restored to file /u01/app/oracle/oradata/kill/users01.dbf
skipping datafile 5; already restored to file /u01/app/oracle/oradata/kill/example01.dbf
restore not done; all files read only, offline, or already restored
Finished restore at 2017-12-25 18:29:58
Starting recover at 2017-12-25 18:29:58
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 2017-12-25 18:29:58
RMAN>
8.Resetlogs方式打开数据库:
RMAN> alter database open resetlogs;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 12/25/2017 18:31:24
ORA-00344: unable to re-create online log '/u01/app/oracle/oradata/DBdb/redo01.log'
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 1
报错因为此时数据库SID为kill,不一致导致。
--查看源库有三个日志组,需转换路径:
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/DBdb/redo03.log
/u01/app/oracle/oradata/DBdb/redo02.log
/u01/app/oracle/oradata/DBdb/redo01.log
--开始转换:
run{
sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo01.log'' to ''/u01/app/oracle/oradata/kill/redo01.log'' ";
sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo02.log'' to ''/u01/app/oracle/oradata/kill/redo02.log'' ";
sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo03.log'' to ''/u01/app/oracle/oradata/kill/redo03.log'' ";
}
RMAN> run{
2> sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo01.log'' to ''/u01/app/oracle/oradata/kill/redo01.log'' ";
3> sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo02.log'' to ''/u01/app/oracle/oradata/kill/redo02.log'' ";
4> sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo03.log'' to ''/u01/app/oracle/oradata/kill/redo03.log'' ";
5> }
sql statement: alter database rename file ''/u01/app/oracle/oradata/DBdb/redo01.log'' to ''/u01/app/oracle/oradata/kill/redo01.log''
sql statement: alter database rename file ''/u01/app/oracle/oradata/DBdb/redo02.log'' to ''/u01/app/oracle/oradata/kill/redo02.log''
sql statement: alter database rename file ''/u01/app/oracle/oradata/DBdb/redo03.log'' to ''/u01/app/oracle/oradata/kill/redo03.log''
RMAN>
--再次resetlogs方式启动数据库:
RMAN> alter database open resetlogs;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 12/25/2017 18:38:39
ORA-00392: log 1 of thread 1 is being cleared, operation not allowed
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/kill/redo01.log'
RMAN>
--解决:手工clear然后再Open resetlogs
RMAN> sql 'alter database clear logfile group 1';
sql statement: alter database clear logfile group 1
RMAN>
RMAN> alter database open resetlogs;
database opened
RMAN>
9.收尾工作:
此时已经open了数据库,看似已经完成恢复,但其实还差一点点,我们查询临时表空间数据文件时,会报如下错误,可以看出来,还是由于我们改换了实例名造成的。
[oracle@testdb kill]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 25 18:42:09 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select status from v$instance;
STATUS
------------
OPEN
SQL>
SQL> select file_name from dba_temp_files;
select file_name from dba_temp_files
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 201 - see DBWR trace file
ORA-01110: data file 201: '/u01/app/oracle/oradata/DBdb/temp01.dbf'
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string DBdb
db_unique_name string DBdb
global_names boolean FALSE
instance_name string kill
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string service1,service2,service3
--解决这个错误,如下操作:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 549456976 bytes
Database Buffers 281018368 bytes
Redo Buffers 2371584 bytes
Database mounted.
SQL>
SQL> alter database rename file '/u01/app/oracle/oradata/DBdb/temp01.dbf' to '/u01/app/oracle/oradata/kill/temp01.dbf';
Database altered.
SQL> alter database open;
Database altered.
SQL> select file_name from dba_temp_files;
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/kill/temp01.dbf
SQL>
b库alert_01.txt
b库alert_02.txt
网页标题:【备份恢复】}异机备份恢复数据库
网页URL:http://pwwzsj.com/article/pisdoi.html
目标库只是按照到oracle软件为止。
源库(A库): 192.168.56.12 ORACLE_SID=DBdb DBID=3282897732
目标库(B库):192.168.56.28 ORACLE_SID=kill
源库备份(A库)联机全备:
全库备份加控制文件及归档备份;(热备)
run
{
backup database format '/home/oracle/BKdbfile_%d_%U_%T';
sql 'alter system archive log current';
#backup all archive logs
BACKUP FORMAT '/home/oracle/BKarch_%d_%U_%T'
ARCHIVELOG ALL DELETE INPUT;
BACKUP CURRENT CONTROLFILE FORMAT '/home/oracle/conbak.%u';
}
-本次只是全被数据库,没开自动控制文件备份,但是当数据库结构变化是,控制文件及spfile会自动备份
RMAN> backup database;
Starting backup at 11-DEC-17
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/DBdb/users01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/DBdb/undotbs01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/DBdb/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/DBdb/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/DBdb/example01.dbf
channel ORA_DISK_1: starting piece 1 at 11-DEC-17
channel ORA_DISK_1: finished piece 1 at 11-DEC-17
piece handle=/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_nnndf_TAG20171211T070728_f2vhkjlf_.bkp tag=TAG20171211T070728 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 11-DEC-17
channel ORA_DISK_1: finished piece 1 at 11-DEC-17
piece handle=/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp tag=TAG20171211T070728 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-DEC-17
目标库(B库操作):
[oracle@testdb ~]$ cat .bash_profile
export ORACLE_SID=kill
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export NLS_LANG="american_america.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:Mi:SS"
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
[oracle@testdb ~]$
注意:让ORACLE_BASE/ORACLE_HOME目录不一致时,可以不先设置环境变量文件,等到恢复后再设置。
1.拷贝RMAN备份文件:
创建相同目录并将源库RMAN备份文件拷贝到目标库 ,因为是用备份的控制文件进行恢复,而控制文件记录的备份位置如上。
[oracle@testdb ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/
[oracle@testdb ~]$ cd /u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/
[oracle@testdb 2017_12_11]$
[oracle@testdb 2017_12_11]$ scp oracle@192.168.56.12:/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_nnndf_TAG20171211T070728_f2vhkjlf_.bkp .
oracle@192.168.56.12's password:
o1_mf_nnndf_TAG20171211T070728_f2vhkjlf_.bkp 100% 1351MB 28.1MB/s 00:48
[oracle@testdb 2017_12_11]$
[oracle@testdb 2017_12_11]$ scp oracle@192.168.56.12:/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp .
oracle@192.168.56.12's password:
o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp 100% 10MB 9.9MB/s 00:00
[oracle@testdb 2017_12_11]$
2.配置目标数据库:
目标库设置环境变量,启动rman到nomount状态,设置dbid(即源库dbid)
[oracle@testdb 2017_12_25]$ echo $ORACLE_SID
kill
[oracle@testdb 2017_12_25]$
[oracle@testdb 2017_12_25]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Dec 25 16:29:37 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
RMAN> set dbid 3282897732
executing command: SET DBID
RMAN>
set dbid,从字面上也可以看出其就是指定数据库的ID,和controlfile里的DBID一致 。
如果用如下命令启动数据库到NOMOUNT状态
RMAN> startup nomount;
此时RMAN是可以使用一个dummy参数文件启动实例到NOMOUNT状态
即虚拟一个db name为DUMMY的DB,这个dbname在备份中是没有的
因此需要设定dbid,RMAN以此确定用哪个备份。
3.目标库启动到nomount模式:
此时会报错,原因是,目标库没有参数文件,但也是能启动到nomount模式,分配内存、启动后台进程
RMAN> startup nomount;
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initkill.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
Total System Global Area 1068937216 bytes
Fixed Size 2260088 bytes
Variable Size 281019272 bytes
Database Buffers 780140544 bytes
Redo Buffers 5517312 bytes
RMAN>
4.恢复参数文件:
RMAN> restore spfile to pfile '?/dbs/initkill.ora' from '/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp';
Starting restore at 2017-12-25 18:13:44
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 2017-12-25 18:13:46
--查看恢复的pfile文件;
[oracle@testdb ~]$ cd $ORACLE_HOME/dbs
[oracle@testdb dbs]$ ls
hc_kill.dat initkill.ora init.ora
[oracle@testdb dbs]$
5.编辑pfile参数文件:
编辑pfile参数文件并且在目标库创建相关目录,因为目标库只安装了数据库软件,所以,好多目录都未创建,或源库目录与目标库目录不同
[oracle@testdb dbs]$ vi initkill.ora
kill.__db_cache_size=394264576
kill.__java_pool_size=4194304
kill.__large_pool_size=8388608
kill.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
kill.__pga_aggregate_target=293601280
kill.__sga_target=545259520
kill.__shared_io_pool_size=0
kill.__shared_pool_size=130023424
kill.__streams_pool_size=0
*._optimizer_adaptive_cursor_sharing=FALSE
*._optimizer_extended_cursor_sharing='NONE'
*._optimizer_extended_cursor_sharing_rel='NONE'
*.audit_file_dest='/u01/app/oracle/admin/kill/adump'
*.audit_trail='DB'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/kill/control01.ctl','/u01/app/oracle/fast_recovery_area/kill/control02.ctl'#Restore Controlfile
*.db_block_size=8192
*.db_domain=''
*.db_name='DBdb'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area/kill/newback'
*.db_recovery_file_dest_size=9663676416
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=DBdbXDB)'
*.filesystemio_options='ASYNCH'
*.memory_target=838860800
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.service_names='service1,service2,service3'
*.undo_tablespace='UNDOTBS1'
[oracle@testdb dbs]$
--按照pfile参数文件创建相应目录
[oracle@testdb dbs]$ mkdir -p /u01/app/oracle/admin/kill/adump
[oracle@testdb dbs]$ mkdir -p /u01/app/oracle/oradata/kill
[oracle@testdb dbs]$ mkdir -p /u01/app/oracle/fast_recovery_area/kill
[oracle@testdb dbs]$ mkdir -p /u01/app/oracle/fast_recovery_area/kill/newback
[oracle@testdb dbs]$
6.通过pfile启动数据库到nomount模式,测试pfile是否有修改参数
[oracle@testdb dbs]$ echo $ORACLE_SID
kill
[oracle@testdb dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 25 18:18:57 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string
SQL>
SQL> create spfile from pfile;
File created.
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL>
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 549456976 bytes
Database Buffers 281018368 bytes
Redo Buffers 2371584 bytes
SQL>
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
spfile string /u01/app/oracle/product/11.2.0
/dbhome_1/dbs/spfilekill.ora
6..还原控制文件:
还原控制文件并启动到mount模式
[oracle@testdb ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Dec 25 18:21:51 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: DBDB (not mounted)
RMAN> restore controlfile from '/u01/app/oracle/fast_recovery_area/DBDB/newback/DBDB/backupset/2017_12_11/o1_mf_ncsnf_TAG20171211T070728_f2vhm8nz_.bkp';
Starting restore at 2017-12-25 18:22:13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/kill/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/kill/control02.ctl
Finished restore at 2017-12-25 18:22:15
RMAN>
--启库到mount下:
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
7.还原数据文件(即set newname):
RMAN> run{
set newname for datafile 1 to '/u01/app/oracle/oradata/kill/system01.dbf';
set newname for datafile 2 to '/u01/app/oracle/oradata/kill/sysaux01.dbf';
set newname for datafile 3 to '/u01/app/oracle/oradata/kill/undotbs01.dbf';
set newname for datafile 4 to '/u01/app/oracle/oradata/kill/users01.dbf';
set newname for datafile 5 to '/u01/app/oracle/oradata/kill/example01.dbf';
restore database;
switch datafile all;
recover database;
}
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 2017-12-25 17:12:18
Starting implicit crosscheck backup at 2017-12-25 17:12:18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 2017-12-25 17:12:19
Starting implicit crosscheck copy at 2017-12-25 17:12:19
using channel ORA_DISK_1
Finished implicit crosscheck copy at 2017-12-25 17:12:19
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_12_25/o1_mf_ncsnf_TAG20171225T125632_f411cfmz_.bkp
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/oradata/kill/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/kill/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/kill/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/kill/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/kill/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_12_25/o1_mf_nnndf_TAG20171225T125632_f4118147_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/ORCL/backupset/2017_12_25/o1_mf_nnndf_TAG20171225T125632_f4118147_.bkp tag=TAG20171225T125632
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:45
Finished restore at 2017-12-25 17:14:05
datafile 1 switched to datafile copy
input datafile copy RECID=7 STAMP=963681246 file name=/u01/app/oracle/oradata/kill/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=963681246 file name=/u01/app/oracle/oradata/kill/undotbs01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=9 STAMP=963681246 file name=/u01/app/oracle/oradata/kill/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=10 STAMP=963681247 file name=/u01/app/oracle/oradata/kill/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=11 STAMP=963681247 file name=/u01/app/oracle/oradata/kill/example01.dbf
Starting recover at 2017-12-25 17:14:07
using channel ORA_DISK_1
starting media recovery
unable to find archived log
archived log thread=1 sequence=138
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 12/25/2017 17:14:08
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 138 and starting SCN of 5021427
RMAN>
--此处我们会发现,在recover的时候,由于没有归档日志,所以,提示只能恢复到SCN 5021427
RMAN> run{
set until scn 5456222;
restore database;
switch datafile all;
recover database;
}
executing command: SET until clause
Starting restore at 2017-12-25 18:29:57
using channel ORA_DISK_1
skipping datafile 1; already restored to file /u01/app/oracle/oradata/kill/system01.dbf
skipping datafile 2; already restored to file /u01/app/oracle/oradata/kill/sysaux01.dbf
skipping datafile 3; already restored to file /u01/app/oracle/oradata/kill/undotbs01.dbf
skipping datafile 4; already restored to file /u01/app/oracle/oradata/kill/users01.dbf
skipping datafile 5; already restored to file /u01/app/oracle/oradata/kill/example01.dbf
restore not done; all files read only, offline, or already restored
Finished restore at 2017-12-25 18:29:58
Starting recover at 2017-12-25 18:29:58
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 2017-12-25 18:29:58
RMAN>
8.Resetlogs方式打开数据库:
RMAN> alter database open resetlogs;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 12/25/2017 18:31:24
ORA-00344: unable to re-create online log '/u01/app/oracle/oradata/DBdb/redo01.log'
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 1
报错因为此时数据库SID为kill,不一致导致。
--查看源库有三个日志组,需转换路径:
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/DBdb/redo03.log
/u01/app/oracle/oradata/DBdb/redo02.log
/u01/app/oracle/oradata/DBdb/redo01.log
--开始转换:
run{
sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo01.log'' to ''/u01/app/oracle/oradata/kill/redo01.log'' ";
sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo02.log'' to ''/u01/app/oracle/oradata/kill/redo02.log'' ";
sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo03.log'' to ''/u01/app/oracle/oradata/kill/redo03.log'' ";
}
RMAN> run{
2> sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo01.log'' to ''/u01/app/oracle/oradata/kill/redo01.log'' ";
3> sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo02.log'' to ''/u01/app/oracle/oradata/kill/redo02.log'' ";
4> sql "alter database rename file ''/u01/app/oracle/oradata/DBdb/redo03.log'' to ''/u01/app/oracle/oradata/kill/redo03.log'' ";
5> }
sql statement: alter database rename file ''/u01/app/oracle/oradata/DBdb/redo01.log'' to ''/u01/app/oracle/oradata/kill/redo01.log''
sql statement: alter database rename file ''/u01/app/oracle/oradata/DBdb/redo02.log'' to ''/u01/app/oracle/oradata/kill/redo02.log''
sql statement: alter database rename file ''/u01/app/oracle/oradata/DBdb/redo03.log'' to ''/u01/app/oracle/oradata/kill/redo03.log''
RMAN>
--再次resetlogs方式启动数据库:
RMAN> alter database open resetlogs;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 12/25/2017 18:38:39
ORA-00392: log 1 of thread 1 is being cleared, operation not allowed
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/kill/redo01.log'
RMAN>
--解决:手工clear然后再Open resetlogs
RMAN> sql 'alter database clear logfile group 1';
sql statement: alter database clear logfile group 1
RMAN>
RMAN> alter database open resetlogs;
database opened
RMAN>
9.收尾工作:
此时已经open了数据库,看似已经完成恢复,但其实还差一点点,我们查询临时表空间数据文件时,会报如下错误,可以看出来,还是由于我们改换了实例名造成的。
[oracle@testdb kill]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 25 18:42:09 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select status from v$instance;
STATUS
------------
OPEN
SQL>
SQL> select file_name from dba_temp_files;
select file_name from dba_temp_files
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 201 - see DBWR trace file
ORA-01110: data file 201: '/u01/app/oracle/oradata/DBdb/temp01.dbf'
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string DBdb
db_unique_name string DBdb
global_names boolean FALSE
instance_name string kill
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string service1,service2,service3
--解决这个错误,如下操作:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 549456976 bytes
Database Buffers 281018368 bytes
Redo Buffers 2371584 bytes
Database mounted.
SQL>
SQL> alter database rename file '/u01/app/oracle/oradata/DBdb/temp01.dbf' to '/u01/app/oracle/oradata/kill/temp01.dbf';
Database altered.
SQL> alter database open;
Database altered.
SQL> select file_name from dba_temp_files;
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/kill/temp01.dbf
SQL>
b库alert_01.txt
b库alert_02.txt
网页标题:【备份恢复】}异机备份恢复数据库
网页URL:http://pwwzsj.com/article/pisdoi.html