Oracle RMAN備份恢復(fù)測(cè)試步驟

1.1數(shù)據(jù)庫測(cè)試環(huán)境

RMAN恢復(fù)可以有原機(jī)恢復(fù)和異機(jī)恢復(fù),這里我們將分別模擬這2種恢復(fù)場(chǎng)景。


1.2RMAN備份

1.2.1?設(shè)置數(shù)據(jù)庫歸檔

查看數(shù)據(jù)庫是否運(yùn)行在歸檔模式:

SQL> archive log list;

Database log mode?????????No Archive Mode

Automatic archival???????Disabled?????#未開啟歸檔

Archive destination??????USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence?????117

Current log sequence??????????119

SQL>?

備注:如果數(shù)據(jù)庫已經(jīng)開啟歸檔,下面的操縱可以忽略。

如上所示未開啟歸檔,可按下面方法開啟數(shù)據(jù)庫歸檔

SQL>?shutdownimmediate????#關(guān)閉數(shù)據(jù)庫

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL>?startupmount;????#啟動(dòng)到mount狀態(tài)

ORACLE instance started.


Total System Global Area??688959488 bytes

Fixed Size??????????2256432 bytes

Variable Size????????566231504 bytes

Database Buffers?????117440512 bytes

Redo Buffers???????????3031040 bytes

Database mounted.

SQL>?alterdatabase archivelog;????#開啟歸檔


Database altered.


SQL>?alterdatabase open;???#open數(shù)據(jù)庫


Database altered.


SQL>?altersystem set?log_archive_dest_1='location=/data/CEBPM/archivelog';??#設(shè)置歸檔路徑


System altered.


SQL> archive log list;

Database log mode?????????Archive Mode

Automatic archival???????Enabled

Archive destination???????/data/CEBPM/archivelog

Oldest online log sequence?????119

Next log sequence to archive???121

Current log sequence??????????121

SQL>

1.2.2?構(gòu)建RMAN備份腳本

run{

???allocate channel d1 type disk;

???backup filesperset 10 full format'/data/backup/cebpm/fullback/FULLBAK_%d_%T_%s_%p' tag db_full_bakdatabase;??#全備份

???sql 'alter system archive log current';??#歸檔

???backup filesperset 50 archivelog all deleteall input tag arch_bak format'/data/backup/cebpm/archivelog/ARCHBAK_%d_%T_%s_%p';?#歸檔備份

???backup?format '/data/backup/cebpm/ctlbackup/CTLBAK_%d_%T_%s_%p' tag ctl_bakcurrent controlfile;?#控制文件備份

???backup?format '/data/backup/cebpm/ctlbackup/INITBAK_%d_%T_%s_%p' taginitpara_bak spfile;?#參數(shù)文件備份

???release channel d1;

????}

1.2.3?執(zhí)行備份

執(zhí)行上面的構(gòu)建好的rman備份腳本:

cebpm:/home/oracle@db1>rman target /


Recovery Manager: Release 11.2.0.4.0 -Production on Mon Jun 12 14:37:07 2017


Copyright (c) 1982, 2011, Oracle and/or itsaffiliates.??All rights reserved.


connected to target database: CEBPM(DBID=3677012495)


RMAN> run{

??allocate channel d1 type disk;

??backup filesperset 10 full format'/data/backup/cebpm/fullback/FULLBAK_%d_%T_%s_%p' tag db_full_bak database;

??sql 'alter system archive log current';

??backup filesperset 50 archivelog all delete all input tag arch_bakformat '/data/backup/cebpm/archivelog/ARCHBAK_%d_%T_%s_%p';

??backup??format'/data/backup/cebpm/ctlbackup/CTLBAK_%d_%T_%s_%p' tag ctl_bak currentcontrolfile;

??backup??format'/data/backup/cebpm/ctlbackup/INITBAK_%d_%T_%s_%p' tag initpara_bak spfile;

??release channel d1;

????}

2> 3> 4> 5> 6> 7> 8>9>

using target database control file insteadof recovery catalog

allocated channel: d1

channel d1: SID=38 device type=DISK


Starting backup at 2017/06/12 14:37:16

channel d1: starting full datafile backupset

channel d1: specifying datafile(s) inbackup set

input datafile file number=00001name=/data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf

input datafile file number=00002name=/data/CEBPM/datafile/o1_mf_sysaux_dm1fnw5v_.dbf

input datafile file number=00003name=/data/CEBPM/datafile/o1_mf_undotbs1_dm1foow9_.dbf

