[Oracle] 单实例rman备份异机恢复到rac环境


本文总阅读量

1、查询DBID信息

DBID是DataBase IDentifier的缩写,是数据库的唯一标识符。这个DBID在数据文件头和控制文件都是存在的,可以用于标示数据文件的归属。对于不同数据库来说,DBID应当不同,而db_name则可能是相同的。一般在nocatalog模式并且控制文件丢失时才需要这个。
查看源库的dbid

1
2
3
4
SYS@ testcadb> select name,dbid from v$database;
NAME DBID
--------- ----------
TESTCADB 2313387174

2、查看源库的数据文件路径

1
2
3
4
5
6
7
8
SYS@ testcadb> select file_id,file_name from dba_data_files;
FILE_ID FILE_NAME

4 /home/oracle/u01/app/oracle/oradata/testcadb/users01.dbf
3 /home/oracle/u01/app/oracle/oradata/testcadb/undotbs01.dbf
2 /home/oracle/u01/app/oracle/oradata/testcadb/sysaux01.dbf
1 /home/oracle/u01/app/oracle/oradata/testcadb/system01.dbf
5 /home/oracle/oradata/orcl/ebank_data.dbf

3、查看临时表空间数据文件

1
2
3
4
5
SYS@ testcadb> select * from dba_temp_files;
FILE_NAME FILE_ID TABLESPACE_NAME BYTES BLOCKS STATUS RELATIVE_FNO AUT MAXBYTES MAXBLOCKS INCREMENT_BY USER_BYTES USER_BLOCKS
-----------------------------------------------------------------------------------------------------------------------------------
/home/oracle/u01/app/oracle/oradata/testcadb/temp01.dbf 1 TEMP 20971520 2560 ONLINE 1 YES 3.4360E+10 4194302 80 19922944 2432
/home/oracle/oradata/orcl/test_temp01.dbf 2 TEST_TEMP 33554432 4096 ONLINE 1 YES 2147483648 262144 4096 32505856 3968

4、查看日志文件路径:

1
2
3
4
5
sql > select a.bytes/1024/1024,b.member,b.group#,a.thread# from v$log a,v$logfile b where a.group#=b.group#;
A.BYTES/1024/1024 MEMBER GROUP# THREAD#
50 /home/oracle/u01/app/oracle/oradata/testcadb/redo03.log 3 1
50 /home/oracle/u01/app/oracle/oradata/testcadb/redo02.log 2 1
50 /home/oracle/u01/app/oracle/oradata/testcadb/redo01.log 1 1

5、开始备份数据库(非归档模式的数据库需要在mount状态下执行)

1
2
3
4
5
6
7
8
9
10
11
shell > mkdir -p /tmp/backup/
shell > rman target /
RMAN> run {
allocate channel c1 device type disk;
backup incremental level 0 format '/tmp/backup/db_full_%U.bkp' tag '2018-12-19-FULL' database plus archivelog;
release channel c1;
}
备份控制文件
RMAN> backup current controlfile format '/tmp/backup/control20181219.bak';
备份pfile文件
RMAN> backup spfile format '/tmp/backup/spfile20181219.bak';

6、拷贝源库备份文件到目标库服务器

