19.13備庫備份恢復新主庫(一)
阿新 • • 發佈:2022-12-13
問題描述:主備兩個庫不在同一個機房,此時想從這一套庫中在複製一套可讀可寫的新庫出來。網路頻寬要求比較高,需要從備庫中使用備份在起一個新庫,也要測試下使用duplicate從備庫能夠在複製一個新庫。經過測試,使用備份和duplicate都可以從備庫中恢復新庫。
下面使用備份恢復新主庫,跟rman恢復庫區別不大,主要在恢復的時候指定好控制檔案即可。
DG環境介紹一、備庫執行備份二、在新主機執行恢復操作 2.1、恢復spfile 2.2、恢復控制檔案 2.3、註冊備份資訊 2.4、還原資料檔案 2.5、恢復資料庫 2.6、啟用備庫為主庫,並啟動資料庫
1.環境介紹
利用實時備庫orclstd進行新主庫orcl_new的恢復,使用
IP |
oracle版本 |
oracle_sid |
db_unique_name |
角色 |
192.168.163.25 |
19.13 |
orcl |
orcl |
主庫 |
192.168.163.45 |
19.13 |
orclstd |
orclstd |
備庫 |
192.168.163.46 |
19.13 |
orcl_new |
orcl_new |
新主庫 |
主庫:
SQL> select open_mode,protection_mode,database_role,switchover_status fromv$database; OPEN_MODE PROTECTION_MODE DATABASE_ROLE SWITCHOVER_STATUS -------------------- -------------------- ---------------- -------------------- READ WRITE MAXIMUM PERFORMANCE PRIMARY TO STANDBY
備庫:
SQL> select open_mode,protection_mode,database_role,switchover_status fromv$database; OPEN_MODE PROTECTION_MODE DATABASE_ROLE SWITCHOVER_STATUS -------------------- -------------------- ---------------- -------------------- READ ONLY WITH APPLY MAXIMUM PERFORMANCE PHYSICAL STANDBY NOT ALLOWED SQL> select process, status, thread#,sequence#, block#, blocks from v$managed_standby; PROCESS STATUS THREAD# SEQUENCE# BLOCK# BLOCKS --------- ------------ ---------- ---------- ---------- ---------- ARCH CONNECTED 0 0 0 0 DGRD ALLOCATED 0 0 0 0 DGRD ALLOCATED 0 0 0 0 ARCH CONNECTED 0 0 0 0 ARCH CONNECTED 0 0 0 0 ARCH CONNECTED 0 0 0 0 RFS IDLE 1 0 0 0 RFS IDLE 1 41 874 1 RFS IDLE 0 0 0 0 MRP0 APPLYING_LOG 1 41 874 245760
10 rows selected.
2.備庫全備
cat > /data/rman_backup_oradgphy_full.sh <<"EOF0" #!/bin/ksh rman target / log /data/backup/backup_oradgphy_full_$MYDATE.log append <<EOF run { sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"'; sql 'alter session set NLS_LANGUAGE="AMERICAN"'; allocate channel c1 type disk; allocate channel c2 type disk; backup as compressed backupset database format '/data/backup/FULL_%d_%U.full'; backup as compressed backupset archivelog from time 'sysdate-1' format '/data/backup/ARC_%d_%U.arc'; backup current controlfile format '/data/backup/standby_%U.ctl'; backup spfile format '/data/backup/spfile_%d_%U.ora'; release channel c1; release channel c2; } EOF EOF0
3.恢復資料庫
[oracle@19c-test:~]>$rman target / Recovery Manager: Release 19.0.0.0.0 - Production on Sun Nov 13 14:50:02 2022 Version 19.13.0.0.0 Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved. connected to target database (not started) --啟動到nomount RMAN> startup nomount; startup failed: ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file '/u01/app/oracle/product/19.0.0.0/dbhome_1/dbs/initorcl_new.ora' starting Oracle instance without parameter file for retrieval of spfile Oracle instance started Total System Global Area 1073737792 bytes Fixed Size 8904768 bytes Variable Size 276824064 bytes Database Buffers 780140544 bytes Redo Buffers 7868416 bytes
3.1恢復spfile
RMAN> restore spfile to pfile '/u01/app/oracle/product/19.0.0.0/dbhome_1/dbs/initorcl_new.ora' from '/data/backup/spfile_ORCL_1u1cnr92_62_1_1.ora'; Starting restore at 2022-11-13 14:50:31 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 spfile from AUTOBACKUP /data/backup/spfile_ORCL_1u1cnr92_62_1_1.ora channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete Finished restore at 2022-11-13 14:50:32
3.2編輯pfile
原pfile
[oracle@19c-test:dbs]>$cat initorcl_new.ora orclstd.__data_transfer_cache_size=0 orclstd.__db_cache_size=343932928 orclstd.__inmemory_ext_roarea=0 orclstd.__inmemory_ext_rwarea=0 orclstd.__java_pool_size=79691776 orclstd.__large_pool_size=4194304 orclstd.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment orclstd.__pga_aggregate_target=192937984 orclstd.__sga_target=771751936 orclstd.__shared_io_pool_size=37748736 orclstd.__shared_pool_size=289406976 orclstd.__streams_pool_size=0 orclstd.__unified_pga_pool_size=0 *._optimizer_cartesian_enabled=FALSE *.audit_file_dest='/u01/app/oracle/admin/orclstd/adump' *.audit_trail='NONE' *.compatible='19.0.0' *.control_files='/oradata/orclstd/control01.ctl','/oradata/orclstd/control02.ctl' *.db_block_size=8192 *.db_create_file_dest='/oradata' *.db_file_name_convert='/oradata/ORCL/','/oradata/orclstd/' *.db_name='orcl' *.db_recovery_file_dest_size=16106127360 *.db_recovery_file_dest='/home/oracle/flashdata' *.db_unique_name='ORCLSTD' *.deferred_segment_creation=FALSE *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.event='10949 trace name context forever:28401 trace name context forever,level 1:10849 trace name context forever, level 1:19823 trace name context forever, level 90' *.fal_client='orclstd' *.fal_server='orcl' *.local_listener='LISTENER_ORCL' *.log_archive_config='DG_CONFIG=(orcl,orclstd)' *.log_archive_dest_1='location=/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl' *.log_archive_dest_2='SERVICE=orclstd LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orclstd' *.log_archive_format='%t_%s_%r.dbf' *.log_file_name_convert='/oradata/ORCL/','/oradata/orclstd/' *.nls_language='AMERICAN' *.nls_territory='AMERICA' *.open_cursors=300 *.pga_aggregate_target=184m *.processes=300 *.remote_login_passwordfile='EXCLUSIVE' *.result_cache_max_size=0 *.sga_target=735m *.standby_file_management='AUTO' *.undo_tablespace='UNDOTBS1'
去除DG相關引數
orcl_new.__data_transfer_cache_size=0 orcl_new.__db_cache_size=343932928 orcl_new.__inmemory_ext_roarea=0 orcl_new.__inmemory_ext_rwarea=0 orcl_new.__java_pool_size=79691776 orcl_new.__large_pool_size=4194304 orcl_new.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment orcl_new.__pga_aggregate_target=192937984 orcl_new.__sga_target=771751936 orcl_new.__shared_io_pool_size=37748736 orcl_new.__shared_pool_size=289406976 orcl_new.__streams_pool_size=0 orcl_new.__unified_pga_pool_size=0 *._optimizer_cartesian_enabled=FALSE *.audit_file_dest='/u01/app/oracle/admin/orcl_new/adump' *.audit_trail='NONE' *.compatible='19.0.0' *.control_files='/oradata/orcl_new/control01.ctl','/oradata/orcl_new/control02.ctl' *.db_block_size=8192 *.db_create_file_dest='/oradata' *.db_name='orcl' *.db_recovery_file_dest_size=16106127360 *.db_recovery_file_dest='/home/oracle/flashdata' *.db_unique_name='orcl_new' *.deferred_segment_creation=FALSE *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' *.event='10949 trace name context forever:28401 trace name context forever,level 1:10849 trace name context forever, level 1:19823 trace name context forever, level 90' *.log_archive_dest_1='location=/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl_new' *.log_archive_format='%t_%s_%r.dbf' *.nls_language='AMERICAN' *.nls_territory='AMERICA' *.open_cursors=300 *.pga_aggregate_target=184m *.processes=300 *.remote_login_passwordfile='EXCLUSIVE' *.result_cache_max_size=0 *.sga_target=735m *.standby_file_management='AUTO' *.undo_tablespace='UNDOTBS1'
3.3建立相關目錄
mkdir -p /home/oracle/flashdata mkdir -p /u01/app/oracle/admin/orcl_new/adump mkdir -p /oradata/orcl_new mkdir -p /oradata/ORCL chown -R oracle.oinstall /oradata/
3.4restore控制檔案
SQL> create spfile from pfile; File created. SQL> startup force nomount; ORACLE instance started. Total System Global Area 771748528 bytes Fixed Size 8901296 bytes Variable Size 373293056 bytes Database Buffers 381681664 bytes Redo Buffers 7872512 bytes --還原控制檔案,加上primary關鍵字 RMAN> restore primary controlfile from '/data/backup/standby_1t1cnr90_61_1_1.ctl'; Starting restore at 2022-11-13 15:19:45 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=18 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/orcl_new/control01.ctl output file name=/oradata/orcl_new/control02.ctl Finished restore at 2022-11-13 15:19:47
3.5註冊備份資訊
SQL> alter database mount; Database altered. --清除之前的備份資訊 EXECUTE DBMS_BACKUP_RESTORE.RESETCFILESECTION(11); /** CLEAR V$ARCHIVED_LOG */ EXECUTE DBMS_BACKUP_RESTORE.RESETCFILESECTION(12); /** CLEAR V$BACKUP_SET */ EXECUTE DBMS_BACKUP_RESTORE.RESETCFILESECTION(13); /** CLEAR V$BACKUP_PIECE */ SQL> EXECUTE DBMS_BACKUP_RESTORE.RESETCFILESECTION(11); PL/SQL procedure successfully completed. SQL> EXECUTE DBMS_BACKUP_RESTORE.RESETCFILESECTION(12); PL/SQL procedure successfully completed. SQL> EXECUTE DBMS_BACKUP_RESTORE.RESETCFILESECTION(13); PL/SQL procedure successfully completed. --註冊備份集 RMAN> catalog start with '/data/backup'; released channel: ORA_DISK_1 Starting implicit crosscheck backup at 2022-11-13 15:22:52 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=18 device type=DISK Finished implicit crosscheck backup at 2022-11-13 15:22:52 Starting implicit crosscheck copy at 2022-11-13 15:22:52 using channel ORA_DISK_1 Finished implicit crosscheck copy at 2022-11-13 15:22:52 searching for all files in the recovery area cataloging files... no files cataloged searching for all files that match the pattern /data/backup List of Files Unknown to the Database ===================================== File Name: /data/backup/backup_oradgphy_full_.log File Name: /data/backup/FULL_ORCL_1o1cnr7q_56_1_1.full File Name: /data/backup/FULL_ORCL_1p1cnr7q_57_1_1.full File Name: /data/backup/ARC_ORCL_1q1cnr8t_58_1_1.arc File Name: /data/backup/ARC_ORCL_1r1cnr8t_59_1_1.arc File Name: /data/backup/ARC_ORCL_1s1cnr8u_60_1_1.arc File Name: /data/backup/standby_1t1cnr90_61_1_1.ctl File Name: /data/backup/spfile_ORCL_1u1cnr92_62_1_1.ora Do you really want to catalog the above files (enter YES or NO)? yes cataloging files... cataloging done List of Cataloged Files ======================= File Name: /data/backup/FULL_ORCL_1o1cnr7q_56_1_1.full File Name: /data/backup/FULL_ORCL_1p1cnr7q_57_1_1.full File Name: /data/backup/ARC_ORCL_1q1cnr8t_58_1_1.arc File Name: /data/backup/ARC_ORCL_1r1cnr8t_59_1_1.arc File Name: /data/backup/ARC_ORCL_1s1cnr8u_60_1_1.arc File Name: /data/backup/standby_1t1cnr90_61_1_1.ctl File Name: /data/backup/spfile_ORCL_1u1cnr92_62_1_1.ora List of Files Which Were Not Cataloged ======================================= File Name: /data/backup/backup_oradgphy_full_.log RMAN-07517: Reason: The file header is corrupted
3.6恢復資料檔案
cat > /home/oracle/rman_restore_orcl_new.sh <<"EOF0" MYDATE=`date +'%Y%m%d%H%M%S'` export NLS_DATE_FORMAT="yyyy-mm-dd hh24:mi:ss" rman target / log /home/oracle/rman_restore_LHRDB_$MYDATE.log append <<EOF run { sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"'; sql 'alter session set NLS_LANGUAGE="AMERICAN"'; allocate channel c1 type disk; allocate channel c2 type disk; SET NEWNAME FOR DATABASE TO '/oradata/orcl_new/%b'; restore database; switch datafile all; release channel c1; release channel c2; } EOF EOF0
4.啟動新主庫
4.1啟動open
[oracle@19c-test:~]>$sqlplus / as sysdba SQL*Plus: Release 19.0.0.0.0 - Production on Sun Nov 13 15:54:57 2022 Version 19.13.0.0.0 Copyright (c) 1982, 2021, Oracle. All rights reserved. Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.13.0.0.0 SQL> SQL> alter database open resetlogs; Database altered. SQL> select open_mode , database_role, flashback_on from v$database; OPEN_MODE DATABASE_ROLE FLASHBACK_ON -------------------- ---------------- ------------------ READ WRITE PRIMARY NO SQL> select status,instance_name from v$instance; STATUS INSTANCE_NAME ------------ ---------------- OPEN orcl_new