input datafile file number=00004name=/data/CEBPM/datafile/o1_mf_users_dm1fqcrp_.dbf

channel d1: starting piece 1 at 2017/06/1214:37:17

channel d1: finished piece 1 at 2017/06/1214:39:15

piece handle=/data/backup/cebpm/fullback/FULLBAK_CEBPM_20170612_34_1tag=DB_FULL_BAK comment=NONE

channel d1: backup set complete, elapsedtime: 00:01:58

channel d1: starting full datafile backupset

channel d1: specifying datafile(s) inbackup set

including current control file in backupset

including current SPFILE in backup set

channel d1: starting piece 1 at 2017/06/1214:39:17

channel d1: finished piece 1 at 2017/06/1214:39:18

piecehandle=/data/backup/cebpm/fullback/FULLBAK_CEBPM_20170612_35_1 tag=DB_FULL_BAKcomment=NONE

channel d1: backup set complete, elapsedtime: 00:00:01

Finished backup at 2017/06/12 14:39:18


sql statement: alter system archive logcurrent


Starting backup at 2017/06/12 14:39:25

current log archived

channel d1: starting archived log backupset

channel d1: specifying archived log(s) inbackup set

input archived log thread=1 sequence=24RECID=153 STAMP=946477368

input archived log thread=1 sequence=25RECID=154 STAMP=946477652

input archived log thread=1 sequence=26RECID=155 STAMP=946477652

input archived log thread=1 sequence=27RECID=156 STAMP=946478014

input archived log thread=1 sequence=28RECID=157 STAMP=946478365

input archived log thread=1 sequence=29RECID=158 STAMP=946478365

channel d1: starting piece 1 at 2017/06/1214:39:27

channel d1: finished piece 1 at 2017/06/1214:39:28

piecehandle=/data/backup/cebpm/archivelog/ARCHBAK_CEBPM_20170612_36_1 tag=ARCH_BAKcomment=NONE

channel d1: backup set complete, elapsedtime: 00:00:01

channel d1: deleting archived log(s)

archived log filename=/data/CEBPM/archivelog/1_24_945953743.arc RECID=153 STAMP=946477368

archived log filename=/data/CEBPM/archivelog/1_25_945953743.arc RECID=154 STAMP=946477652

archived log filename=/data/CEBPM/archivelog/1_26_945953743.arc RECID=155 STAMP=946477652

archived log filename=/data/CEBPM/archivelog/1_27_945953743.arc RECID=156 STAMP=946478014

archived log filename=/data/CEBPM/archivelog/1_28_945953743.arc RECID=157 STAMP=946478365

archived log filename=/data/CEBPM/archivelog/1_29_945953743.arc RECID=158 STAMP=946478365

Finished backup at 2017/06/12 14:39:29


Starting backup at 2017/06/12 14:39:31

channel d1: starting full datafile backupset

channel d1: specifying datafile(s) inbackup set

including current control file in backupset

channel d1: starting piece 1 at 2017/06/1214:39:33

channel d1: finished piece 1 at 2017/06/1214:39:34

piecehandle=/data/backup/cebpm/ctlbackup/CTLBAK_CEBPM_20170612_37_1 tag=CTL_BAKcomment=NONE

channel d1: backup set complete, elapsedtime: 00:00:01

Finished backup at 2017/06/12 14:39:34


Starting backup at 2017/06/12 14:39:38

channel d1: starting full datafile backupset

channel d1: specifying datafile(s) inbackup set

including current SPFILE in backup set

channel d1: starting piece 1 at 2017/06/1214:39:39

channel d1: finished piece 1 at 2017/06/1214:39:40

piecehandle=/data/backup/cebpm/ctlbackup/INITBAK_CEBPM_20170612_38_1tag=INITPARA_BAK comment=NONE

channel d1: backup set complete, elapsedtime: 00:00:02

Finished backup at 2017/06/12 14:39:41


released channel: d1


RMAN>

1.2.4?生成測(cè)試時(shí)間點(diǎn)

這里我們?yōu)榱蓑?yàn)證恢復(fù)之后數(shù)據(jù)的可靠性,我們?cè)跀?shù)據(jù)庫備份完成之后,再進(jìn)行一些操作,并記錄下這些操作的時(shí)間,以便后續(xù)作為參考。

SQL> set time on;

15:32:02 SQL> create table mytest1(idnumber);


Table created.


15:32:29 SQL> insert into mytest1values(1);


1 row created.


15:32:46 SQL> insert into mytest1values(2);


1 row created.


15:33:04 SQL> commit;


