【12c 庫異機恢復】實驗

Yichen16發表於2022-01-25

前面我做了 11g 異機恢復實驗(就是同一臺機器不同目錄的方式來模擬),本次實驗在 12c 的環境下完成異機的恢復工作。

1 、系統環境

作業系統: CentOS Linux release 7.7.1908

資料庫:    Version 12.1.0.2.0  

目錄變換

資料目錄: /oradata               /oradata/orclnew                              

歸檔目錄: /archivelog           /archivelognew                         

閃回目錄: /falsh_recovery     /flash_recoverynew

 

2 、備份原庫( /home/oracle/backup

run{

allocate channel c1 type disk;

allocate channel c2 type disk;

allocate channel c3 type disk;

allocate channel c4 type disk;

backup as compressed backupset tag='full_backup' format '/home/oracle/backup/full_db_%U_%T' database;

sql 'alter system archive log current'; 

backup archivelog all format '/home/oracle/backup/archivelog_%U_%T' delete all input;

backup current controlfile tag='ctl_file' format='/home/oracle/backup/ctl_file_%U_%T';

backup spfile tag='spfile' format='/home/oracle/backup/spfile_%U_%T';

report obsolete; 

delete noprompt obsolete; 

crosscheck backup; 

delete noprompt expired backup;

release channel c1;

release channel c2;

release channel c3;

release channel c4;

}

[oracle@db1 backup]$ ll

total 649888

-rw-r----- 1 oracle oinstall  10382336 Jan 25 09:36 archivelog_0j0k5ho8_1_1_20220125

-rw-r----- 1 oracle oinstall      2560 Jan 25 09:36 archivelog_0k0k5ho8_1_1_20220125

-rw-r----- 1 oracle oinstall  17891328 Jan 25 09:36 ctl_file_0l0k5ho9_1_1_20220125

-rw-r----- 1 oracle oinstall   1073152 Jan 25 09:35 full_db_020k5hn2_1_1_20220125

-rw-r----- 1 oracle oinstall 159014912 Jan 25 09:35 full_db_030k5hn2_1_1_20220125

-rw-r----- 1 oracle oinstall 105201664 Jan 25 09:35 full_db_040k5hn2_1_1_20220125

-rw-r----- 1 oracle oinstall   1081344 Jan 25 09:35 full_db_050k5hn3_1_1_20220125

-rw-r----- 1 oracle oinstall   1105920 Jan 25 09:35 full_db_060k5hn3_1_1_20220125

-rw-r----- 1 oracle oinstall   1105920 Jan 25 09:35 full_db_070k5hn3_1_1_20220125

-rw-r----- 1 oracle oinstall   1105920 Jan 25 09:35 full_db_080k5hn4_1_1_20220125

-rw-r----- 1 oracle oinstall  64159744 Jan 25 09:35 full_db_090k5hn4_1_1_20220125

-rw-r----- 1 oracle oinstall  64159744 Jan 25 09:35 full_db_0a0k5hn4_1_1_20220125

-rw-r----- 1 oracle oinstall  64167936 Jan 25 09:35 full_db_0b0k5hnk_1_1_20220125

-rw-r----- 1 oracle oinstall  40525824 Jan 25 09:35 full_db_0c0k5hnk_1_1_20220125

-rw-r----- 1 oracle oinstall  40542208 Jan 25 09:35 full_db_0d0k5hnk_1_1_20220125

-rw-r----- 1 oracle oinstall  40525824 Jan 25 09:35 full_db_0e0k5hnn_1_1_20220125

-rw-r----- 1 oracle oinstall  53338112 Jan 25 09:36 full_db_0f0k5hnu_1_1_20220125

-rw-r----- 1 oracle oinstall     98304 Jan 25 09:36 spfile_0m0k5hoc_1_1_20220125

 

現狀:

SYS@orcl>select file_id,file_name,tablespace_name from cdb_data_files;

 

   FILE_ID FILE_NAME                                                    TABLESPACE_NAME

---------- ------------------------------------------------------------ ------------------------------

         1 /oradata/orcl/system01.dbf                                   SYSTEM

         3 /oradata/orcl/sysaux01.dbf                                   SYSAUX

         5 /oradata/orcl/undotbs1.dbf                                   UNDOTBS1

         6 /oradata/orcl/user01.dbf                                     USERS

         8 /oradata/orcl/pdb1/system01.dbf                              SYSTEM

         9 /oradata/orcl/pdb1/sysaux01.dbf                              SYSAUX

        10 /oradata/orcl/pdb1/user01.dbf                                USERS

        11 /oradata/orcl/pdb1/data.dbf                                  DATA

        12 /oradata/orcl/pdb2/system01.dbf                              SYSTEM

        13 /oradata/orcl/pdb2/sysaux01.dbf                              SYSAUX

        14 /oradata/orcl/pdb2/user01.dbf                                USERS

11 rows selected.

 

SYS@orcl>select file_id,file_name,tablespace_name from cdb_temp_files;

 

   FILE_ID FILE_NAME                                                    TABLESPACE_NAME

---------- ------------------------------------------------------------ ------------------------------

         1 /oradata/orcl/temp01.dbf                                     TEMP

         4 /oradata/orcl/pdb2/temp01.dbf                                TEMP

         3 /oradata/orcl/pdb1/temp01.dbf                                TEMP

 

3 、恢復到測試機

目標主機引數檔案

[oracle@db1 ~]$ cat 4.sql 

orcl.__data_transfer_cache_size=0

orcl.__db_cache_size=956301312

orcl.__java_pool_size=16777216

orcl.__large_pool_size=33554432

orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment

orcl.__pga_aggregate_target=738197504

orcl.__sga_target=1409286144

orcl.__shared_io_pool_size=67108864

orcl.__shared_pool_size=318767104

orcl.__streams_pool_size=0

*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'

*.audit_trail='db'

*.compatible='12.1.0'

*.control_files='/oradata/orclnew/control01.ctl','/oradata/orclnew/control02.ctl'

*.db_block_size=8192

*.db_domain=''

*.db_name='orcl'

*.db_recovery_file_dest='/flash_recoverynew'

*.db_recovery_file_dest_size=10G

*.db_securefile='PREFERRED'

*.diagnostic_dest='/u01/app/oracle'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'

*.enable_pluggable_database=true

*.log_archive_dest_1='location=/archivelognew'

*.memory_target=2G

*.open_cursors=300

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

 

建立檔案目錄

[root@db1 ~]# mkdir -p /oradata/orclnew /flash_recoverynew /archivelognew 

[root@db1 ~]# chmod 775 /oradata/orclnew /flash_recoverynew /archivelognew  -R

[root@db1 ~]# chown oracle:oinstall /oradata/orclnew /flash_recoverynew /archivelognew  -R

[root@db1 ~]#cd  /oradata/orclnew 

[root@db1 orclnew]# mkdir -p pdbseed  pdb1 pdb2

[root@db1 orclnew]# chmod 775 pdbseed pdb1 pdb2 -R

[root@db1 orclnew]# chown oracle:oinstall  pdbseed pdb1 pdb2 -R

 

SYS@orcl>create spfile from pfile='/home/oracle/4.sql';

File created.

SYS@orcl>startup nomount;

ORACLE instance started.

Total System Global Area 2147483648 bytes

Fixed Size                  2926472 bytes

Variable Size            1174407288 bytes

Database Buffers          956301312 bytes

Redo Buffers               13848576 bytes

 

恢復控制:

[oracle@db1 ~]$ rman target /

 

Recovery Manager: Release 12.1.0.2.0 - Production on Tue Jan 25 09:51:05 2022

 

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

 

connected to target database: ORCL (not mounted)

 

RMAN> restore controlfile from '/home/oracle/backup/ctl_file_0l0k5ho9_1_1_20220125';

 

Starting restore at 25-JAN-22

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=131 device type=DISK

 

channel ORA_DISK_1: restoring control file

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

output file name=/oradata/orclnew/control01.ctl

output file name=/oradata/orclnew/control02.ctl

Finished restore at 25-JAN-22

[oracle@db1 oradata]$ sqlplus / as sysdba

 

SQL*Plus: Release 12.1.0.2.0 Production on Tue Jan 25 09:52:40 2022

 

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

 

SYS@orcl>alter database mount;

 

Database altered.

 

恢復資料檔案:

run{

allocate channel c1 type disk;

allocate channel c2 type disk;

allocate channel c3 type disk;

allocate channel c4 type disk;

set newname for datafile  1 to '/oradata/orclnew/pdb2/system01.dbf';

set newname for datafile  3 to '/oradata/orclnew/pdb2/sysaux01.dbf';

set newname for datafile  5 to '/oradata/orclnew/pdb2/user01.dbf  ';

set newname for datafile  6 to '/oradata/orclnew/pdb1/system01.dbf';

set newname for datafile  8 to '/oradata/orclnew/pdb1/sysaux01.dbf';

set newname for datafile  9 to '/oradata/orclnew/pdb1/user01.dbf';

set newname for datafile 10 to '/oradata/orclnew/pdb1/data.dbf';

set newname for datafile 11 to '/oradata/orclnew/system01.dbf';

set newname for datafile 12 to '/oradata/orclnew/sysaux01.dbf';

set newname for datafile 13 to '/oradata/orclnew/undotbs1.dbf';

set newname for datafile 14 to '/oradata/orclnew/user01.dbf';

restore database;

switch datafile all;

recover database;

release channel c1;             

release channel c2;

release channel c3;

release channel c4;

}

SYS@orcl>alter database open resetlogs;

SYS@orcl>show pdbs;    

 

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

         2 PDB$SEED                       READ ONLY  NO

         3 PDB1                           MOUNTED

         4 PDB2                           MOUNTED

 

4 、檢查各項引數,確認是否正確

cdb pdb 臨時檔案 (新建 temp 檔案)

[oracle@db1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Tue Jan 25 10:42:58 2022

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SYS@orcl>create temporary tablespace temp101 tempfile '/oradata/orclnew/temp101.dbf' size 200m autoextend on maxsize 2g;

SYS@orcl>alter database default temporary tablespace temp101;

 

SYS@orcl>conn sys/oracle@pdb1 as sysdba

SYS@pdb1>create temporary tablespace temp201 tempfile '/oradata/orclnew/temp201.dbf' size 200m autoextend on maxsize 2g;

SYS@pdb1>alter database default temporary tablespace temp201;

 

SYS@orcl>show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

         2 PDB$SEED                       READ ONLY  NO

         3 PDB1                           MOUNTED

         4 PDB2                           MOUNTED

SYS@orcl>select file_id,file_name,tablespace_name from cdb_temp_files;

 

   FILE_ID FILE_NAME                                                    TABLESPACE_NAME

---------- ------------------------------------------------------------ ------------------------------

         5 /oradata/orclnew/temp101.dbf                                 TEMP101

 

redolog 檔案(新建 redolog

alter database add logfile '/oradata/orclnew/redo10.log' size 50m;

alter database add logfile '/oradata/orclnew/redo11.log' size 50m;

alter database add logfile '/oradata/orclnew/redo12.log' size 50m;

 

pdbseed (發現恢復後 pdbseed 檔案為空,怎麼辦?)

cdb 啟動到 mount 狀態

alter database rename file  '/oradata/orcl/pdbseed/sysaux01.dbf'  to  '/oradata/orclnew/pdbseed/sysaux01.dbf' ;

alter database rename file  '/oradata/orcl/pdbseed/system01.dbf'  to  '/oradata/orclnew/pdbseed/system01.dbf' ;

alter database rename file  '/oradata/orcl/pdbseed/temp01.dbf'  to    '/oradata/orclnew/pdbseed/temp01.dbf'  ;

alter database rename file  '/oradata/orcl/pdbseed/user01.dbf'  to    '/oradata/orclnew/pdbseed/user01.dbf'  ;

刪除原有 redolog (透過切換 redolog

alter system switch logfile;

alter system checkpoint;

alter database drop logfile to group 1;

alter database drop logfile to group 2;

alter database drop logfile to group 3;

 

SYS@orcl>select *from v$logfile;

    GROUP# STATUS  TYPE    MEMBER                                                       IS_     CON_ID

---------- ------- ------- ------------------------------------------------------------ --- ----------

         4         ONLINE  /oradata/orclnew/redo10.log                                  NO           0

         5         ONLINE  /oradata/orclnew/redo11.log                                  NO           0

         6         ONLINE  /oradata/orclnew/redo12.log                                  NO           0

 

測試建立 pdb 庫,檢查 pdbseed 是否可用:

SYS@orcl>show pdbs;

 

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

         2 PDB$SEED                       READ ONLY  NO

         3 PDB1                           READ WRITE NO

         4 PDB2                           READ WRITE NO

SYS@orcl>create pluggable database pdb3 admin user pdb3 identified by pdb3 file_name_convert=('/oradata/orclnew/pdbseed','/oradata/orclnew/pdb3/');

 

Pluggable database created.

 

SYS@orcl>show pdbs;

 

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

         2 PDB$SEED                       READ ONLY  NO

         3 PDB1                           READ WRITE NO

         4 PDB2                           READ WRITE NO

         5 PDB3                           MOUNTED

SYS@orcl>alter pluggable database pdb3 open;

 

Pluggable database altered.

 

SYS@orcl>show pdbs;

 

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED

---------- ------------------------------ ---------- ----------

         2 PDB$SEED                       READ ONLY  NO

         3 PDB1                           READ WRITE NO

         4 PDB2                           READ WRITE NO

         5 PDB3                           READ WRITE NO

SYS@orcl>select file_name from cdb_temp_files;

 

FILE_NAME

------------------------------------------------------------

/oradata/orclnew/temp301.dbf

/oradata/orclnew/temp101.dbf

/oradata/orclnew/temp201.dbf

/oradata/orclnew/pdb3/temp01.dbf

 

SYS@orcl>select file_name,tablespace_name from cdb_temp_files;

 

FILE_NAME                                                    TABLESPACE_NAME

------------------------------------------------------------ ------------------------------

/oradata/orclnew/temp101.dbf                                 TEMP101

/oradata/orclnew/pdb3/temp01.dbf                             TEMP

/oradata/orclnew/temp301.dbf                                 TEMP301

/oradata/orclnew/temp201.dbf                                 TEMP201

 

總結:比起 11g 異機恢復, 12c 的異機恢復多了 pdbseed 種子庫的遷移,其他過程沒有區別。(注意:檢視整個庫中的檔案使用 cdb_data_files cdb_temp_files 檢視)

 


Yicheng16
22.01.25

-- The End --       


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69963467/viewspace-2853869/,如需轉載,請註明出處,否則將追究法律責任。

相關文章