rman初步簡單使用
1、確保數據庫在archive(歸檔)模式
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Enabled
Archive destination /u01/oradata/general/archive
Oldest online log sequence 13
Current log sequence 15
SQL>
修改成歸檔模式:
SQL> startup mount;
修改成歸檔模式:
SQL> startup mount;
SQL> alter database archivelog;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/oradata/general/archive
Oldest online log sequence 13
Next log sequence to archive 15
Current log sequence 15
SQL>
</div>2、確保環境變量(即稍后運行的rman命令是Oracle的命令)
[oracle@linuxForOra general10g]$ echo $PATH
/u01/oracle/oracle/product/10.2.0/db_1/bin:/usr/java/jdk1.6.0_18/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/NX/bin:/u01/oracle//bin:/usr/NX/bin:/usr/NX/bin:/usr/NX/bin
[oracle@linuxForOra general10g]$
</div>即oracle的目錄位置在環境變量的前面就可以了,否則可能就是執行的操作系統的命令,如果需要修改
,將Oracle的bin目錄放到環境變量前面即可
3、進入rman環境進行備份
</div></div>
,將Oracle的bin目錄放到環境變量前面即可
3、進入rman環境進行備份
[oracle@linuxForOra ~]$ rman nocatalog
Recovery Manager: Release 9.2.0.4.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
RMAN> connect target /
connected to target database: GENERAL (DBID=1855318131)
using target database controlfile instead of recovery catalog
RMAN> list backupset;
RMAN> backup database;
Starting backup at 02-SEP-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=13 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current SPFILE in backupset
including current controlfile in backupset
input datafile fno=00001 name=/u01/oradata/general/system01.dbf
input datafile fno=00002 name=/u01/oradata/general/undotbs01.dbf
input datafile fno=00011 name=/u01/oradata/general/COMMONSPACE.dbf
input datafile fno=00005 name=/u01/oradata/general/example01.dbf
input datafile fno=00010 name=/u01/oradata/general/xdb01.dbf
input datafile fno=00006 name=/u01/oradata/general/indx01.dbf
input datafile fno=00009 name=/u01/oradata/general/users01.dbf
input datafile fno=00003 name=/u01/oradata/general/cwmlite01.dbf
input datafile fno=00004 name=/u01/oradata/general/drsys01.dbf
input datafile fno=00007 name=/u01/oradata/general/odm01.dbf
input datafile fno=00008 name=/u01/oradata/general/tools01.dbf
channel ORA_DISK_1: starting piece 1 at 02-SEP-11
channel ORA_DISK_1: finished piece 1 at 02-SEP-11
piece handle=/u01/oracle/dbs/01mlhfp6_1_1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:26
Finished backup at 02-SEP-11(說明備份成功)
RMAN> list backupset;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1 Full 778M DISK 00:01:21 02-SEP-11
BP Key: 1 Status: AVAILABLE Tag: TAG20110902T104702
Piece Name: /u01/oracle/dbs/01mlhfp6_1_1
SPFILE Included: Modification time: 24-SEP-10
List of Datafiles in backup set 1
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 811809 02-SEP-11 /u01/oradata/general/system01.dbf
2 Full 811809 02-SEP-11 /u01/oradata/general/undotbs01.dbf
3 Full 811809 02-SEP-11 /u01/oradata/general/cwmlite01.dbf
4 Full 811809 02-SEP-11 /u01/oradata/general/drsys01.dbf
5 Full 811809 02-SEP-11 /u01/oradata/general/example01.dbf
6 Full 811809 02-SEP-11 /u01/oradata/general/indx01.dbf
7 Full 811809 02-SEP-11 /u01/oradata/general/odm01.dbf
8 Full 811809 02-SEP-11 /u01/oradata/general/tools01.dbf
9 Full 811809 02-SEP-11 /u01/oradata/general/users01.dbf
10 Full 811809 02-SEP-11 /u01/oradata/general/xdb01.dbf
11 Full 811809 02-SEP-11 /u01/oradata/general/COMMONSPACE.dbf
RMAN>
4、為了模擬rman的恢復操作,首先刪除剛才的演示備份操作
4、為了模擬rman的恢復操作,首先刪除剛才的演示備份操作
(1)、查看已有的備份集的信息
RMAN> crosscheck backup;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=17 devtype=DISK
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/u01/oracle/dbs/01mlhfp6_1_1 recid=1 stamp=760790823
Crosschecked 1 objects
(2)、刪除所有的備份集
RMAN> delete backup;
using channel ORA_DISK_1
List of Backup Pieces
BP Key BS Key Pc# Cp# Status Device Type Piece Name
------- ------- --- --- ----------- ----------- ----------
1 1 1 1 AVAILABLE DISK /u01/oracle/dbs/01mlhfp6_1_1
Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/u01/oracle/dbs/01mlhfp6_1_1 recid=1 stamp=760790823
Deleted 1 objects
(3)、查看已有的鏡像備份
RMAN> crosscheck copy;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=17 devtype=DISK
validation succeeded for archived log
archive log filename=/u01/oradata/general/archive/1_10.dbf recid=1 stamp=732901799
validation succeeded for archived log
archive log filename=/u01/oradata/general/archive/1_11.dbf recid=2 stamp=741876225
validation succeeded for archived log
archive log filename=/u01/oradata/general/archive/1_12.dbf recid=3 stamp=743094932
validation succeeded for archived log
archive log filename=/u01/oradata/general/archive/1_13.dbf recid=4 stamp=760111347
validation succeeded for archived log
archive log filename=/u01/oradata/general/archive/1_14.dbf recid=5 stamp=760789488
Crosschecked 5 objects
(4)、刪除所有的鏡像備份
RMAN> delete copy;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=17 devtype=DISK
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - --------- ----
1 1 10 A 24-SEP-10 /u01/oradata/general/archive/1_10.dbf
2 1 11 A 20-OCT-10 /u01/oradata/general/archive/1_11.dbf
3 1 12 A 31-JAN-11 /u01/oradata/general/archive/1_12.dbf
4 1 13 A 14-FEB-11 /u01/oradata/general/archive/1_13.dbf
5 1 14 A 25-AUG-11 /u01/oradata/general/archive/1_14.dbf
Do you really want to delete the above objects (enter YES or NO)? yes
deleted archive log
archive log filename=/u01/oradata/general/archive/1_10.dbf recid=1 stamp=732901799
deleted archive log
archive log filename=/u01/oradata/general/archive/1_11.dbf recid=2 stamp=741876225
deleted archive log
archive log filename=/u01/oradata/general/archive/1_12.dbf recid=3 stamp=743094932
deleted archive log
archive log filename=/u01/oradata/general/archive/1_13.dbf recid=4 stamp=760111347
deleted archive log
archive log filename=/u01/oradata/general/archive/1_14.dbf recid=5 stamp=760789488
Deleted 5 objects
(5)、通過下面的命令查出已經不存在rman備份了
RMAN> list backupset;
RMAN> list copy;
specification does not match any archive log in the recovery catalog
RMAN>
</div></div></div>5、模擬刪除數據后的rman恢復
(1)、在自己創建的表空間COMMONSPACE上創建表rmantest,并插入3條數據
sesese色
(1)、在自己創建的表空間COMMONSPACE上創建表rmantest,并插入3條數據
SQL> select segment_name,tablespace_name from user_segments where segment_name='RMANTEST';
SEGMENT_NAME TABLESPACE_NAME
------------------------------ ------------------------------
RMANTEST COMMONSPACE
SQL> select * from rmantest;
A
----------
11
12
13
SQL>
</div></div>(2)、使用rman進行備份
[oracle@linuxForOra ~]$ rman nocatalog
Recovery Manager: Release 9.2.0.4.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
RMAN> connect target /
connected to target database: GENERAL (DBID=1855318131)
using target database controlfile instead of recovery catalog
RMAN> list backupset;
RMAN> list copy;
specification does not match any archive log in the recovery catalog
RMAN> backup database;
Starting backup at 02-SEP-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=18 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current SPFILE in backupset
including current controlfile in backupset
input datafile fno=00001 name=/u01/oradata/general/system01.dbf
input datafile fno=00002 name=/u01/oradata/general/undotbs01.dbf
input datafile fno=00011 name=/u01/oradata/general/COMMONSPACE.dbf
input datafile fno=00005 name=/u01/oradata/general/example01.dbf
input datafile fno=00010 name=/u01/oradata/general/xdb01.dbf
input datafile fno=00006 name=/u01/oradata/general/indx01.dbf
input datafile fno=00009 name=/u01/oradata/general/users01.dbf
input datafile fno=00003 name=/u01/oradata/general/cwmlite01.dbf
input datafile fno=00004 name=/u01/oradata/general/drsys01.dbf
input datafile fno=00007 name=/u01/oradata/general/odm01.dbf
input datafile fno=00008 name=/u01/oradata/general/tools01.dbf
channel ORA_DISK_1: starting piece 1 at 02-SEP-11
channel ORA_DISK_1: finished piece 1 at 02-SEP-11
piece handle=/u01/oracle/dbs/02mlhike_1_1 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:26
Finished backup at 02-SEP-11
RMAN> quit
</div>(3)、關閉數據庫(shutdown immediate),然后刪除文件
[oracle@linuxForOra general]$ rm COMMONSPACE.dbf
</div>(4)、啟動到mount狀態,開始使用rman進行恢復
SQL> startup mount;
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
SQL>
[oracle@linuxForOra general]$ rman nocatalog
Recovery Manager: Release 9.2.0.4.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
RMAN> connect target /
connected to target database: GENERAL (DBID=1855318131)
using target database controlfile instead of recovery catalog
RMAN> restore database;
Starting restore at 02-SEP-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=13 devtype=DISK
skipping datafile 1; already restored to file /u01/oradata/general/system01.dbf
skipping datafile 2; already restored to file /u01/oradata/general/undotbs01.dbf
skipping datafile 3; already restored to file /u01/oradata/general/cwmlite01.dbf
skipping datafile 4; already restored to file /u01/oradata/general/drsys01.dbf
skipping datafile 5; already restored to file /u01/oradata/general/example01.dbf
skipping datafile 6; already restored to file /u01/oradata/general/indx01.dbf
skipping datafile 7; already restored to file /u01/oradata/general/odm01.dbf
skipping datafile 8; already restored to file /u01/oradata/general/tools01.dbf
skipping datafile 9; already restored to file /u01/oradata/general/users01.dbf
skipping datafile 10; already restored to file /u01/oradata/general/xdb01.dbf
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00011 to /u01/oradata/general/COMMONSPACE.dbf
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/oracle/dbs/02mlhike_1_1 tag=TAG20110902T113542 params=NULL
channel ORA_DISK_1: restore complete
Finished restore at 02-SEP-11
recover database之后才能打開數據庫
RMAN> recover database;
Starting recover at 02-SEP-11
using channel ORA_DISK_1
starting media recovery
media recovery complete
Finished recover at 02-SEP-11
RMAN> exit
Recovery Manager complete.
</div></div>SQL> select open_mode from v$database;
OPEN_MODE
----------
MOUNTED
SQL> alter database open;
Database altered.
SQL> select * from rmantest;
A
----------
11
12
13
</div>到此為止,恢復完畢!
6、rman原理簡單分析
rman 備份是針對塊一級的,支持增量備份。
Rman備份并不需要將數據庫或者表空間置于backup狀態,但是它會把scn記錄在catalog中對應你的backupset
準備在恢復的時候來使用。
對users表空間做一個完全備份
$ rman target sys/oracle nocatalog
RMAN>; run {
2>; allocate channel d1 type disk;
3>; backup
4>; format='/u03/oraclebk/%d_%N_%s.bk' tablespace users;
5>; release channel d1;
6>; }
看一下備份集里都有什么,注意看Ckp SCN 546792,
RMAN>; list backup of tablespace users;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3 Full 1M DISK 00:00:02 31-MAR-05
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20050331T153729
Piece Name: /u03/oraclebk/SALES_USERS_4.bk
List of Datafiles in backup set 3
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 546792 31-MAR-05 /u02/oradata/sales/users01.dbf
恢復的時候應用546792開始到現在的歸檔日志和重做日志.
rman的增量備份的基本原理
其實原理很簡單,主要就是弄明白怎么樣在做增量備份時確定某個數據塊需要備份,哪個不需要
rman在做1級備份的時候怎么來確定0級備份之后都有哪些數據塊做了修改呢?看下面一段
Each data block in a datafile contains a system change number (SCN), which is the
SCN at which the most recent change was made to the block. During an incremental
backup, RMAN reads the SCN of each data block in the input file and compares it to
the checkpoint SCN of the parent incremental backup. If the SCN in the input data
block is greater than or equal to the checkpoint SCN of the parent, then RMAN copies
the block.
原來block里邊也有一個change scn
也就是說在做level 1級備份的時候,需要掃描所有的數據塊并且用塊中記錄修改的SCN跟level 0備份時的SCN做比較(備份記錄中的Ckp SCN),來確定這個塊是否需要備份。
所以掃描整個數據文件是不可避免的 !
這是傳統的rman做增量備份
在10g中rman做增量備份不再需要掃描整個數據文件了
10g引入的新特性 block change tracking:
Block change tracking進程記錄自從上一次備份以來數據塊的變化,并把這些信息記錄在跟蹤文件中。RMAN使用這個文件判斷增量備份中需要備份的變更數據。這極大的促進了備份性能,RMAN可以不再掃描整個文件以查找變更數據。
RMAN's change tracking feature for incremental backups improves incremental
backup performance by recording changed blocks in each datafile in a change tracking
file. If change tracking is enabled, RMAN uses the change tracking file to identify
changed blocks for incremental backup, thus avoiding the need to scan every block in
the datafile.
估計是使用的位圖文件做的記錄!
有興趣的可以看看dump的數據塊
通過下面的查詢找一個表對應的數據塊
SQL>; select file_id,block_id,blocks
2 from dba_extents
3 where segment_name='EMPLOYEES';
FILE_ID BLOCK_ID BLOCKS
---------- ---------- ----------
5 81 8
dump一個塊到udump的trc文件
SQL>; alter system dump datafile 5 block 81;
System altered.
在udump目錄找到對應的trc文件,找到dump那段
Start dump data blocks tsn: 6 file#: 5 minblk 81 maxblk 81
buffer tsn: 6 rdba: 0x01400051 (5/81)
scn: 0x0000.00086c4d seq: 0x01 flg: 0x04 tail: 0x4b502001
后面省略了
scn: 0x0000.00086c4d是16進制你可以換算過來552013
你可以嘗試做一下修改,不過一定要保證對應的塊被修改了,并且被寫了,才能反映出來。
rman 備份是針對塊一級的,支持增量備份。
Rman備份并不需要將數據庫或者表空間置于backup狀態,但是它會把scn記錄在catalog中對應你的backupset
準備在恢復的時候來使用。
對users表空間做一個完全備份
$ rman target sys/oracle nocatalog
RMAN>; run {
2>; allocate channel d1 type disk;
3>; backup
4>; format='/u03/oraclebk/%d_%N_%s.bk' tablespace users;
5>; release channel d1;
6>; }
看一下備份集里都有什么,注意看Ckp SCN 546792,
RMAN>; list backup of tablespace users;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3 Full 1M DISK 00:00:02 31-MAR-05
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20050331T153729
Piece Name: /u03/oraclebk/SALES_USERS_4.bk
List of Datafiles in backup set 3
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 546792 31-MAR-05 /u02/oradata/sales/users01.dbf
恢復的時候應用546792開始到現在的歸檔日志和重做日志.
rman的增量備份的基本原理
其實原理很簡單,主要就是弄明白怎么樣在做增量備份時確定某個數據塊需要備份,哪個不需要
rman在做1級備份的時候怎么來確定0級備份之后都有哪些數據塊做了修改呢?看下面一段
Each data block in a datafile contains a system change number (SCN), which is the
SCN at which the most recent change was made to the block. During an incremental
backup, RMAN reads the SCN of each data block in the input file and compares it to
the checkpoint SCN of the parent incremental backup. If the SCN in the input data
block is greater than or equal to the checkpoint SCN of the parent, then RMAN copies
the block.
原來block里邊也有一個change scn
也就是說在做level 1級備份的時候,需要掃描所有的數據塊并且用塊中記錄修改的SCN跟level 0備份時的SCN做比較(備份記錄中的Ckp SCN),來確定這個塊是否需要備份。
所以掃描整個數據文件是不可避免的 !
這是傳統的rman做增量備份
在10g中rman做增量備份不再需要掃描整個數據文件了
10g引入的新特性 block change tracking:
Block change tracking進程記錄自從上一次備份以來數據塊的變化,并把這些信息記錄在跟蹤文件中。RMAN使用這個文件判斷增量備份中需要備份的變更數據。這極大的促進了備份性能,RMAN可以不再掃描整個文件以查找變更數據。
RMAN's change tracking feature for incremental backups improves incremental
backup performance by recording changed blocks in each datafile in a change tracking
file. If change tracking is enabled, RMAN uses the change tracking file to identify
changed blocks for incremental backup, thus avoiding the need to scan every block in
the datafile.
估計是使用的位圖文件做的記錄!
有興趣的可以看看dump的數據塊
通過下面的查詢找一個表對應的數據塊
SQL>; select file_id,block_id,blocks
2 from dba_extents
3 where segment_name='EMPLOYEES';
FILE_ID BLOCK_ID BLOCKS
---------- ---------- ----------
5 81 8
dump一個塊到udump的trc文件
SQL>; alter system dump datafile 5 block 81;
System altered.
在udump目錄找到對應的trc文件,找到dump那段
Start dump data blocks tsn: 6 file#: 5 minblk 81 maxblk 81
buffer tsn: 6 rdba: 0x01400051 (5/81)
scn: 0x0000.00086c4d seq: 0x01 flg: 0x04 tail: 0x4b502001
后面省略了
scn: 0x0000.00086c4d是16進制你可以換算過來552013
你可以嘗試做一下修改,不過一定要保證對應的塊被修改了,并且被寫了,才能反映出來。
本文由用戶 baojian322 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!
推薦閱讀
rman初步簡單使用
1、確保數據庫在archive(歸檔)模式 SQL> archive log list; Database log mode ? ? ? ? ? ? ?No Archive Mode Autom...
RMAN-06056: could not access datafile 6解決方法
在使用rman備份的時候遇到的問題:RMAN-06056: could not access datafile 6 RMAN> backup database; Starting backup ...
使用python進行簡單的文本處理
由于有多線程的影響,c++項目打印出來的時間順序不一致,導致不太好在excel中統計,故使用python寫了段腳本來解決之。涉及到如下方面 1. txt文本的讀取,utf8的處理 2. 字符串的...
使用JavaScript將HTML轉化成文本的簡單方法
非常簡單的方法,利用JavaScript來獲取HTML標簽字符串,并去掉標簽。 function strip(html) { var tmp = document.createElement("...