Commit complete.


15:33:14 SQL> selectto_char(sysdate,'yyyy-mm-dd hh24:mi:ss') time from dual;


TIME

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

2017-06-12 15:33:21???#將要恢復(fù)的時(shí)間點(diǎn)


15:33:21 SQL> insert into mytest1values(3);

1 row created.


15:33:40 SQL> commit;


Commit complete.


15:33:44 SQL> alter system archive logcurrent;


System altered.


15:33:55 SQL>

2.1RMAN恢復(fù)

2.1.1?基于時(shí)間點(diǎn)的原機(jī)恢復(fù)

1、??這里為了測(cè)試,所以在恢復(fù)之前首先把數(shù)據(jù)庫關(guān)閉

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL>

2、??由于是原機(jī)恢復(fù),這里直接將數(shù)據(jù)庫啟動(dòng)到mount狀態(tài)(忽略恢復(fù)spfile和controlfile步驟)

SQL>?startup mount

ORACLE instancestarted.


Total SystemGlobal Area??688959488 bytes

Fixed Size??????????????????????2256432 bytes

Variable Size?????????????566231504 bytes

Database Buffers?????117440512 bytes

Redo Buffers??????????????3031040 bytes

Database mounted.

3、??恢復(fù)數(shù)據(jù)文件

cebpm:/home/oracle@db1>rman target /


Recovery Manager: Release 11.2.0.4.0 - Production on MonJun 12 15:37:30 2017


Copyright (c) 1982, 2011, Oracle and/or itsaffiliates.??All rights reserved.


connected to target database: CEBPM (DBID=3677012495, notopen)


RMAN>restore database;


Starting restore at 2017-06-12 15:37:37

using target database control file instead of recoverycatalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=20 device type=DISK


channel ORA_DISK_1: starting datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restorefrom backup set

channel ORA_DISK_1: restoring datafile 00001 to/data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf

channel ORA_DISK_1: restoring datafile 00002 to/data/CEBPM/datafile/o1_mf_sysaux_dm1fnw5v_.dbf

channel ORA_DISK_1: restoring datafile 00003 to/data/CEBPM/datafile/o1_mf_undotbs1_dm1foow9_.dbf

channel ORA_DISK_1: restoring datafile 00004 to/data/CEBPM/datafile/o1_mf_users_dm1fqcrp_.dbf

channel ORA_DISK_1: reading from backup piece/data/backup/cebpm/fullback/FULLBAK_CEBPM_20170612_34_1

channel ORA_DISK_1: piecehandle=/data/backup/cebpm/fullback/FULLBAK_CEBPM_20170612_34_1 tag=DB_FULL_BAK

channel ORA_DISK_1: restored backup piece 1

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

Finishedrestore at 2017-06-12 15:38:57


RMAN>


4、??應(yīng)用歸檔日志:

RMAN> run{

?????sql 'altersession set NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"';

?????recover database until time '2017-06-1215:33:21';

?}

2> 3> 4>

sql statement: alter session setNLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"


Starting recover at 2017-06-12 15:40:34

using channel ORA_DISK_1


starting media recovery


archived log for thread 1 with sequence 28 is already ondisk as file /data/CEBPM/archivelog/1_28_945953743.arc

archived log for thread 1 with sequence 29 is already ondisk as file /data/CEBPM/archivelog/1_29_945953743.arc

archived log for thread 1 with sequence 30 is already ondisk as file /data/CEBPM/archivelog/1_30_945953743.arc

archived log for thread 1 with sequence 1 is already ondisk as file /data/CEBPM/archivelog/1_1_946480114.arc

archived log for thread 1 with sequence 2 is already ondisk as file /data/CEBPM/archivelog/1_2_946480114.arc

archived log for thread 1 with sequence 1 is already ondisk as file /data/CEBPM/archivelog/1_1_946481342.arc

archived log filename=/data/CEBPM/archivelog/1_28_945953743.arc thread=1 sequence=28

archived log file name=/data/CEBPM/archivelog/1_29_945953743.arcthread=1 sequence=29

archived log filename=/data/CEBPM/archivelog/1_30_945953743.arc thread=1 sequence=30

archived log filename=/data/CEBPM/archivelog/1_1_946480114.arc thread=1 sequence=1

archived log file name=/data/CEBPM/archivelog/1_2_946480114.arcthread=1 sequence=2

media recovery complete, elapsed time: 00:00:02

Finishedrecover at 2017-06-12 15:40:38

RMAN>

5、??開啟數(shù)據(jù)庫

