Oracle RMAN异机迁移数据库从文件系统至ASM

Oracle RMAN异机迁移数据库从文件系统至ASM

准备环境

源库(文件系统) 目标库(ASM)
IP地址 172.30.21.191 172.30.21.98
主机名称 hfzcdb91 hfwmsdb98
数据库名 hfzcdb hfwmsdb
实例名 hfzcdb hfwmsdb

from:

source ip:172.30.21.191 19c hfzcdb filesystem 【172.30.21.191】

to:

target ip:172.30.21.98 19c asm

备份 【21.191】

备份参数文件

create pfile='/home/oracle/hfzcdb.pfile' from spfile;

备份数据库

vi hfzcdb_rman_full.sh

chmod u+x hfzcdb_rman_full.sh

./hfzcdb_rman_full.sh

sql 复制代码
rman target / msglog '/backup/hfzcdb_rman_full_backup.log' << EOF 
run { 
allocate channel d1 type disk; 
allocate channel d2 type disk; 
setlimit channel d1 kbytes 204800000 maxopenfiles 32 rate 204800000;
setlimit channel d2 kbytes 204800000 maxopenfiles 32 rate 204800000;
backup 
incremental level 0 
skip inaccessible 
tag itpux_level0 
filesperset 8
format '/backup/hfzcdb_full_%s_%p_%t' 
(database); 
release channel d1; 
release channel d2; 
 allocate channel d3 type disk; 
backup format '/backup/hfzcdb_ctl_%s_%p_%t' current controlfile; 
release channel d3; 
 allocate channel d4 type disk; 
copy current controlfile to '/backup/control_hfzcdb.ctl'; 
release channel d4; 
} 
exit 
EOF

传输备份到新主机

[oracle@hfzcdb91:/home/oracle]$nohup ./hfzcdb_rman_full.sh & --执行sh文件,后台输出

