[20160923]取出備份集的archivelog檔案.txt

lfree發表於2016-09-27

[20160923]取出備份集的archivelog檔案.txt

--這個測試來源1次幫別人解決問題時遇到的情況,當時需要使用logminer分析archivelog檔案,因為要求對方把archivelog拿過來在我
--的電腦分析。前提是要使用 EXECUTE DBMS_LOGMNR_D.BUILD(OPTIONS=> DBMS_LOGMNR_D.STORE_IN_REDO_LOGS); 生成資料字典檔案在
--歸檔日誌中,可以參考我以前寫的blog,連結:
http://blog.itpub.net/267265/viewspace-1360796/ =>  [20141208]使用logminer看遠端歸檔檔案.txt
http://blog.itpub.net/267265/viewspace-1362767/ =>  [20141210]使用logminer看遠端歸檔檔案補充

--結果對方使用rman把需要的archive備份傳了過來,當時要在我的電腦取出archivelog有點急,請求對方一個檔案(壓縮)傳給我,
--這樣解決問題。今天有空,看看如果使用備份集是archivelog,在別的機器如何取出。

1.環境:
SCOTT@book> @ &r/ver1

PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

--//建立archivelog的備份。
RMAN> backup archivelog all format '/u01/backup/archive_%U';
Starting backup at 2016-09-23 10:52:27
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=6 RECID=2 STAMP=923304579
input archived log thread=1 sequence=7 RECID=3 STAMP=923309427
input archived log thread=1 sequence=8 RECID=4 STAMP=923309458
input archived log thread=1 sequence=9 RECID=5 STAMP=923309467
input archived log thread=1 sequence=10 RECID=6 STAMP=923309547
channel ORA_DISK_1: starting piece 1 at 2016-09-23 10:52:27
channel ORA_DISK_1: finished piece 1 at 2016-09-23 10:52:28
piece handle=/u01/backup/archive_03rgh5fb_1_1 tag=TAG20160923T105227 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-09-23 10:52:28

$ cd /u01/app/oracle/archivelog/book
$ ls -l
total 46464
-rw-r----- 1 oracle oinstall     1024 2016-09-23 10:52:27 1_10_896605872.dbf
-rw-r----- 1 oracle oinstall 11609600 2016-09-23 09:29:39 1_6_896605872.dbf
-rw-r----- 1 oracle oinstall 35895808 2016-09-23 10:50:27 1_7_896605872.dbf
-rw-r----- 1 oracle oinstall     2048 2016-09-23 10:50:58 1_8_896605872.dbf
-rw-r----- 1 oracle oinstall     1536 2016-09-23 10:51:07 1_9_896605872.dbf

2.測試是否可以取出:
--在家裡的機器是否可以取出裡面的檔案archivelog。
SYS@test> @ ver1
PORT_STRING                    VERSION        BANNER                                                                               CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0           12.1.0.1.0     Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

RMAN> catalog start with 'd:\temp\dd\archive_03rgh5fb_1_1';
using target database control file instead of recovery catalog
searching for all files that match the pattern d:\temp\dd\archive_03rgh5fb_1_1

List of Files Unknown to the Database
=====================================
File Name: D:\TEMP\DD\archive_03rgh5fb_1_1

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
no files cataloged

List of Files Which Were Not Cataloged
=======================================
File Name: D:\TEMP\DD\archive_03rgh5fb_1_1
  RMAN-07518: Reason: Foreign database file DBID: 1337401710  Database Name: BOOK
--資料庫不同。dbid也不一樣,不行catalog。
--如何取出裡面的archivelog呢?

--編寫指令碼,實際上這個指令碼就是安裝建立資料庫的指令碼改了一下。
--可以參考連結http://blog.itpub.net/267265/viewspace-2036568/=>[20160304]奇怪的回滾段2.txt

set verify off;
set echo off;
set serveroutput on;
select TO_CHAR(systimestamp,'YYYYMMDD HH24:MI:SS') from dual;
variable devicename varchar2(255);
declare
omfname varchar2(512) := NULL;
  done boolean;
  begin
    dbms_output.put_line(' ');
    dbms_output.put_line(' Allocating device.... ');
    dbms_output.put_line(' Specifying datafiles... ');
        :devicename := dbms_backup_restore.deviceAllocate;
    dbms_output.put_line(' Specifing datafiles... ');
--  dbms_backup_restore.restoreSetDataFile;
--  dbms_backup_restore.restoreDataFileTo(1, '/tmp/system01.dbf', 0, 'SYSTEM');

    dbms_backup_restore.restoresetarchivedlog(DESTINATION=>'d:/temp/dd');
    dbms_backup_restore.restorearchivedlog(1, 6);
    dbms_backup_restore.restorearchivedlog(1, 7);
    dbms_backup_restore.restorearchivedlog(1, 8);
    dbms_backup_restore.restorearchivedlog(1, 9);
    dbms_backup_restore.restorearchivedlog(1, 10);

    dbms_output.put_line(' Restoring ... ');
    dbms_backup_restore.restoreBackupPiece('d:/temp/dd/archive_03rgh5fb_1_1', done);
    if done then
        dbms_output.put_line(' Restore done.');
    else
        dbms_output.put_line(' ORA-XXXX: Restore failed');
    end if;
    dbms_backup_restore.deviceDeallocate;
  end;