RMAN>alter database open resetlogs;

databaseopened

RMAN>

6、??驗(yàn)證恢復(fù)數(shù)據(jù),以上面的時(shí)間軸為參考點(diǎn)

SQL> select * frommytest1;


??????????ID

----------

???????????1

???????????2


SQL> select count(*)from mytest1;


??COUNT(*)

----------

???????????2


SQL>



如上可知基于時(shí)間點(diǎn)的恢復(fù)正常。

2..2?基于時(shí)間點(diǎn)的異機(jī)恢復(fù)

1、??首先將原機(jī)的備份文件傳到異機(jī)上

這里利用scp?命令進(jìn)行傳送,具體過程不再贅述,傳送到異機(jī)/u01/backup?下。如下所示:

cebpm:/u01/backup@db1>ll

總用量?967524

-rw-r-----. 1 oracle dba?14145024 6月??12 16:34ARCHBAK_CEBPM_20170612_36_1

drwxr-xr-x. 2 oracle dba??????4096 6月??12 16:48?archivelog

-rw-r-----. 1 oracle dba??9961472 6月??12 16:35CTLBAK_CEBPM_20170612_37_1

-rw-r-----. 1 oracle dba 956538880 6月??12 14:38 FULLBAK_CEBPM_20170612_34_1

-rw-r-----. 1 oracle dba??9994240 6月??12 14:39FULLBAK_CEBPM_20170612_35_1

-rw-r-----. 1 oracle dba????98304 6月??12 16:35INITBAK_CEBPM_20170612_38_1


注意這里一定要把歸檔也傳送過來。

2、??恢復(fù)參數(shù)文件

cebpm:/u01/backup@db2>rman target /


Recovery Manager: Release 11.2.0.4.0- Production on Tue Jun 13 08:34:58 2017


Copyright (c) 1982, 2011, Oracleand/or its affiliates.??All rightsreserved.


connected to target database (notstarted)


RMAN>?setdbid 3677012495


executing command: SET DBID


RMAN>?startupnomount


startup failed: ORA-01078: failurein processing system parameters

LRM-00109: could not open parameterfile '/u01/app/oracle/product/11.2.0/db_1/dbs/initcebpm.ora'


starting Oracle instance withoutparameter file for retrieval of spfile

Oracle instance started


Total System Global Area????1068937216 bytes


Fixed Size?????????????????????2260088 bytes

Variable Size????????????????281019272 bytes

Database Buffers?????????????780140544 bytes

Redo Buffers???????????????????5517312 bytes


RMAN>restore spfile to '/u01/app/oracle/product/11.2.0/db_1/dbs/initcebpm.ora' from'/u01/backup/INITBAK_CEBPM_20170612_38_1';


Starting restore at 2017/06/1308:39:04

using target database control fileinstead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=19 devicetype=DISK


channel ORA_DISK_1: restoring spfilefrom AUTOBACKUP /u01/backup/INITBAK_CEBPM_20170612_38_1

channel ORA_DISK_1: SPFILE restorefrom AUTOBACKUP complete

Finished restore at 2017/06/13 08:39:08


RMAN>

注意:

1.在rman下即使沒有參數(shù)文件,默認(rèn)也會(huì)啟動(dòng)一個(gè)DUMMY實(shí)例,以便能夠恢復(fù)參數(shù)???????文件。

備注:set dbid的唯一目的是使RMAN找到恢復(fù)參數(shù)文件和控制文件唯一確定的的備份?????????文件。

3、??對(duì)剛才恢復(fù)出來的參數(shù)文件稍作修改

ebpm.__java_pool_size=4194304

cebpm.__large_pool_size=8388608

cebpm.__oracle_base='/u01/app/oracle'#ORACLE_BASEset from environment

cebpm.__pga_aggregate_target=167772160

cebpm.__sga_target=524288000

cebpm.__shared_io_pool_size=0

cebpm.__shared_pool_size=155189248

cebpm.__streams_pool_size=0

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

*.audit_trail='db'

*.compatible='11.2.0.4.0'

*.control_files='/data/cdbpm/controlfile/control01.ctl'

*.db_create_file_dest='/data'

*.db_domain=''

*.db_name='cebpm'

*.db_recovery_file_dest='/data/cebpm'

*.db_recovery_file_dest_size=5368709120

*.db_unique_name='cebpm'

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

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

*.log_archive_dest_1='location=/data/cdbpm/archivelog'

*.log_archive_dest_2=''

*.log_archive_dest_state_1='enable'