1
shell > scp /tmp/backup/* oracle@hostip*:/home/oracle/backup/

7、以下操作都是在目标节点上执行

8、查看文件权限,如果权限不对需要修改

1
shell > chown oracle.oinstall /home/oracle/backup/*

9、在节点1上执行恢复spfile文件:

1
2
3
4
5
6
7
8
9
10
11
生成临时pfile文件
shell > echo 'db_name=testcadb' > $ORACLE_HOME/dbs/inittestcadb1.ora
声明ORACLE_SID
shell > export ORACLE_SID=testcadb1
shell > rman target /
以临时pfile文件启动库到nomount:
rman > startup nomount pfile='/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/inittestcadb1.ora';
设置dbid
rman > set DBID=2313387174;
从备份中恢复spfile文件
rman > restore spfile to '/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/spfileoibs1.ora' from '/home/oracle/backup/spfile20181218.bak';

操作结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[oracle@rac1 backup]$ rman target /
恢复管理器: Release 11.2.0.4.0 - Production on 星期五 9月 23 14:13:35 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
RMAN> startup nomount pfile='/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/inittestcadb1.ora';
Oracle instance started
Total System Global Area 371654656 bytes
Fixed Size 2253304 bytes
Variable Size 314576392 bytes
Database Buffers 50331648 bytes
Redo Buffers 4493312 bytes

RMAN> set DBID=2313387174;
executing command: SET DBID

RMAN> restore spfile to '/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/spfiletestcadb1.ora' from '/home/oracle/backup/spfile20181219.bak';
Starting restore at 2018:12:19 10:25:18
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=134 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /home/oracle/backup/spfile20181218.bak
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 2018:12:19 10:25:20

根据生成的spfile文件生成pfile文件

1
2
[oracle@rac1 backup]$ sqlplus / as sysdba
sql > create pfile from spfile;

对生成的pfile文件进行修改
vim /u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/inittestcadb1.ora

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
*.__db_cache_size=969567232
*.__java_pool_size=16777216
*.__large_pool_size=184549376
*.__oracle_base='/home/oracle/u01/app/oracle'#ORACLE_BASE set from environment
*.__pga_aggregate_target=1617245696
*.__sga_target=1925868544
*.__shared_io_pool_size=0
*.__shared_pool_size=704643072
*.__streams_pool_size=0
*.aq_tm_processes=0
*.audit_file_dest='/u01/app/oracle/admin/testcadb/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='+DATA1/testcadb/control01.ctl','+DATA1/testcadb/control02.ctl'
*.cpu_count=3
*.db_block_size=8192
*.db_domain=''
*.db_name='testcadb'
*.db_recovery_file_dest='+ARCH'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=testcadbXDB)'
*.job_queue_processes=0
*.memory_target=3529482752
*.open_cursors=300
*.processes=400
*.remote_login_passwordfile='EXCLUSIVE'
*.resource_manager_plan='default_plan'
*.sessions=445
*.log_archive_dest_1='LOCATION=+ARCH/testcadb/archivelog'
*.log_archive_format='arch_%t_%s_%r.arc'
testcadb1.instance_name='testcadb1'
testcadb2.instance_name='testcadb2'
testcadb1.instance_number=1
testcadb2.instance_number=2
testcadb1.undo_tablespace='UNDOTBS1'
testcadb2.undo_tablespace='UNDOTBS2'
testcadb2.thread=2
testcadb1.thread=1
*.remote_listener='racscan:1521'

停止数据库

1
2
3
19:17:48 SYS@ testcadb1> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.

根据pfile文件中的设置路径,创建相应目录,oracle用户:

1
shell > mkdir -p /u01/app/oracle/admin/testcadb/adump

grid用户:

1
2
shell > asmcmd
asmcmd> mkdir ***

修改完成之后以pfile文件重新启动数据库

1
sql > startup nomount pfile='/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/inittestcadb1.ora';

根据pfile文件生成新的spfile文件

1
2
3
sql > create spfile='+DATA1/testcadb/spfiletestcadb.ora' from pfile;
SQL> shutdown abort
ORACLE instance shut down.

将所有的节点上pfile文件,指向共享文件上的spfile文件
rac1节点:

1
[oracle@rac1 ~]$ echo "SPFILE='+DATA1/testcadb/spfiletestcadb.ora' " > /u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/inittestcadb1.ora

rac2节点:

1
[oracle@rac2 ~]$ echo "SPFILE='+DATA1/testcadb/spfiletestcadb.ora' " > /u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/inittestcadb2.ora

10、还原数据库的controlfile

1
2
[oracle@rac2 ~]$ rman target /
rman > startup nomount

还原控制文件

1
rman > restore controlfile from '/home/oracle/backup/control20181219.bak';

启动到mount

1
rman > alter database mount;

11、还原数据库,指定备份文件到存放路径

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
rman > catalog start with '/home/oracle/backup';
rman > list backup summary;
执行下列run脚本(根据数据文件的不同作相应修改)
RMAN> run{
set newname for datafile '/home/oracle/u01/app/oracle/oradata/testcadb/users01.dbf' to '+DATA1/testcadb/users01.dbf';
set newname for datafile '/home/oracle/u01/app/oracle/oradata/testcadb/undotbs01.dbf' to '+DATA1/testcadb/undotbs01.dbf';
set newname for datafile '/home/oracle/u01/app/oracle/oradata/testcadb/sysaux01.dbf' to '+DATA1/testcadb/sysaux01.dbf';
set newname for datafile '/home/oracle/u01/app/oracle/oradata/testcadb/system01.dbf' to '+DATA1/testcadb/system01.dbf';
set newname for datafile '/home/oracle/oradata/orcl/ebank_data.dbf' to '+DATA1/testcadb/ebank_data.dbf';
restore database;
switch datafile all;
}
或者:
RMAN> run{
set newname for datafile 1 to '+DATA1/testcadb/users01.dbf';
set newname for datafile 2 to '+DATA1/testcadb/undotbs01.dbf';
set newname for datafile 3 to '+DATA1/testcadb/sysaux01.dbf';
set newname for datafile 4 to '+DATA1/testcadb/system01.dbf';
set newname for datafile 5 to '+DATA1/testcadb/ebank_data.dbf';
restore database;
switch datafile all;
}
查看备份的归档(如果是非归档模式的备份没有数据)
RMAN> list backup of archivelog all;
根据scn恢复数据库
RMAN> recover database until scn 2896925;
或者如果没有归档,直接恢复数据库
RMAN> recover database;

尝试打开数据库:

1
2
3
4
5
6
7
8
9
shell > sqlplus / as sysdba
sql > alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-00344: unable to re-create online log '/home/oracle/u01/app/oracle/oradata/testcadb/redo01.log'
ORA-27040: file create error, unable to create file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 1

提示redolog文件路径错误,重新生成redolog文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
sql > select group#,thread#,members,archived,status from v$log;

GROUP# THREAD# MEMBERS ARCHIV STATUS
---------- ---------- ---------- ------ --------------------------------
1 1 1 NO CLEARING
3 1 1 NO CLEARING_CURRENT
2 1 1 NO CLEARING
Elapsed: 00:00:00.03
删除原来的logfile
sql > alter database drop logfile group 1;
新增logfile(要保证redolog路径存在)
sql > alter database add logfile group 1 '+ARCH/testcadb/redolog/redo01.log' size 100M;
sql > alter database drop logfile group 2;
sql > alter database add logfile group 2 '+ARCH/testcadb/redolog/redo02.log' size 100M;
sql > alter database drop logfile group 3;
提示日志无法删除
sql > alter database drop logfile group 3;
alter database drop logfile group 3
*
ERROR at line 1:
ORA-01623: log 3 is current log for instance testcadb1 (thread 1) - cannot drop
ORA-00312: online log 3 thread 1: '/home/oracle/u01/app/oracle/oradata/testcadb/redo03.log'
对文件进行重命名
sql > alter database rename file '/home/oracle/u01/app/oracle/oradata/testcadb/redo03.log' to '+ARCH/testcadb/redolog/redo03.log';
sql > alter database clear logfile group 3;
因为日志文件大小还是按原来的大小,需要重新建
sql > alter database drop logfile group 3;
sql > alter database add logfile group 3 '+ARCH/testcadb/redolog/redo03.log' size 100M;
打开数据库
sql > alter database open resetlogs;
如果原库版本不一样(源库11.2.0.3目标库11.2.0.4)需要升级数据库
sql > startup mount;
sql > alter database open upgrade;
sql > select status from v$Instance;
sql > @$ORACLE_HOME/rdbms/admin/catupgrd.sql;

启动库之后临时表空间是不可用的,需要重新配置临时表空间:

1
2
3
4
5
6
sql > select * from dba_temp_files;
select * 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: '/home/oracle/u01/app/oracle/oradata/testcadb/temp01.dbf'

更换临时表空间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
创建中转临时表空间
sql > create TEMPORARY TABLESPACE TEMP2 TEMPFILE '+DATA1/testcadb/TEMP02.DBF' SIZE 2048M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE 5120M;
切换默认临时表空间
sql > alter database default temporary tablespace temp2;
sql >
sql > drop tablespace temp including contents and datafiles;
sql > create TEMPORARY TABLESPACE TEMP TEMPFILE '+DATA1/testcadb/TEMP01.DBF' SIZE 2048M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE 5120M;
sql > alter database default temporary tablespace temp;
或者 sql > alter user *** temporary tablespace temp;(修改单独某个用户的临时表空间)

sql > drop tablespace temp2 including contents and datafiles;
sql > select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARCHIV STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- ------ -------------------------------- ------------- ------------------- ------------ -------------------
1 1 25 104857600 512 1 NO INACTIVE 64817466 2018:12:19 14:19:09 64828852 2018:12:19 14:21:47
2 1 26 104857600 512 1 NO CURRENT 64828852 2018:12:19 14:21:47 2.8147E+14
3 1 24 52428800 512 1 NO INACTIVE 64807090 2018:12:19 14:18:29 64817466 2018:12:19 14:19:09

添加thread 2对应的logfile,用于分配给节点2

1
2
3
sql > alter database add logfile thread 2 group 4 '+ARCH/testcadb/redolog/redo04.log' size 100m;
sql > alter database add logfile thread 2 group 5 '+ARCH/testcadb/redolog/redo05.log' size 100m;
sql > alter database add logfile thread 2 group 6 '+ARCH/testcadb/redolog/redo06.log' size 100m;

启动thread2

1
2
3
4
5
6
sql > select thread#,status,enabled from v$thread;
THREAD# STATUS ENABLED
---------- ------------ ----------------
1 OPEN PUBLIC
2 CLOSED DISABLED
sql > alter database enable thread 2;

配置两个节点信息

1
2
3
4
5
6
sql > alter system set thread=1 scope=spfile sid='testcadb1';
sql > alter system set thread=2 scope=spfile sid='testcadb2';
sql > alter system set instance_number=1 scope=spfile sid='testcadb1';
sql > alter system set instance_number=2 scope=spfile sid='testcadb2';
sql > alter system set cluster_database_instances=2 scope=spfile;
sql > alter system set cluster_database=true scope=spfile;

为节点2添加undo表空间

1
2
3
sql > select substr(file_name,1,60) UNDO_FILES from dba_data_files where tablespace_name = 'UNDOTBS1' 
sql > create undo tablespace undotbs2 datafile '+data1/testcadb/undotbs02.dbf' size 200M;
sql > alter system set undo_tablespace='undotbs2' scope=spfile sid='testcadb2';

关闭节点1并重新启动,如果不重新启动节点1,直接启动节点2报一下错误:

1
ORA-01102: cannot mount database in EXCLUSIVE mode

启动节点2(在节点2操作)
节点2:注意audit目录是否存在,不存在手动创建一下

1
2
3
4
5
6
shell > mkdir -p /u01/app/oracle/admin/testcadb/adump
shell > export ORACLE_SID=testcadb2
shell > sqlplus / as sysdba
sql > startup nomount;
sql > alter database mount;
sql > alter database open;

至此数据库已经换成完成,但是恢复的数据库还没有注册到集群管理下

12、将数据库注册到集群下

在节点1使用oracle用户执行(不要使用grid用户)

1
2
3
[oracle@rac1 ~]$ srvctl add database -d testcadb -o /u01/app/oracle/product/11.2.0.4/dbhome_1 -p +DATA1/testcadb/spfiletestcadb.ora
[oracle@rac1 ~]$ srvctl add instance -d testcadb -i testcadb1 -n rac1
[oracle@rac1 ~]$ srvctl add instance -d testcadb -i testcadb2 -n rac2

重启数据库

1
2
3
[oracle@rac1 ~]$ srvctl stop database -d testcadb
#因为启动不是通过srvctl启动的,可能需要进入sqlplus控制台先手动关闭库(两个节点都要运行),然后通过下面命令启动数据库:
[oracle@rac1 ~]$ srvctl start database -d testcadb

13、查看监听有没有注册到scanip上,如果没有注册到scanip上继续下面的操作

1
2
3
4
5
6
7
8
9
10
sql > show parameter remote_listener;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_listener string racscan:1521
#grid用户执行:
shell > lsnrctl status LISTENER_SCAN1
#如果没有注册监听信息,按下面方法配置
alter system set remote_listener = 'racscan:1521' sid='*' scope=both;
alter system register;
lsnrctl status LISTENER_SCAN1

14、因为恢复过来的数据库没有passwordfile,存在sys用户远程登录问题

查看remote_login_passwordfile设置值

1
2
3
4
5
6
7
sql > show parameter remote_login_passwordfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile string EXCLUSIVE

修改值使用下面方法,修改完成之后,需要重新启动数据库才能生效:
alter system set remote_login_passwordfile='exclusive' scope=spfile sid='*';

查看详细的remote_login_passwordfile配置点击此处
remote_login_passwordfile修改完成之后,生成秘钥文件
节点1

1
orapwd file=orapwtestcadb1 password=oracle entries=100

节点2

1
orapwd file=orapwtestcadb2 password=oracle entries=100

现在,数据终于可以正常访问了。

目录
  1. 1. 1、查询DBID信息
  2. 2. 2、查看源库的数据文件路径
  3. 3. 3、查看临时表空间数据文件
  4. 4. 4、查看日志文件路径:
  5. 5. 5、开始备份数据库(非归档模式的数据库需要在mount状态下执行)
  6. 6. 6、拷贝源库备份文件到目标库服务器
  7. 7. 7、以下操作都是在目标节点上执行
  8. 8. 8、查看文件权限,如果权限不对需要修改
  9. 9. 9、在节点1上执行恢复spfile文件:
  10. 10. 10、还原数据库的controlfile
  11. 11. 11、还原数据库,指定备份文件到存放路径
  12. 12. 12、将数据库注册到集群下
  13. 13. 13、查看监听有没有注册到scanip上,如果没有注册到scanip上继续下面的操作
  14. 14. 14、因为恢复过来的数据库没有passwordfile,存在sys用户远程登录问题

Proudly powered by Hexo and Theme by Lap
本站访客数人次
© 2020 zeven0707's blog