Oracle RMAN恢復測試

chenoracle發表於2020-08-01

場景一: 使用0級備份 恢復資料庫

需要0級備份+0級備份期間產生的歸檔日誌

場景二: 使用0級+1級備份 恢復資料庫

需要0級備份+1級備份+1級備份期間產生的歸檔日誌

場景三: 使用0級+歸檔 備份恢復資料庫

場景四: 完全恢復

場景五: 異機恢復常用命令

######備份######

1 啟動歸檔

[oracle@chendb ~]$ sqlplus / as sysdba
SQL> alter system set log_archive_dest_1='location=/arch';
SQL> alter system set log_archive_format = "chendb_%t_%s_%r.arc" scope=spfile;
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;
SQL> archive log list;

2 建立測試資料

SQL> conn cjc/***
SQL>
create table t1(id number,ttime varchar2(100));
CREATE OR REPLACE PROCEDURE test_pro is
begin
  for i in 1 .. 10 loop
    insert into t1 values (i, to_char(sysdate, 'yyyy/mm/dd hh24:mi:ss'));
    commit;
  end loop;
end;
/

3 建立0級備份指令碼

[oracle@cjcos01 script]$ vim /rmanbak/script/0_rmanbak.sh
###0_rmanbak.sh begin### 
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
export ORACLE_SID=chendb
rman target / log=/rmanbak/db/0_rmanbak.log <<EOF 
run{
allocate channel ch1 type disk maxpiecesize 1000M;
allocate channel ch2 type disk maxpiecesize 1000M;
backup incremental level = 0 
filesperset = 32
format '/rmanbak/db/lev0_%d_%T_%U.bak'
skip inaccessible  database
include current controlfile 
tag '0_rmanbak_cjcdb' ;
release channel ch1;
release channel ch2;
}
EOF
exit
###0_rmanbak.sh end###

執行0級備份

[oracle@cjcos01 script]$ chmod a+x 0_rmanbak.sh 
[oracle@cjcos01 script]$ ./0_rmanbak.sh

執行備份期間,生成測試資料,切換歸檔日誌

SQL> conn cjc/***
SQL> exec test_pro();
SQL> create table t2 as select * from t1;
SQL> alter system switch logfile;

4 建立1級備份

[oracle@cjcos01 script]$ cat 1_rmanbak.sh 
###1_rmanbak.sh begin### 
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
export ORACLE_SID=chendb 
rman target / log=/rmanbak/db/1_rmanbak.log <<EOF 
run{
allocate channel ch1 type disk maxpiecesize 1000M;
allocate channel ch2 type disk maxpiecesize 1000M;
backup incremental level = 1 
filesperset = 32
format '/rmanbak/db/lev1_%d_%T_%U.bak'
skip inaccessible  database
include current controlfile 
tag '1_rmanbak_cjcdb' ;
release channel ch1;
release channel ch2;
}
EOF
exit 
###1_rmanbak.sh end###

執行1級備份

[oracle@cjcos01 script]$ chmod a+x 1_rmanbak.sh 
[oracle@cjcos01 script]$ ./1_rmanbak.sh

執行備份期間,生成測試資料,切換歸檔日誌

SQL> conn cjc/***
SQL> exec test_pro();
SQL> create table t3 as select * from t2;
SQL> alter system switch logfile;

5 執行歸檔備份

[oracle@cjcos01 script]$ cat arch_rmanbak.sh 
###arch_rmanbak.sh begin### 
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
export ORACLE_SID=chendb
rman target / log=/rmanbak/db/arch_rmanbak.log <<EOF 
run{
allocate channel ch1 type disk maxpiecesize 1000M;
allocate channel ch2 type disk maxpiecesize 1000M;
sql "alter system archive log current";
backup
filesperset = 32
format '/rmanbak/db/arch_%d_%T_%U.bak'
skip inaccessible
archivelog all delete input
tag 'arch_cjcdb';
backup format='/rmandata/db/ctl_%d_%T_%U.ctl' current controlfile ; 
release channel ch1;
release channel ch2;
}
EOF
exit 
###arch_rmanbak.sh end###

執行歸檔備份

[oracle@cjcos01 script]$ ./arch_rmanbak.sh
SQL> create table t5 as select *from t1;

檢視備份資訊

SQL> 
alter session set nls_date_format='yyyymmdd hh24:mi:ss';
col tag for a20
set lin 200 pages 200
col handle for a50
col SIZE_BYTES_DISPLAY for a10
 select BS.RECID,BS.START_TIME,BS.PIECES,BS.INCREMENTAL_LEVEL,BS.BACKUP_TYPE,BP.PIECE#,BP.HANDLE,BP.TAG,BP.STATUS,ROUND(BP.bytes/1024/1024/1024,2) gb
  from v$backup_set bs,v$backup_piece bp 
  where 
  bs.recid=bp.recid;
  
     RECID START_TIME PIECES INCREMENTAL_LEVEL BPIECE# HANDLE  TAG       S GB
---------- ----------------- ---------- ----------------- - ---------- -------------------------------------------------- -------------------- - ----------
 1 20200801 14:31:54      1 0 D     1 /rmanbak/db/lev0_CHENDB_20200801_02v6p8eq_1_1.bak  0_RMANBAK_CJCDB      A.41
 2 20200801 14:31:54      1 0 D     1 /rmanbak/db/lev0_CHENDB_20200801_01v6p8eq_1_1.bak  0_RMANBAK_CJCDB      A.73
 3 20200801 14:33:30      1 0 D     1 /rmanbak/db/lev0_CHENDB_20200801_04v6p8hq_1_1.bak  0_RMANBAK_CJCDB      A  0
 4 20200801 14:33:23      1 0 D     1 /rmanbak/db/lev0_CHENDB_20200801_03v6p8hj_1_1.bak  0_RMANBAK_CJCDB      A.01
 5 20200801 15:07:32      1 1 I     1 /rmanbak/db/lev1_CHENDB_20200801_06v6pahk_1_1.bak  1_RMANBAK_CJCDB      A  0
 6 20200801 15:07:32      1 1 I     1 /rmanbak/db/lev1_CHENDB_20200801_05v6pahk_1_1.bak  1_RMANBAK_CJCDB      A  0
 7 20200801 15:08:49      1 1 I     1 /rmanbak/db/lev1_CHENDB_20200801_08v6pak1_1_1.bak  1_RMANBAK_CJCDB      A  0
 8 20200801 15:08:48      1 1 I     1 /rmanbak/db/lev1_CHENDB_20200801_07v6pak0_1_1.bak  1_RMANBAK_CJCDB      A.01
 9 20200801 15:13:26      1   L     1 /rmanbak/db/arch_CHENDB_20200801_09v6pasm_1_1.bak  ARCH_CJCDB       A.51
10 20200801 15:13:26      1   L     1 /rmanbak/db/arch_CHENDB_20200801_0av6pasm_1_1.bak  ARCH_CJCDB       A.45
11 20200801 15:14:12      1   L     1 /rmanbak/db/arch_CHENDB_20200801_0bv6pau4_1_1.bak  ARCH_CJCDB       A  0
12 20200801 15:14:14      1   D     1 /rmandata/db/ctl_CHENDB_20200801_0cv6pau6_1_1.ctl  TAG20200801T151414   A.01
12 rows selected

BACKUP_TYPE:

Type of files that are in this backup. 

If the backup contains archived redo logs, the value is L. 

If this is a datafile full backup, the value is D. 

If this is an incremental backup, the value is I.

檢視備份資訊

[oracle@cjcos01 script]$ export NLS_DATE_FORMAT='YYYYMMDD HH24:MI:SS'
[oracle@cjcos01 script]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Sat Aug 1 15:24:20 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: CHENDB (DBID=1831901477)

RMAN> list backup summary;
using target database control file instead of recovery catalog
List of Backups
===============
Key     TY LV S Device Type Completion Time   #Pieces #Copies Compressed Tag
------- -- -- - ----------- ----------------- ------- ------- ---------- ---
1       B  0  A DISK        20200801 14:33:06 1       1       NO         0_RMANBAK_CJCDB
2       B  0  A DISK        20200801 14:33:26 1       1       NO         0_RMANBAK_CJCDB
3       B  0  A DISK        20200801 14:33:30 1       1       NO         0_RMANBAK_CJCDB
4       B  0  A DISK        20200801 14:33:31 1       1       NO         0_RMANBAK_CJCDB
5       B  1  A DISK        20200801 15:08:41 1       1       NO         1_RMANBAK_CJCDB
6       B  1  A DISK        20200801 15:08:48 1       1       NO         1_RMANBAK_CJCDB
7       B  1  A DISK        20200801 15:08:49 1       1       NO         1_RMANBAK_CJCDB
8       B  1  A DISK        20200801 15:08:50 1       1       NO         1_RMANBAK_CJCDB
9       B  A  A DISK        20200801 15:14:07 1       1       NO         ARCH_CJCDB
10      B  A  A DISK        20200801 15:14:08 1       1       NO         ARCH_CJCDB
11      B  A  A DISK        20200801 15:14:13 1       1       NO         ARCH_CJCDB
12      B  F  A DISK        20200801 15:14:15 1       1       NO         TAG20200801T151414

######恢復######

場景一:使用0級備份恢復資料庫

手動將增量和歸檔備份設定失效,測試只有0級備份進行恢復資料庫

---生成unavailable指令碼

SQL> set pagesize 2000
SQL> set heading off
SQL> spool /home/oracle/unavailable.log
SQL> 
select 'change backupset '||BS.RECID||' unavailable;'
from v$backup_set bs,v$backup_piece bp 
where 
bs.recid=bp.recid 
and BS.BACKUP_TYPE!='D' 
SQL>spool off
'CHANGEBACKUPSET'||BS.RECID||'UNAVAILABLE;'
----------------------------------------------------------------------
change backupset 5 unavailable;
change backupset 6 unavailable;
change backupset 7 unavailable;
change backupset 8 unavailable;
change backupset 9 unavailable;
change backupset 10 unavailable;
change backupset 11 unavailable;
RMAN> 
change backupset 5 unavailable;
change backupset 6 unavailable;
change backupset 7 unavailable;
change backupset 8 unavailable;
change backupset 9 unavailable;
change backupset 10 unavailable;
change backupset 11 unavailable;

檢視狀態,5-12備份集已經失效

RMAN> list backup summary;
List of Backups
===============
Key     TY LV S Device Type Completion Time   #Pieces #Copies Compressed Tag
------- -- -- - ----------- ----------------- ------- ------- ---------- ---
1       B  0  A DISK        20200801 14:33:06 1       1       NO         0_RMANBAK_CJCDB
2       B  0  A DISK        20200801 14:33:26 1       1       NO         0_RMANBAK_CJCDB
3       B  0  A DISK        20200801 14:33:30 1       1       NO         0_RMANBAK_CJCDB
4       B  0  A DISK        20200801 14:33:31 1       1       NO         0_RMANBAK_CJCDB
5       B  1  U DISK        20200801 15:08:41 1       1       NO         1_RMANBAK_CJCDB
6       B  1  U DISK        20200801 15:08:48 1       1       NO         1_RMANBAK_CJCDB
7       B  1  U DISK        20200801 15:08:49 1       1       NO         1_RMANBAK_CJCDB
8       B  1  U DISK        20200801 15:08:50 1       1       NO         1_RMANBAK_CJCDB
9       B  A  U DISK        20200801 15:14:07 1       1       NO         ARCH_CJCDB
10      B  A  U DISK        20200801 15:14:08 1       1       NO         ARCH_CJCDB
11      B  A  U DISK        20200801 15:14:13 1       1       NO         ARCH_CJCDB
12      B  F  A DISK        20200801 15:14:15 1       1       NO         TAG20200801T151414

0級恢復

SQL> shutdown immediate

冷備

[oracle@cjcos01 oradata]$ pwd
/u01/app/oracle11/oradata
[oracle@cjcos01 oradata]$ cp chendb chendb_0801bak -r
SQL> startup mount

開始0級恢復

預設執行完全恢復,歸檔備份已經設定失效,所有會提示找不到歸檔

RMAN>
run{
allocate channel d1 type disk;
restore database;
recover database;
release channel d1;
}

恢復日誌如下:

using target database control file instead of recovery catalog
allocated channel: d1
channel d1: SID=20 device type=DISK
Starting restore at 20200801 15:30:43
channel d1: starting datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
channel d1: restoring datafile 00002 to /u01/app/oracle11/oradata/chendb/sysaux01.dbf
channel d1: restoring datafile 00004 to /u01/app/oracle11/oradata/chendb/users01.dbf
channel d1: restoring datafile 00006 to /u01/app/oracle11/oradata/chendb/cjctbs01.dbf
channel d1: reading from backup piece /rmanbak/db/lev0_CHENDB_20200801_02v6p8eq_1_1.bak
channel d1: piece handle=/rmanbak/db/lev0_CHENDB_20200801_02v6p8eq_1_1.bak tag=0_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:01:05
channel d1: starting datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
channel d1: restoring datafile 00001 to /u01/app/oracle11/oradata/chendb/system01.dbf
channel d1: restoring datafile 00003 to /u01/app/oracle11/oradata/chendb/undotbs01.dbf
channel d1: restoring datafile 00005 to /u01/app/oracle11/oradata/chendb/example01.dbf
channel d1: reading from backup piece /rmanbak/db/lev0_CHENDB_20200801_01v6p8eq_1_1.bak
channel d1: piece handle=/rmanbak/db/lev0_CHENDB_20200801_01v6p8eq_1_1.bak tag=0_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:01:15
Finished restore at 20200801 15:33:04
Starting recover at 20200801 15:33:05
starting media recovery
released channel: d1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 08/01/2020 15:33:06
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of archived log for thread 1 with sequence 39 and starting SCN of 2280954 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 38 and starting SCN of 2280793 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 37 and starting SCN of 2280705 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 36 and starting SCN of 2278640 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 35 and starting SCN of 2278619 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 34 and starting SCN of 2277662 found to restore

檢視控制檔案記錄的資料檔案scn

SQL> select file#,checkpoint_change# from v$datafile;
     FILE# CHECKPOINT_CHANGE#
---------- ------------------
 1      2281863
 2      2281863
 3      2281863
 4      2281863
 5      2281863
 6      2281863
6 rows selected.

檢視資料檔案頭記錄的SCN

SQL> select file#,checkpoint_change# from v$datafile_header;
     FILE# CHECKPOINT_CHANGE#
---------- ------------------
 1      2278590
 2      2278591
 3      2278590
 4      2278591
 5      2278590
 6      2278591
6 rows selected.

0級別恢復,執行不完全恢復,恢復到資料檔案頭最大的scn

RMAN>
run{
allocate channel d1 type disk;
restore database until scn 2278591;
recover database until scn 2278591;
release channel d1;
}
released channel: d1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 08/01/2020 15:41:12
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of archived log for thread 1 with sequence 34 and starting SCN of 2277662 found to restore

提示恢復需要34號歸檔檔案,檢視34號歸檔所在備份集

RMAN> list backupset of archivelog sequence 34;
List of Backup Sets
===================
BS Key  Size       Device Type Elapsed Time Completion Time  
------- ---------- ----------- ------------ -----------------
10      463.58M    DISK        00:00:42     20200801 15:14:08
        BP Key: 10   Status: AVAILABLE  Compressed: NO  Tag: ARCH_CJCDB
        Piece Name: /rmanbak/db/arch_CHENDB_20200801_0av6pasm_1_1.bak
  List of Archived Logs in backup set 10
  Thrd Seq     Low SCN    Low Time          Next SCN   Next Time
  ---- ------- ---------- ----------------- ---------- ---------
  1    34      2277662    20200801 14:16:55 2278619    20200801 14:32:15

手動將10號備份置為有效

RMAN> change backupset 10 available;
using channel ORA_DISK_1
changed backup piece available
backup piece handle=/rmanbak/db/arch_CHENDB_20200801_0av6pasm_1_1.bak RECID=10 STAMP=1047309207
Changed 1 objects to AVAILABLE status

解壓出34號歸檔檔案

RMAN> restore archivelog sequence 34;
Starting restore at 20200801 15:46:11
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=34
channel ORA_DISK_1: reading from backup piece /rmanbak/db/arch_CHENDB_20200801_0av6pasm_1_1.bak
channel ORA_DISK_1: piece handle=/rmanbak/db/arch_CHENDB_20200801_0av6pasm_1_1.bak tag=ARCH_CJCDB
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 20200801 15:46:18
[oracle@cjcos01 db]$ ls /arch/
chendb_1_34_1042210216.arc

再次執行恢復

此次使用了0級備份+34號歸檔 完成了恢復 

RMAN>
run{
allocate channel d1 type disk;
restore database until scn 2278591;
recover database until scn 2278591;
release channel d1;
}
released channel: ORA_DISK_1
allocated channel: d1
channel d1: SID=20 device type=DISK
Starting restore at 20200801 15:47:12
skipping datafile 1; already restored to file /u01/app/oracle11/oradata/chendb/system01.dbf
skipping datafile 3; already restored to file /u01/app/oracle11/oradata/chendb/undotbs01.dbf
skipping datafile 5; already restored to file /u01/app/oracle11/oradata/chendb/example01.dbf
skipping datafile 2; already restored to file /u01/app/oracle11/oradata/chendb/sysaux01.dbf
skipping datafile 4; already restored to file /u01/app/oracle11/oradata/chendb/users01.dbf
skipping datafile 6; already restored to file /u01/app/oracle11/oradata/chendb/cjctbs01.dbf
restore not done; all files read only, offline, or already restored
Finished restore at 20200801 15:47:12
Starting recover at 20200801 15:47:12
starting media recovery
archived log for thread 1 with sequence 34 is already on disk as file /arch/chendb_1_34_1042210216.arc
archived log file name=/arch/chendb_1_34_1042210216.arc thread=1 sequence=34
media recovery complete, elapsed time: 00:00:00
Finished recover at 20200801 15:47:12
released channel: d1

恢復成功

檢視當前資料檔案scn

SQL> select file#,checkpoint_change# from v$datafile_header;
     FILE# CHECKPOINT_CHANGE#
---------- ------------------
 1      2278591
 2      2278591
 3      2278591
 4      2278591
 5      2278591
 6      2278591
6 rows selected.

場景二:使用0級+1級備份 恢復資料庫

將增量備份設定為有效

RMAN> 
change backupset 5 available;
change backupset 6 available;
change backupset 7 available;
change backupset 8 available;

檢視備份狀態

RMAN> list backup summary;
List of Backups
===============
Key     TY LV S Device Type Completion Time   #Pieces #Copies Compressed Tag
------- -- -- - ----------- ----------------- ------- ------- ---------- ---
1       B  0  A DISK        20200801 14:33:06 1       1       NO         0_RMANBAK_CJCDB
2       B  0  A DISK        20200801 14:33:26 1       1       NO         0_RMANBAK_CJCDB
3       B  0  A DISK        20200801 14:33:30 1       1       NO         0_RMANBAK_CJCDB
4       B  0  A DISK        20200801 14:33:31 1       1       NO         0_RMANBAK_CJCDB
5       B  1  A DISK        20200801 15:08:41 1       1       NO         1_RMANBAK_CJCDB
6       B  1  A DISK        20200801 15:08:48 1       1       NO         1_RMANBAK_CJCDB
7       B  1  A DISK        20200801 15:08:49 1       1       NO         1_RMANBAK_CJCDB
8       B  1  A DISK        20200801 15:08:50 1       1       NO         1_RMANBAK_CJCDB
9       B  A  U DISK        20200801 15:14:07 1       1       NO         ARCH_CJCDB
10      B  A  U DISK        20200801 15:14:08 1       1       NO         ARCH_CJCDB
11      B  A  U DISK        20200801 15:14:13 1       1       NO         ARCH_CJCDB
12      B  F  A DISK        20200801 15:14:15 1       1       NO         TAG20200801T151414

刪除解壓的歸檔

[oracle@cjcos01 db]$ rm -rf /arch/chendb_1_34_1042210216.arc

恢復冷備份

SQL> shutdown immediate
[oracle@cjcos01 oradata]$ rm -rf chendb/*
[oracle@cjcos01 oradata]$ cp chendb_0801bak/* chendb/ -r
SQL> startup mount

開始0+1級恢復,預設執行完全恢復

歸檔備份已經設定失效,所有會提示找不到歸檔

RMAN>
run{
allocate channel d1 type disk;
restore database;
recover database;
release channel d1;
}
allocated channel: d1
channel d1: SID=20 device type=DISK
Starting restore at 20200801 16:15:57
channel d1: starting datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
channel d1: restoring datafile 00002 to /u01/app/oracle11/oradata/chendb/sysaux01.dbf
channel d1: restoring datafile 00004 to /u01/app/oracle11/oradata/chendb/users01.dbf
channel d1: restoring datafile 00006 to /u01/app/oracle11/oradata/chendb/cjctbs01.dbf
channel d1: reading from backup piece /rmanbak/db/lev0_CHENDB_20200801_02v6p8eq_1_1.bak
channel d1: piece handle=/rmanbak/db/lev0_CHENDB_20200801_02v6p8eq_1_1.bak tag=0_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:25
channel d1: starting datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
channel d1: restoring datafile 00001 to /u01/app/oracle11/oradata/chendb/system01.dbf
channel d1: restoring datafile 00003 to /u01/app/oracle11/oradata/chendb/undotbs01.dbf
channel d1: restoring datafile 00005 to /u01/app/oracle11/oradata/chendb/example01.dbf
channel d1: reading from backup piece /rmanbak/db/lev0_CHENDB_20200801_01v6p8eq_1_1.bak
channel d1: piece handle=/rmanbak/db/lev0_CHENDB_20200801_01v6p8eq_1_1.bak tag=0_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:35
Finished restore at 20200801 16:16:58
Starting recover at 20200801 16:16:58
channel d1: starting incremental datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00002: /u01/app/oracle11/oradata/chendb/sysaux01.dbf
destination for restore of datafile 00004: /u01/app/oracle11/oradata/chendb/users01.dbf
destination for restore of datafile 00006: /u01/app/oracle11/oradata/chendb/cjctbs01.dbf
channel d1: reading from backup piece /rmanbak/db/lev1_CHENDB_20200801_06v6pahk_1_1.bak
channel d1: piece handle=/rmanbak/db/lev1_CHENDB_20200801_06v6pahk_1_1.bak tag=1_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:01
channel d1: starting incremental datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /u01/app/oracle11/oradata/chendb/system01.dbf
destination for restore of datafile 00003: /u01/app/oracle11/oradata/chendb/undotbs01.dbf
destination for restore of datafile 00005: /u01/app/oracle11/oradata/chendb/example01.dbf
channel d1: reading from backup piece /rmanbak/db/lev1_CHENDB_20200801_05v6pahk_1_1.bak
channel d1: piece handle=/rmanbak/db/lev1_CHENDB_20200801_05v6pahk_1_1.bak tag=1_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:01
starting media recovery
released channel: d1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 08/01/2020 16:17:00
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of archived log for thread 1 with sequence 39 and starting SCN of 2280954 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 38 and starting SCN of 2280793 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 37 and starting SCN of 2280705 found to restore
RMAN-06025: no backup of archived log for thread 1 with sequence 36 and starting SCN of 2278640 found to restore

檢視資料檔案頭scn

SQL> select file#,checkpoint_change# from v$datafile_header;
     FILE# CHECKPOINT_CHANGE#
---------- ------------------
 1      2280683
 2      2280684
 3      2280683
 4      2280684
 5      2280683
 6      2280684
6 rows selected.

執行不完全恢復

RMAN>
run{
allocate channel d1 type disk;
###restore database until scn 2280684;
recover database until scn 2280684;
release channel d1;
}
allocated channel: d1
channel d1: SID=20 device type=DISK
Starting recover at 20200801 16:18:27
starting media recovery
released channel: d1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 08/01/2020 16:18:28
RMAN-06053: unable to perform media recovery because of missing log
RMAN-06025: no backup of archived log for thread 1 with sequence 36 and starting SCN of 2278640 found to restore

提示需要36號歸檔檔案 

檢視sequence 36

RMAN> list backupset of archivelog sequence 36;
List of Backup Sets
===================
BS Key  Size       Device Type Elapsed Time Completion Time  
------- ---------- ----------- ------------ -----------------
10      463.58M    DISK        00:00:42     20200801 15:14:08
        BP Key: 10   Status: UNAVAILABLE  Compressed: NO  Tag: ARCH_CJCDB
        Piece Name: /rmanbak/db/arch_CHENDB_20200801_0av6pasm_1_1.bak
  List of Archived Logs in backup set 10
  Thrd Seq     Low SCN    Low Time          Next SCN   Next Time
  ---- ------- ---------- ----------------- ---------- ---------
  1    36      2278640    20200801 14:33:01 2280705    20200801 15:07:56

需要備份片10

RMAN> change backupset 10 available;

解壓歸檔

RMAN> restore archivelog sequence 36;
[oracle@cjcos01 chendb]$ ls /arch/
chendb_1_36_1042210216.arc

恢復資料庫

RMAN>
run{
allocate channel d1 type disk;
restore database until scn 2280684;
recover database until scn 2280684;
release channel d1;
}
allocated channel: d1
channel d1: SID=20 device type=DISK
Starting restore at 20200801 16:53:20
channel d1: starting datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
channel d1: restoring datafile 00002 to /u01/app/oracle11/oradata/chendb/sysaux01.dbf
channel d1: restoring datafile 00004 to /u01/app/oracle11/oradata/chendb/users01.dbf
channel d1: restoring datafile 00006 to /u01/app/oracle11/oradata/chendb/cjctbs01.dbf
channel d1: reading from backup piece /rmanbak/db/lev0_CHENDB_20200801_02v6p8eq_1_1.bak
channel d1: piece handle=/rmanbak/db/lev0_CHENDB_20200801_02v6p8eq_1_1.bak tag=0_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:25
channel d1: starting datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
channel d1: restoring datafile 00001 to /u01/app/oracle11/oradata/chendb/system01.dbf
channel d1: restoring datafile 00003 to /u01/app/oracle11/oradata/chendb/undotbs01.dbf
channel d1: restoring datafile 00005 to /u01/app/oracle11/oradata/chendb/example01.dbf
channel d1: reading from backup piece /rmanbak/db/lev0_CHENDB_20200801_01v6p8eq_1_1.bak
channel d1: piece handle=/rmanbak/db/lev0_CHENDB_20200801_01v6p8eq_1_1.bak tag=0_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:35
Finished restore at 20200801 16:54:21
Starting recover at 20200801 16:54:21
channel d1: starting incremental datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00002: /u01/app/oracle11/oradata/chendb/sysaux01.dbf
destination for restore of datafile 00004: /u01/app/oracle11/oradata/chendb/users01.dbf
destination for restore of datafile 00006: /u01/app/oracle11/oradata/chendb/cjctbs01.dbf
channel d1: reading from backup piece /rmanbak/db/lev1_CHENDB_20200801_06v6pahk_1_1.bak
channel d1: piece handle=/rmanbak/db/lev1_CHENDB_20200801_06v6pahk_1_1.bak tag=1_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:03
channel d1: starting incremental datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /u01/app/oracle11/oradata/chendb/system01.dbf
destination for restore of datafile 00003: /u01/app/oracle11/oradata/chendb/undotbs01.dbf
destination for restore of datafile 00005: /u01/app/oracle11/oradata/chendb/example01.dbf
channel d1: reading from backup piece /rmanbak/db/lev1_CHENDB_20200801_05v6pahk_1_1.bak
channel d1: piece handle=/rmanbak/db/lev1_CHENDB_20200801_05v6pahk_1_1.bak tag=1_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:01
starting media recovery
archived log for thread 1 with sequence 36 is already on disk as file /arch/chendb_1_36_1042210216.arc
archived log file name=/arch/chendb_1_36_1042210216.arc thread=1 sequence=36
media recovery complete, elapsed time: 00:00:01
Finished recover at 20200801 16:54:26
released channel: d1

恢復成功 

SQL> select file#,checkpoint_change# from v$datafile_header;
     FILE# CHECKPOINT_CHANGE#
---------- ------------------
 1      2280684
 2      2280684
 3      2280684
 4      2280684
 5      2280684
 6      2280684
6 rows selected.

場景三:使用0級+歸檔備份恢復資料庫

設定增量備份失效

RMAN> 
change backupset 5 unavailable;
change backupset 6 unavailable;
change backupset 7 unavailable;
change backupset 8 unavailable;
change backupset 9 available;
change backupset 10 available;
change backupset 11 available;

檢視備份狀態

RMAN> list backupset summary;
List of Backups
===============
Key     TY LV S Device Type Completion Time   #Pieces #Copies Compressed Tag
------- -- -- - ----------- ----------------- ------- ------- ---------- ---
1       B  0  A DISK        20200801 14:33:06 1       1       NO         0_RMANBAK_CJCDB
2       B  0  A DISK        20200801 14:33:26 1       1       NO         0_RMANBAK_CJCDB
3       B  0  A DISK        20200801 14:33:30 1       1       NO         0_RMANBAK_CJCDB
4       B  0  A DISK        20200801 14:33:31 1       1       NO         0_RMANBAK_CJCDB
5       B  1  U DISK        20200801 15:08:41 1       1       NO         1_RMANBAK_CJCDB
6       B  1  U DISK        20200801 15:08:48 1       1       NO         1_RMANBAK_CJCDB
7       B  1  U DISK        20200801 15:08:49 1       1       NO         1_RMANBAK_CJCDB
8       B  1  U DISK        20200801 15:08:50 1       1       NO         1_RMANBAK_CJCDB
9       B  A  A DISK        20200801 15:14:07 1       1       NO         ARCH_CJCDB
10      B  A  A DISK        20200801 15:14:08 1       1       NO         ARCH_CJCDB
11      B  A  A DISK        20200801 15:14:13 1       1       NO         ARCH_CJCDB
12      B  F  A DISK        20200801 15:14:15 1       1       NO         TAG20200801T151414

執行完全恢復

RMAN>
run{
allocate channel d1 type disk;
restore database;
recover database;
release channel d1;
}
released channel: ORA_DISK_1
allocated channel: d1
channel d1: SID=20 device type=DISK
Starting restore at 20200801 17:12:20
channel d1: starting datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
channel d1: restoring datafile 00002 to /u01/app/oracle11/oradata/chendb/sysaux01.dbf
channel d1: restoring datafile 00004 to /u01/app/oracle11/oradata/chendb/users01.dbf
channel d1: restoring datafile 00006 to /u01/app/oracle11/oradata/chendb/cjctbs01.dbf
channel d1: reading from backup piece /rmanbak/db/lev0_CHENDB_20200801_02v6p8eq_1_1.bak
channel d1: piece handle=/rmanbak/db/lev0_CHENDB_20200801_02v6p8eq_1_1.bak tag=0_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:25
channel d1: starting datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
channel d1: restoring datafile 00001 to /u01/app/oracle11/oradata/chendb/system01.dbf
channel d1: restoring datafile 00003 to /u01/app/oracle11/oradata/chendb/undotbs01.dbf
channel d1: restoring datafile 00005 to /u01/app/oracle11/oradata/chendb/example01.dbf
channel d1: reading from backup piece /rmanbak/db/lev0_CHENDB_20200801_01v6p8eq_1_1.bak
channel d1: piece handle=/rmanbak/db/lev0_CHENDB_20200801_01v6p8eq_1_1.bak tag=0_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:35
Finished restore at 20200801 17:13:20
Starting recover at 20200801 17:13:20
starting media recovery
archived log for thread 1 with sequence 36 is already on disk as file /arch/chendb_1_36_1042210216.arc
channel d1: starting archived log restore to default destination
channel d1: restoring archived log
archived log thread=1 sequence=34
channel d1: restoring archived log
archived log thread=1 sequence=35
channel d1: reading from backup piece /rmanbak/db/arch_CHENDB_20200801_0av6pasm_1_1.bak
channel d1: piece handle=/rmanbak/db/arch_CHENDB_20200801_0av6pasm_1_1.bak tag=ARCH_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:15
archived log file name=/arch/chendb_1_34_1042210216.arc thread=1 sequence=34
archived log file name=/arch/chendb_1_35_1042210216.arc thread=1 sequence=35
archived log file name=/arch/chendb_1_36_1042210216.arc thread=1 sequence=36
channel d1: starting archived log restore to default destination
channel d1: restoring archived log
archived log thread=1 sequence=37
channel d1: restoring archived log
archived log thread=1 sequence=38
channel d1: restoring archived log
archived log thread=1 sequence=39
channel d1: reading from backup piece /rmanbak/db/arch_CHENDB_20200801_0bv6pau4_1_1.bak
channel d1: piece handle=/rmanbak/db/arch_CHENDB_20200801_0bv6pau4_1_1.bak tag=ARCH_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:01
archived log file name=/arch/chendb_1_37_1042210216.arc thread=1 sequence=37
media recovery complete, elapsed time: 00:00:01
Finished recover at 20200801 17:13:44
released channel: d1

恢復成功 

場景四:完全恢復

將所有備份設定為可用 

RMAN>
change backupset 5 available;
change backupset 6 available;
change backupset 7 available;
change backupset 8 available;

檢視備份狀態 

RMAN> list backupset summary;
List of Backups
===============
Key     TY LV S Device Type Completion Time   #Pieces #Copies Compressed Tag
------- -- -- - ----------- ----------------- ------- ------- ---------- ---
1       B  0  A DISK        20200801 14:33:06 1       1       NO         0_RMANBAK_CJCDB
2       B  0  A DISK        20200801 14:33:26 1       1       NO         0_RMANBAK_CJCDB
3       B  0  A DISK        20200801 14:33:30 1       1       NO         0_RMANBAK_CJCDB
4       B  0  A DISK        20200801 14:33:31 1       1       NO         0_RMANBAK_CJCDB
5       B  1  A DISK        20200801 15:08:41 1       1       NO         1_RMANBAK_CJCDB
6       B  1  A DISK        20200801 15:08:48 1       1       NO         1_RMANBAK_CJCDB
7       B  1  A DISK        20200801 15:08:49 1       1       NO         1_RMANBAK_CJCDB
8       B  1  A DISK        20200801 15:08:50 1       1       NO         1_RMANBAK_CJCDB
9       B  A  A DISK        20200801 15:14:07 1       1       NO         ARCH_CJCDB
10      B  A  A DISK        20200801 15:14:08 1       1       NO         ARCH_CJCDB
11      B  A  A DISK        20200801 15:14:13 1       1       NO         ARCH_CJCDB
12      B  F  A DISK        20200801 15:14:15 1       1       NO         TAG20200801T151414
released channel: ORA_DISK_1
allocated channel: d1
channel d1: SID=20 device type=DISK
Starting restore at 20200801 17:25:24
channel d1: starting datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
channel d1: restoring datafile 00002 to /u01/app/oracle11/oradata/chendb/sysaux01.dbf
channel d1: restoring datafile 00004 to /u01/app/oracle11/oradata/chendb/users01.dbf
channel d1: restoring datafile 00006 to /u01/app/oracle11/oradata/chendb/cjctbs01.dbf
channel d1: reading from backup piece /rmanbak/db/lev0_CHENDB_20200801_02v6p8eq_1_1.bak
channel d1: piece handle=/rmanbak/db/lev0_CHENDB_20200801_02v6p8eq_1_1.bak tag=0_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:25
channel d1: starting datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
channel d1: restoring datafile 00001 to /u01/app/oracle11/oradata/chendb/system01.dbf
channel d1: restoring datafile 00003 to /u01/app/oracle11/oradata/chendb/undotbs01.dbf
channel d1: restoring datafile 00005 to /u01/app/oracle11/oradata/chendb/example01.dbf
channel d1: reading from backup piece /rmanbak/db/lev0_CHENDB_20200801_01v6p8eq_1_1.bak
channel d1: piece handle=/rmanbak/db/lev0_CHENDB_20200801_01v6p8eq_1_1.bak tag=0_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:35
Finished restore at 20200801 17:26:24
Starting recover at 20200801 17:26:24
channel d1: starting incremental datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00002: /u01/app/oracle11/oradata/chendb/sysaux01.dbf
destination for restore of datafile 00004: /u01/app/oracle11/oradata/chendb/users01.dbf
destination for restore of datafile 00006: /u01/app/oracle11/oradata/chendb/cjctbs01.dbf
channel d1: reading from backup piece /rmanbak/db/lev1_CHENDB_20200801_06v6pahk_1_1.bak
channel d1: piece handle=/rmanbak/db/lev1_CHENDB_20200801_06v6pahk_1_1.bak tag=1_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:01
channel d1: starting incremental datafile backup set restore
channel d1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /u01/app/oracle11/oradata/chendb/system01.dbf
destination for restore of datafile 00003: /u01/app/oracle11/oradata/chendb/undotbs01.dbf
destination for restore of datafile 00005: /u01/app/oracle11/oradata/chendb/example01.dbf
channel d1: reading from backup piece /rmanbak/db/lev1_CHENDB_20200801_05v6pahk_1_1.bak
channel d1: piece handle=/rmanbak/db/lev1_CHENDB_20200801_05v6pahk_1_1.bak tag=1_RMANBAK_CJCDB
channel d1: restored backup piece 1
channel d1: restore complete, elapsed time: 00:00:01
starting media recovery
archived log for thread 1 with sequence 36 is already on disk as file /arch/chendb_1_36_1042210216.arc
archived log for thread 1 with sequence 37 is already on disk as file /arch/chendb_1_37_1042210216.arc
archived log for thread 1 with sequence 38 is already on disk as file /arch/chendb_1_38_1042210216.arc
archived log for thread 1 with sequence 39 is already on disk as file /arch/chendb_1_39_1042210216.arc
archived log file name=/arch/chendb_1_36_1042210216.arc thread=1 sequence=36
archived log file name=/arch/chendb_1_37_1042210216.arc thread=1 sequence=37
media recovery complete, elapsed time: 00:00:01
Finished recover at 20200801 17:26:28
released channel: d1

恢復完成,啟動資料庫

SQL> alter database open;

檢視資料 

SQL> conn cjc/cjc
SQL> select *from tab;
TNAME       TABTYPECLUSTERID
------------------------------ ------- ----------
T1       TABLE
T2       TABLE
T3       TABLE
T5       TABLE
T6       TABLE
6 rows selected.

場景五:異地恢復常用命令

1 恢復引數檔案 

RMAN> startup nomount
RMAN> restore spfile to '/rmandata/spfilecjcdb01.ora' from '/0712/rman/db/lev0_CJCDB01_20200711_04v52r5k_1_1.bak';
SQL> shutdown immedaite
SQL> create pfile='/rmandata/initcjcdb01.ora' from spfile='/rmandata/spfilecjcdb01.ora';
---修改initcjcdb01.ora引數
SQL> startup nomount pfile='/rmandata/initcjcdb01.ora'

2 恢復控制檔案

RMAN> list backupset of controlfile;
run 
{
allocate channel c1 type disk;
restore controlfile from '/0712/rman/db/ctl_CJCDB01_20200712_1vv54j7m_1_1.ctl';
release channel c1;
}

3 檢視檔案路徑

select name from v$datafile
union all
select name from v$tempfile
union all
select name from v$controlfile
union all select member from v$logfile;

4 生成轉換檔案位置的語句

SQL>
set line 150
set page 100
set heading off 
select 'set newname for datafile ' || '''' || name || '''' || ' to ' ||
       chr(39) ||
       replace(name, '+DATA/cjcdb/datafile/', '/rmandata/db/') ||
       ''';'
  from (select name
          from v$datafile
        union all
        select name
          from v$tempfile
        union all
        select name
          from v$controlfile
        union all
        select member from v$logfile);

###
set newname for datafile '+DATA/cjcdb/datafile/system.256.1039343535' to '/rmandata/db/system.256.1039343535';
set newname for datafile '+DATA/cjcdb/datafile/sysaux.257.1039343537' to '/rmandata/db/sysaux.257.1039343537';
set newname for datafile '+DATA/cjcdb/datafile/undotbs1.258.1039343539' to '/rmandata/db/undotbs1.258.1039343539';
set newname for datafile '+DATA/cjcdb/datafile/users.259.1039343539' to '/rmandata/db/users.259.1039343539';
set newname for datafile '+DATA/cjcdb/datafile/undotbs2.264.1039343919' to '/rmandata/db/undotbs2.264.1039343919';
set newname for datafile '+DATA/cjcdb/datafile/cjctbs.268.1043622893' to '/rmandata/db/cjctbs.268.1043622893';
set newname for datafile '+DATA/cjcdb/datafile/chentbs.267.1046799153' to '/rmandata/db/chentbs.267.1046799153';
set newname for datafile '+DATA/cjcdb/datafile/chentbs01.272.1046799329' to '/rmandata/db/chentbs01.272.1046799329';
set newname for datafile '+DATA/cjcdb/tempfile/temp.263.1039343731' to '+DATA/cjcdb/tempfile/temp.263.1039343731';
set newname for datafile '/rmandata/control01.ctl' to '/rmandata/control01.ctl';
set newname for datafile '+DATA/cjcdb/onlinelog/group_2.262.1039343705' to '+DATA/cjcdb/onlinelog/group_2.262.1039343705';
set newname for datafile '+DATA/cjcdb/onlinelog/group_1.261.1039343703' to '+DATA/cjcdb/onlinelog/group_1.261.1039343703';
set newname for datafile '+DATA/cjcdb/onlinelog/group_3.265.1039344119' to '+DATA/cjcdb/onlinelog/group_3.265.1039344119';
set newname for datafile '+DATA/cjcdb/onlinelog/group_4.266.1039344121' to '+DATA/cjcdb/onlinelog/group_4.266.1039344121';
###

5 修改檔案路徑

如果Restore執行後執行了SWITCH DATAFILE ALL;語句,可以不用執行下面的操作。

SQL>
set line 150
set page 100
set heading off 
select 'alter database rename file ' || '''' || name || '''' || ' to ' ||
       chr(39) ||
       replace(name, '+DATA/cjcdb/datafile/', '/rmandata/db/') ||
       ''';'
  from (select name
          from v$datafile
        union all
        select name
          from v$tempfile
        union all
        select name
          from v$controlfile
        union all
        select member from v$logfile);
###
alter database rename file '+DATA/cjcdb/datafile/system.256.1039343535' to '/rmandata/db/system.256.1039343535';
alter database rename file '+DATA/cjcdb/datafile/sysaux.257.1039343537' to '/rmandata/db/sysaux.257.1039343537';
alter database rename file '+DATA/cjcdb/datafile/undotbs1.258.1039343539' to '/rmandata/db/undotbs1.258.1039343539';
alter database rename file '+DATA/cjcdb/datafile/users.259.1039343539' to '/rmandata/db/users.259.1039343539';
alter database rename file '+DATA/cjcdb/datafile/undotbs2.264.1039343919' to '/rmandata/db/undotbs2.264.1039343919';
alter database rename file '+DATA/cjcdb/datafile/cjctbs.268.1043622893' to '/rmandata/db/cjctbs.268.1043622893';
alter database rename file '+DATA/cjcdb/datafile/chentbs.267.1046799153' to '/rmandata/db/chentbs.267.1046799153';
alter database rename file '+DATA/cjcdb/datafile/chentbs01.272.1046799329' to '/rmandata/db/chentbs01.272.1046799329';
alter database rename file '+DATA/cjcdb/tempfile/temp.263.1039343731' to '+DATA/cjcdb/tempfile/temp.263.1039343731';
alter database rename file '/rmandata/control01.ctl' to '/rmandata/control01.ctl';
alter database rename file '+DATA/cjcdb/onlinelog/group_2.262.1039343705' to '+DATA/cjcdb/onlinelog/group_2.262.1039343705';
alter database rename file '+DATA/cjcdb/onlinelog/group_1.261.1039343703' to '+DATA/cjcdb/onlinelog/group_1.261.1039343703';
alter database rename file '+DATA/cjcdb/onlinelog/group_3.265.1039344119' to '+DATA/cjcdb/onlinelog/group_3.265.1039344119';
alter database rename file '+DATA/cjcdb/onlinelog/group_4.266.1039344121' to '+DATA/cjcdb/onlinelog/group_4.266.1039344121';
###

6 異機恢復示例(RAC備份恢復到單機):

RMAN>
run{
allocate channel d1 type disk;
set newname for datafile '+DATA/cjcdb/datafile/system.256.1039343535' to '/rmandata/db/system.256.1039343535';
set newname for datafile '+DATA/cjcdb/datafile/sysaux.257.1039343537' to '/rmandata/db/sysaux.257.1039343537';
set newname for datafile '+DATA/cjcdb/datafile/undotbs1.258.1039343539' to '/rmandata/db/undotbs1.258.1039343539';
set newname for datafile '+DATA/cjcdb/datafile/users.259.1039343539' to '/rmandata/db/users.259.1039343539';
set newname for datafile '+DATA/cjcdb/datafile/undotbs2.264.1039343919' to '/rmandata/db/undotbs2.264.1039343919';
set newname for datafile '+DATA/cjcdb/datafile/cjctbs.268.1043622893' to '/rmandata/db/cjctbs.268.1043622893';
set newname for datafile '+DATA/cjcdb/datafile/chentbs.267.1046799153' to '/rmandata/db/chentbs.267.1046799153';
set newname for datafile '+DATA/cjcdb/datafile/chentbs01.272.1046799329' to '/rmandata/db/chentbs01.272.1046799329';
set newname for datafile '+DATA/cjcdb/tempfile/temp.263.1039343731' to '+DATA/cjcdb/tempfile/temp.263.1039343731';
set newname for datafile '/rmandata/control01.ctl' to '/rmandata/control01.ctl';
set newname for datafile '+DATA/cjcdb/onlinelog/group_2.262.1039343705' to '+DATA/cjcdb/onlinelog/group_2.262.1039343705';
set newname for datafile '+DATA/cjcdb/onlinelog/group_1.261.1039343703' to '+DATA/cjcdb/onlinelog/group_1.261.1039343703';
set newname for datafile '+DATA/cjcdb/onlinelog/group_3.265.1039344119' to '+DATA/cjcdb/onlinelog/group_3.265.1039344119';
set newname for datafile '+DATA/cjcdb/onlinelog/group_4.266.1039344121' to '+DATA/cjcdb/onlinelog/group_4.266.1039344121';
restore database until time "to_date('2020-07-31 22:17:47','yyyy-mm-dd hh24:mi:ss')";
SWITCH DATAFILE ALL;
recover database until time "to_date('2020-07-31 22:17:47','yyyy-mm-dd hh24:mi:ss')";
release channel d1;
}

7 在某些特定場景下:

先執行了

restore database until time xxx;
recover database until time xxx;

recover結束後沒有啟動資料庫,資料庫處於mouont狀態。

這時如果想將資料庫recover到更新的時間,不需要在執行

restore database until time xxx;

資料量大時,restore database耗時,耗空間。

只需要執行

recover database until time xxx+time;

但是如果在這個時間段內生成了新的資料檔案,不能直接進行recover。

需要單獨restore新增的資料檔案,或通過下面的命令生成一個新的檔案。

alter database create datafile '+DATA/cjcdb/datafile/cjc_data_5.dbf' as '/oradata/cjcdb/datafile/cjc_data_5.dbf';

然後可以進行執行recover。

歡迎關注我的微信公眾號"IT小Chen",共同學習,共同成長!!  

Oracle RMAN恢復測試

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

相關文章