*.log_archive_format='%t_%s_%r.arc'

*.memory_target=691011584

*.open_cursors=300

*.processes=200

*.remote_login_passwordfile='EXCLUSIVE'

*.sessions=1000

*.standby_file_management='AUTO'

*.undo_tablespace='UNDOTBS1'


修改主要有2個(gè)地方:

1)?參數(shù)文件里有些亂碼需要?jiǎng)h除

2)?修改參數(shù)文件的相關(guān)目錄文件

4、??根據(jù)剛才創(chuàng)建的參數(shù)文件,創(chuàng)建相應(yīng)的目錄

cebpm:/data@db2>mkdir /data/cebpm

cebpm:/data@db2>mkdir -p /u01/app/oracle/admin/cebpm/adump

cebpm:/data@db2>mkdir -p /data/cebpm/controlfile/

cebpm:/data@db2>mkdir -p /data/cebpm/archivelog

5、??用修改過的參數(shù)文件啟動(dòng)到nomount狀態(tài)

SQL>?shutdownabort;

ORACLE instance shut down.

SQL>?startupnomount pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initcebpm.ora';

ORACLE instance started.


Total System Global Area??688959488 bytes

Fixed Size??????????????????????2256432bytes

Variable Size??????????????566231504 bytes

Database Buffers?????117440512 bytes

Redo Buffers???????????????3031040 bytes

SQL>?createspfile from pfile;


File created.

6、??恢復(fù)控制文件

RMAN>?restore controlfile to'/data/cebpm/controlfile/control01.ctl' from'/u01/backup/CTLBAK_CEBPM_20170612_37_1';


Startingrestore at 2017/06/13 08:53:05

usingtarget database control file instead of recovery catalog

allocatedchannel: ORA_DISK_1

channelORA_DISK_1: SID=18 device type=DISK


channelORA_DISK_1: restoring control file

channelORA_DISK_1: restore complete, elapsed time: 00:00:01

Finishedrestore at 2017/06/13 08:53:07


RMAN>

7、??啟動(dòng)到mount狀態(tài)

RMAN>?alterdatabase mount;


using target database control fileinstead of recovery catalog

database mounted

8、??查看schema

RMAN>report schema;


RMAN-06139: WARNING: control file isnot current for REPORT SCHEMA

Report of database schema fordatabase with db_unique_name CEBPM


List of Permanent Datafiles

===========================

File Size(MB) Tablespace???????????RB segs Datafile Name

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

1???0????????SYSTEM???????????????***?????/data/CEBPM/datafile/o1_mf_system_dm1flxkw_.dbf

2???0????????SYSAUX???????????????***?????/data/CEBPM/datafile/o1_mf_sysaux_dm1fnw5v_.dbf

3???0????????UNDOTBS1?????????????***?????/data/CEBPM/datafile/o1_mf_undotbs1_dm1foow9_.dbf

4???0????????USERS????????????????***?????/data/CEBPM/datafile/o1_mf_users_dm1fqcrp_.dbf


List of Temporary Files

=======================

File Size(MB) Tablespace???????????Maxsize(MB) Tempfile Name

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

1???20???????TEMP?????????????????32767???????/data/CEBPM/datafile/o1_mf_temp_dm1fp4bs_.tmp


注意:上面的顯示的數(shù)據(jù)文件是原數(shù)據(jù)庫上的數(shù)據(jù)文件以及數(shù)據(jù)文件的路徑。如果異機(jī)上沒有相應(yīng)的數(shù)據(jù)文件路徑的話,有2種解決辦法:1)創(chuàng)建和原機(jī)完全一樣的數(shù)據(jù)文件路徑2)重指向新的數(shù)據(jù)文件路徑。下面介紹的就是第二種方法。

9、??在新控制文件中注冊(cè)數(shù)據(jù)文件備份和歸檔備份

RMAN>?catalogstart with '/u01/backup';


Starting implicit crosscheck backupat 2017/06/13 08:57:31

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=19 devicetype=DISK

Crosschecked 6 objects

Finished implicit crosscheck backupat 2017/06/13 08:57:33


Starting implicit crosscheck copy at2017/06/13 08:57:33

using channel ORA_DISK_1

Crosschecked 2 objects

Finished implicit crosscheck copy at2017/06/13 08:57:34


searching for all files in therecovery area

cataloging files...

no files cataloged


searching for all files that matchthe pattern /u01/backup


List of Files Unknown to theDatabase

=====================================

File Name:/u01/backup/ARCHBAK_CEBPM_20170612_36_1