/

--//執行如上指令碼:
SYS@test> @ arch.rman

TO_CHARSYSTIMEST
-----------------
20160926 22:36:37
Allocating device....
Specifying datafiles...
Specifing datafiles...
Restoring ...
Restore done.
PL/SQL procedure successfully completed.

D:\temp\dd>ls -l ARC00*
-rw-rw-rw-   1 user     group    11609600 Sep 26 22:36 ARC0000000006_0896605872.0001
-rw-rw-rw-   1 user     group    35895808 Sep 26 22:36 ARC0000000007_0896605872.0001
-rw-rw-rw-   1 user     group        2048 Sep 26 22:36 ARC0000000008_0896605872.0001
-rw-rw-rw-   1 user     group        1536 Sep 26 22:36 ARC0000000009_0896605872.0001
-rw-rw-rw-   1 user     group        1024 Sep 26 22:36 ARC0000000010_0896605872.0001
--//對比前面的大小一致。

D:\temp\dd>md5sum ARC0*
101233b20bad9ffdd99d2cde051e2221 *ARC0000000006_0896605872.0001
20f1efbb275f3a93a1eab15240378cfb *ARC0000000007_0896605872.0001
31462ea8a684aa3efc866378c5139a78 *ARC0000000008_0896605872.0001
4c269d8acdfef4769cb808fdc903c9d3 *ARC0000000009_0896605872.0001
816b32f56304990da2edf645a1262491 *ARC0000000010_0896605872.0001

--明天到單位驗證md5s是否正確。
$ md5sum 1_[6-9]_896605872.dbf 1_10_896605872.dbf
bfe41590af10ae5520a4811dc7844349  1_6_896605872.dbf
56efdee679fe4e874fbf75dd7f86a9c7  1_7_896605872.dbf
c380653ceb6403a6fd6567cedfa6ba7d  1_8_896605872.dbf
35841b9b849013e03c62444b0bba9fa4  1_9_896605872.dbf
64533fca9548442ed46de84ad317c1f9  1_10_896605872.dbf
--奇怪md5sum不一致,為什麼?

$ xxd -c32 1_10_896605872.dbf >|w.txt
$ xxd -c32 ARC0000000010_0896605872.0001>|l.txt
$ diff -Nur w.txt l.txt
--- w.txt       2016-09-27 08:22:54.000000000 +0800
+++ l.txt       2016-09-27 08:23:23.000000000 +0800
@@ -1,5 +1,5 @@
-0000000: 0022 0000 0000 c0ff 0000 0000 0000 0000 6758 0000 0002 0000 0100 0000 7d7c 7b7a  ."....?........gX..........}|{z
-0000020: a081 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000  ................................
+0000000: 0022 0000 0000 c0ff 0000 0000 0000 0000 c7d9 0000 0002 0000 0100 0000 7d7c 7b7a  ."....?........琴..........}|{z
                                                  ~~~~~
+0000020: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000  ................................
0000040: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000  ................................
0000060: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000  ................................
0000080: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000  ................................

--僅僅第17,18位元組不一致。這個很像資料檔案的OS頭部(因為出現7d 7c 7b 7a)。也許跟os版本有關。我取出archivelog的版本是
--oracle 12c for windows。
--先暫時放棄。

 

--補充測試,下午想一下,看看是否可以catalog看看。

RMAN> catalog start with '/u01/backup/ARC0000000010_0896605872.0001';

using target database control file instead of recovery catalog
searching for all files that match the pattern /u01/backup/ARC0000000010_0896605872.0001

List of Files Unknown to the Database
=====================================
File Name: /u01/backup/ARC0000000010_0896605872.0001

Do you really want to catalog the above files (enter YES or NO)? YES
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/backup/ARC0000000010_0896605872.0001


RMAN> list archivelog all ;

List of Archived Log Copies for database with db_unique_name BOOK
=====================================================================

Key     Thrd Seq     S Low Time
------- ---- ------- - -------------------
2       1    6       A 2016-08-17 11:03:10
        Name: /u01/app/oracle/archivelog/book/1_6_896605872.dbf

3       1    7       A 2016-09-23 09:29:38
        Name: /u01/app/oracle/archivelog/book/1_7_896605872.dbf

4       1    8       A 2016-09-23 10:50:27
        Name: /u01/app/oracle/archivelog/book/1_8_896605872.dbf

5       1    9       A 2016-09-23 10:50:58
        Name: /u01/app/oracle/archivelog/book/1_9_896605872.dbf

11      1    10      A 2016-09-23 10:51:07
        Name: /u01/backup/ARC0000000010_0896605872.0001

10      1    10      A 2016-09-23 10:51:07
        Name: /u01/backup/1_10_896605872.dbf

6       1    10      A 2016-09-23 10:51:07
        Name: /u01/app/oracle/archivelog/book/1_10_896605872.dbf

7       1    11      A 2016-09-23 10:52:27
        Name: /u01/app/oracle/archivelog/book/1_11_896605872.dbf

8       1    12      A 2016-09-24 09:00:52
        Name: /u01/app/oracle/archivelog/book/1_12_896605872.dbf

9       1    13      A 2016-09-25 14:00:39
        Name: /u01/app/oracle/archivelog/book/1_13_896605872.dbf

--說明這樣沒有問題的。

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

相關文章