scp /backup/* 172.30.21.98:/backup/

scp orapwhfzcdb 172.30.21.98:$PWD

scp hfzcdb.pfile 172.30.21.98:/backup/

新主机准备目录

su - oracle

[oracle@hfwmsdb98:/backup]$mkdir -p $ORACLE_HOME/admin/hfzcdb/adump

[oracle@hfwmsdb98:/backup]$vi hfzcdb1.pfile

sql 复制代码
*.audit_file_dest='/oracle/app/oracle/admin/hfzcdb/adump'
*.audit_trail='NONE'
*.compatible='19.0.0'
*.control_files='+dgsystem/hfzcdb/control01.ctl','+dgsystem/hfzcdb/control02.ctl'
*.db_block_size=16384
*.db_files=16384
*.db_name='hfzcdb'
*.db_recovery_file_dest_size=107374182400
*.db_recovery_file_dest='+dgrecovery'
*.diagnostic_dest='/oracle/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=hfzcdbXDB)'
*.enable_ddl_logging=TRUE
*.nls_language='AMERICAN'
*.nls_territory='AMERICA'
*.open_cursors=300
*.pga_aggregate_target=500m
*.processes=3000
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=2340m
*.undo_tablespace='UNDOTBS1'

创建参数文件

[oracle@hfwmsdb98:/backup]$export ORACLE_SID=hfzcdb

[oracle@hfwmsdb98:/backup]$sqlplus / as sysdba

SQL>create spfile from pfile='/backup/hfzcdb1.pfile';

恢复控制文件

SQL> show parameter control

[oracle@hfwmsdb98:/backup]$rman target /

RMAN> restore controlfile from '/backup/hfzcdb_ctl_4_1_1093888570';

RMAN>alter database mount;

RMAN>report schema; 【查看备份控制文件里面的控制信息】

迁移恢复

sql 复制代码
run{ 
set newname for datafile 1 to '+dgsystem'; 
set newname for datafile 2 to '+dgsystem'; 
set newname for datafile 3 to '+dgsystem'; 
set newname for datafile 4 to '+dgsystem'; 
set newname for datafile 5 to '+dgsystem'; 
set newname for datafile 6 to '+dgsystem'; 
set newname for tempfile 1 to '+dgsystem'; 
restore database; 
switch datafile all; -- 【用新的文件名更新到控制文件里面,等价alter database rename file ......】
recover database; 
} 

--报错:RMAN-06054:media recovery reauqesting unknown archived log for thread 1 with sequence 18 and starting SCN of 830613.

SQL> select * from v$log;

[oracle@hfwmsdb98:/oradata/hfzcdb]$scp redo3.log 172.30.21.98:/backup/

[oracle@hfwmsdb98:/backup]$export ORACLE_SID=hfzcdb

[oracle@hfwmsdb98:/backup]$sqlplus / as sysdba

SQL>recover database until cancel;

SQL>recover database using backup controlfile until cancel;

/backup/redo03.log

查看重做日志文件,路径是否正确:

SQL> select * from v$logfile;

SQL> alter database rename file '/oradata/hfzcdb/redo01.log' to '+dgsystem';

SQL> alter database rename file '/oradata/hfzcdb/redo02.log' to '+dgsystem';

SQL> alter database rename file '/oradata/hfzcdb/redo03.log' to '+dgsystem';

SQL> alter database open resetlogs;

数据库正常启动

启动数据库

调整日志路径

SQL> select * from v$logfile; 【启动数据库,发现自动放在dgrecover目录,调整到dgsystem】

SQL> select * from v$log;

SQL> alter database drop logfile group 2;

SQL> alter database add logfile group 2 ('+dgsystem') size 100M;

SQL> alter database drop logfile group 3;

SQL> alter database add logfile group 3 ('+dgsystem') size 100M;

SQL> alter system switch logfile;

SQL> alter system checkpoint;

SQL> alter database drop logfile group 1;

SQL> alter database add logfile group 1 ('+dgsystem') size 100M;

SQL> select * from v$logfile;

sql 复制代码
 GROUP# STATUS     TYPE
MEMBER                       IS_REC   CON_ID
-------------------------------------------------- ------ ----------
 1        ONLINE  +DGSYSTEM/HFZCDB/ONLINELOG/group_1.278.1133335247 NO       0
 3        ONLINE  +DGSYSTEM/HFZCDB/ONLINELOG/group_3.277.1133335113 NO       0
 2        ONLINE +DGSYSTEM/HFZCDB/ONLINELOG/group_2.276.1133335063 NO       0

查看数据文件路径

SQL> select file_name from dba_data_files;

查看控制文件路径

SQL> select * from v$controlfile;

查看闪回目录路径

SQL> show parameter create;

SQL> show parameter recover;

调整pfile文件路径

SQL> show parameter spfile;

SQL> create pfile from spfile;

SQL> create spfile ='+dgsystem' from pfile='inithfzcdb.ora';

SQL> shutdown immediate

[oracle@hfwmsdb98:/oracle/app/oracle/product/19c/db_1/dbs]$rm inithfzcdb.ora

SQL> startup nomount

SQL> show parameter spfile; 【读不到asm参数】

ASMCMD> cd PARAMETERFILE/

ASMCMD> ls

spfile.275.1133299307

[oracle@hfwmsdb98:/oracle/app/oracle/product/19c/db_1/dbs]$vi inithfzcdb.ora

[oracle@hfwmsdb98:/oracle/app/oracle/product/19c/db_1/dbs]$cat inithfzcdb.ora

sql 复制代码
SPFILE='+DGSYSTEM/HFZCDB/PARAMETERFILE/spfile.275.1133299307'

SQL> shutdown immediate 【spfile 如果是单机的话 放在本地也是可以的】

SQL> startup

SQL> show parameter spfile;

查看归档日志路径

SQL> archive log list

调整临时文件路径

SQL> select file_name from dba_temp_files;

SQL>alter tablespace temp add tempfile '+dgsystem' size 100m;

SQL>alter tablespace temp drop tempfile '/oradata/hfzcdb/temp01.dbf';

SQL> select file_name from dba_temp_files;

SQL> shutdown immediate

SQL> startup

复制tnsnames文件到本库

tnsnames.ora 文件需要拷贝到迁移主机,并测试下外部连接。

[oracle@hfwmsdb98:/backup]$ps -ef |grep smon

sql 复制代码
oracle  6422 15394 0 07:42 pts/1  00:00:00 grep --color=auto smon
grid   8508   1 0 Apr04 ?    00:00:02 asm_smon_+ASM
oracle  26264   1 0 Apr04 ?    00:00:02 ora_smon_hfzcdb

查看集群参数

[grid@hfwmsdb98:/home/grid]$crsctl status res -t

hfzcdb.db 在里面crs没有

--相关参数

[oracle@hfwmsdb98:/home/oracle]$srvctl add database -db hfzcdb -oraclehome /oracle/app/oracle/product/19c/db_1

[oracle@hfwmsdb98:/home/oracle]$srvctl modify database -db hfzcdb -spfile '+DGSYSTEM/HFZCDB/PARAMETERFILE/spfile.275.1133299307'

检查:

[oracle@hfwmsdb98:/home/oracle]$srvctl config database -db hfzcdb

[oracle@hfwmsdb98:/home/oracle]$srvctl stop database -db hfzcd 【报错没有识别到数据,到数据库里面停止】

[oracle@hfwmsdb98:/home/oracle]$srvctl start database -db hfzcd

[root@hfwmsdb98 ~]# su - grid

Last login: Wed Apr 5 07:51:35 CST 2023 on pts/1

[grid@hfwmsdb98:/home/grid]$crsctl status res -t

sql 复制代码
			--------------------------------------------------------------------------------
Name           Target  State        Server                   State details
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DGDATA01.dg
               ONLINE  ONLINE       hfwmsdb98                STABLE
ora.DGDATA02.dg
               ONLINE  ONLINE       hfwmsdb98                STABLE
ora.DGGRID.dg
               ONLINE  ONLINE       hfwmsdb98                STABLE
ora.DGRECOVERY.dg
               ONLINE  ONLINE       hfwmsdb98                STABLE
ora.DGSYSTEM.dg
               ONLINE  ONLINE       hfwmsdb98                STABLE
ora.LISTENER.lsnr
               ONLINE  ONLINE       hfwmsdb98                STABLE
ora.asm
               ONLINE  ONLINE       hfwmsdb98                Started,STABLE
ora.ons
               OFFLINE OFFLINE      hfwmsdb98                STABLE
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.cssd
      1        ONLINE  ONLINE       hfwmsdb98                STABLE
ora.diskmon
      1        OFFLINE OFFLINE                               STABLE
ora.evmd
      1        ONLINE  ONLINE       hfwmsdb98                STABLE
ora.hfwmsdb.db
      1        OFFLINE OFFLINE                               STABLE
ora.hfzcdb.db
      1        ONLINE  ONLINE       hfwmsdb98                Open,HOME=/oracle/ap
                                                             p/oracle/product/19c
                                                             /db_1,STABLE
--------------------------------------------------------------------------------

外部连接测试

通过外部连接进行数据库测试。

相关推荐
鳄鱼的眼泪143 分钟前
mysql深度分页优化
数据库·mysql
yava_free44 分钟前
介绍一下mysql binlog查看指定数据库的方法
java·数据库·mysql
漫天转悠1 小时前
MySQL中in和exists的区别
数据库·mysql
Cosmoshhhyyy2 小时前
mysql低版本中update_time不自动更新问题
数据库·mysql
HilariousDog2 小时前
Redis1——基本命令及原理
数据库·redis·缓存
途普智能2 小时前
途普科技企业知识中台完成华为昇思MindSpore技术认证
数据库·人工智能·科技·华为·知识图谱
DC_BLOG3 小时前
Redis基础配置
数据库·redis·缓存
TPCloud3 小时前
oracle小技巧-解决特殊密码字符而导致的exp错误
oracle·exp·密码特殊字符
TPCloud3 小时前
部署自动清理任务解决ORA-00257: archiver error. Connect internal only, until freed
数据库·oracle·ora-00257