File Name:/u01/backup/CTLBAK_CEBPM_20170612_37_1

File Name:/u01/backup/archivelog/1_2_946480114.arc

File Name:/u01/backup/archivelog/1_28_945953743.arc

File Name: /u01/backup/archivelog/1_31_945953743.arc

File Name:/u01/backup/archivelog/1_1_946481342.arc

File Name:/u01/backup/archivelog/1_1_946480114.arc

File Name:/u01/backup/archivelog/1_29_945953743.arc

File Name:/u01/backup/archivelog/1_2_946481342.arc

File Name:/u01/backup/archivelog/1_32_945953743.arc

File Name:/u01/backup/archivelog/1_3_946480114.arc

File Name:/u01/backup/archivelog/1_30_945953743.arc

File Name:/u01/backup/FULLBAK_CEBPM_20170612_35_1

File Name:/u01/backup/INITBAK_CEBPM_20170612_38_1

File Name:/u01/backup/FULLBAK_CEBPM_20170612_34_1


Do you really want to catalog theabove files (enter YES or NO)??y

cataloging files...

cataloging done


List of Cataloged Files

=======================

File Name:/u01/backup/ARCHBAK_CEBPM_20170612_36_1

File Name:/u01/backup/CTLBAK_CEBPM_20170612_37_1

File Name:/u01/backup/archivelog/1_2_946480114.arc

File Name:/u01/backup/archivelog/1_28_945953743.arc

File Name:/u01/backup/archivelog/1_31_945953743.arc

File Name:/u01/backup/archivelog/1_1_946481342.arc

File Name:/u01/backup/archivelog/1_1_946480114.arc

File Name:/u01/backup/archivelog/1_29_945953743.arc

File Name:/u01/backup/archivelog/1_2_946481342.arc

File Name:/u01/backup/archivelog/1_32_945953743.arc

File Name: /u01/backup/archivelog/1_3_946480114.arc

File Name:/u01/backup/archivelog/1_30_945953743.arc

File Name:/u01/backup/FULLBAK_CEBPM_20170612_35_1

File Name:/u01/backup/INITBAK_CEBPM_20170612_38_1

File Name: /u01/backup/FULLBAK_CEBPM_20170612_34_1


10、???????????恢復(fù)數(shù)據(jù)文件

具體執(zhí)行腳本如下:

run{

set newnamefor datafile 1 to '/data/cebpm/datafile/system01.db';

setnewname for datafile 2 to '/data/cebpm/datafile/sysaux01.dbf';

setnewname for datafile 3 to '/data/cebpm/datafile/undotbs01.dbf';

setnewname for datafile 4 to?'/data/cebpm/datafile/users01.dbf';

restoredatabase;

switchdatafile all;

}

這里面set newname?是將原庫的數(shù)據(jù)文件的路徑重新指向到異機(jī)上新的路徑,

注意:異機(jī)上要首先創(chuàng)建/data/cebpm/datafile?這個(gè)路徑,如下

cebpm:/data/cebpm@db2>mkdir -p/data/cebpm/datafile/

具體執(zhí)行結(jié)果如下:

RMAN> run{

set newname for datafile 1 to '/data/cebpm/datafile/system01.db';

set newname for datafile 2 to '/data/cebpm/datafile/sysaux01.dbf';

set newname for datafile 3 to '/data/cebpm/datafile/undotbs01.dbf';

set newname for datafile 4 to?'/data/cebpm/datafi2> le/users01.dbf';

restore database;

switch datafile all;

}3> 4> 5> 6> 7> 8>


executing command: SET NEWNAME


executing command: SET NEWNAME


executing command: SET NEWNAME


executing command: SET NEWNAME


Starting restore at 2017/06/13 09:13:03

using channel ORA_DISK_1


channel ORA_DISK_1: starting datafile backup set restore

channel ORA_DISK_1: specifying datafile(s) to restore from backupset

channel ORA_DISK_1: restoring datafile 00001 to/data/cebpm/datafile/system01.db

channel ORA_DISK_1: restoring datafile 00002 to/data/cebpm/datafile/sysaux01.dbf

channel ORA_DISK_1: restoring datafile 00003 to/data/cebpm/datafile/undotbs01.dbf

channel ORA_DISK_1: restoring datafile 00004 to/data/cebpm/datafile/users01.dbf

channel ORA_DISK_1: reading from backup piece/u01/backup/FULLBAK_CEBPM_20170612_34_1

channel ORA_DISK_1: piecehandle=/u01/backup/FULLBAK_CEBPM_20170612_34_1 tag=DB_FULL_BAK

channel ORA_DISK_1: restored backup piece 1

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

Finished restore at 2017/06/13 09:14:20


datafile 1 switched to datafile copy

input datafile copy RECID=10 STAMP=946545261 filename=/data/cebpm/datafile/system01.db

datafile 2 switched to datafile copy

input datafile copy RECID=11 STAMP=946545261 filename=/data/cebpm/datafile/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=12 STAMP=946545261 filename=/data/cebpm/datafile/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=13 STAMP=946545261 filename=/data/cebpm/datafile/users01.dbf


RMAN>

11、???????????應(yīng)用歸檔日志


RMAN> run{

????sql 'altersession set NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"';

?????recover database until time '2017-06-1215:33:21';

?}2> 3> 4>


sql statement: alter session setNLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"


Starting recover at 2017/06/1309:17:24

using channel ORA_DISK_1


starting media recovery


archived log for thread 1 withsequence 28 is already on disk as file/u01/backup/archivelog/1_28_945953743.arc

archived log for thread 1 withsequence 29 is already on disk as file /u01/backup/archivelog/1_29_945953743.arc

archived log for thread 1 withsequence 30 is already on disk as file/u01/backup/archivelog/1_30_945953743.arc

archived log for thread 1 withsequence 1 is already on disk as file /u01/backup/archivelog/1_1_946480114.arc

archived log for thread 1 withsequence 2 is already on disk as file /u01/backup/archivelog/1_2_946480114.arc

archived log for thread 1 withsequence 1 is already on disk as file /u01/backup/archivelog/1_1_946481342.arc

archived log filename=/u01/backup/archivelog/1_28_945953743.arc thread=1 sequence=28

archived log filename=/u01/backup/archivelog/1_29_945953743.arc thread=1 sequence=29

archived log filename=/u01/backup/archivelog/1_30_945953743.arc thread=1 sequence=30

archived log filename=/u01/backup/archivelog/1_1_946480114.arc thread=1 sequence=1

archived log filename=/u01/backup/archivelog/1_2_946480114.arc thread=1 sequence=2

archived log filename=/u01/backup/archivelog/1_1_946481342.arc thread=1 sequence=1

media recovery complete, elapsedtime: 00:00:03

Finished recover at 2017/06/1309:17:30


RMAN>

12、???????????重定向在線歸檔日志文件

首先查看歸檔日志文件

SQL> select member fromv$logfile;


MEMBER

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

/data/CEBPM/onlinelog/o1_mf_1_dm1fljft_.log

/data/CEBPM/onlinelog/o1_mf_2_dm1fll24_.log

/data/CEBPM/onlinelog/o1_mf_3_dm1flmld_.log


SQL>

上面的顯示的原機(jī)上的歸檔日志文件路徑,現(xiàn)在重定向到異機(jī)上新的位置,具體操作如下:


SQL> alter database rename file'/data/CEBPM/onlinelog/o1_mf_1_dm1fljft_.log' to '/data/cebpm/onlinelog/redo01.log';


Database altered.


SQL> alter database rename file'/data/CEBPM/onlinelog/o1_mf_2_dm1fll24_.log' to'/data/cebpm/onlinelog/redo02.log' ;


Database altered.


SQL> alter database rename file'/data/CEBPM/onlinelog/o1_mf_3_dm1flmld_.log' to'/data/cebpm/onlinelog/redo03.log';


Database altered.

再次查看:

SQL> select member fromv$logfile;


MEMBER

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

/data/cebpm/onlinelog/redo01.log

/data/cebpm/onlinelog/redo02.log

/data/cebpm/onlinelog/redo03.log


SQL>


13、???????????重定向臨時(shí)文件,方法同上

SQL>select name from v$tempfile;


NAME

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

/data/CEBPM/datafile/o1_mf_temp_dm1fp4bs_.tmp


SQL>

重定向到新的路徑,操作如下:

SQL> alter database rename file '/data/CEBPM/datafile/o1_mf_temp_dm1fp4bs_.tmp'to '/data/cebpm/datafile/temp01.dbf';


Databasealtered.


SQL>

再次查看:

SQL>select name from v$tempfile;


NAME

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

/data/cebpm/datafile/temp01.dbf


SQL>

14、???????????打開數(shù)據(jù)庫

RMAN>?alter database open resetlogs;


database opened

15、???????????驗(yàn)證數(shù)據(jù)

SQL>select * from mytest1;


?????????ID

----------

??????????1

??????????2


SQL>select count(*) from mytest1;


??COUNT(*)

----------

??????????2


如上所知,基于時(shí)間點(diǎn)的異機(jī)恢復(fù)數(shù)據(jù)沒有丟失。

2 RMAN常用命令

備份命令:

RMAN> backup database format '.../%d_%U';?? --備份數(shù)據(jù)庫并指定備份路徑

RMAN> backup database;?? --備份數(shù)據(jù)庫

RMAN> backup database include current controlfile plus archivelog delete allinput;? --備份數(shù)據(jù)文件、控制文件、歸檔日志

RMAN> backup incremental level 0 database;?? --差異增量備份數(shù)據(jù)庫

RMAN> backup incremental level 0 cumulative database;?? --累積增量備份數(shù)據(jù)庫

RMAN> backup as compressed backupset database;?? --壓縮備份數(shù)據(jù)庫

RMAN> backup database include current controlfile;?? --備份數(shù)據(jù)庫并備份控制文件

RMAN> backup tablespace users;?? --備份表空間

RMAN> backup datafile n;?? --備份數(shù)據(jù)文件

RMAN> backup datafiel '/opt/oracle/oradata/orcl/users01.dbf';?? --備份數(shù)據(jù)文件

RMAN> backup current controlfile;?? --備份控制文件

RMAN> backup current controlfile plus archivelog;?? --備份控制文件并歸檔然后備份歸檔日志

RMAN> backup archivelog all;?? --備份歸檔日志

RMAN> backup archivelog all delete all input;?? --備份歸檔日志并刪除

RMAN> backup spfile;?? --備份參數(shù)文件

RMAN> backup backupset all;?? --備份全部備份集

RMAN> backup backupset n;?? --備份指定備份集

還原、恢復(fù)命令:

RMAN> restore database;?? --還原數(shù)據(jù)庫

RMAN> restore tablespace users;?? --還原表空間

RMAN> restore datafile n;?? --還原數(shù)據(jù)文件

RMAN> restore archivelog sequence between 10 and 20;?? --還原歸檔日志

RMAN> restore controlfile from autobackup;?? --還原控制文件

RMAN> restore spfile to '/tmp/spfile.ora' from autobackup;?? --還原參數(shù)文件

RMAN> recover database;?? --恢復(fù)數(shù)據(jù)庫

RMAN> recover tablespace users;?? --恢復(fù)表空間

RMAN> recover datafile n;?? --恢復(fù)數(shù)據(jù)文件

RMAN> restore validate database;????? --驗(yàn)證數(shù)據(jù)庫可恢復(fù)性

RMAN> restore validate controlfile;?? --驗(yàn)證控制文件可恢復(fù)性

RMAN> restore validate spfile;??????? --驗(yàn)證參數(shù)文件可恢復(fù)性

查看備份集命令:

RMAN> list backup;?? --列出數(shù)據(jù)庫中所有的備份集

RMAN> list backup of database;?? --查看數(shù)據(jù)庫備份集

RMAN> list backup of tablespace users;?? --查看表空間備份集

RMAN> list backup of datafile n;?? --查看備份的數(shù)據(jù)文件

RMAN> list backup of controlfile;?? --查看控制文件備份集

RMAN> list backup of archivelog all;?? --查看歸檔日志備份集

RMAN> list archivelog all;?? --查看當(dāng)前所有歸檔日志

RMAN>?list expired backup;?? --列出所有無效備份

管理備份集命令:

RMAN> crosscheck backup;?? --檢查所有備份集

RMAN> crosscheck archivelog all;?? --檢查所有歸檔文件

RMAN> delete [noprompt] obsolete;?? --刪除過期備份

RMAN> delete expired backup;?? --刪除無效備份

RMAN> delete expired archivelog all;? --刪除所有無效歸檔文件

RMAN> delete backupset 1;?? --刪除指定備份

RMAN> delete backup;?? --刪除所有備份

RMAN> change backupset 3 unavailable;?? --更改備份集3為無效

RMAN> change backupset 3 available;???? --更改備份集3為有效

RMAN> change backup of controlfile unavailable;?? --更改控制文件為無效

RMAN> change backup of controlfile available;???? --更改控制文件為有效

RMAN> report schema;?? --查看數(shù)據(jù)庫備份結(jié)構(gòu)

RMAN> report need backup;?? --查看所以需要備份的文件

RMAN> report need backup tablespace system;?? --查看指定表空間是否需要備份

RMAN> report obsolete;?? --查看過期備份


僅供參考

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容