ASM後設資料備份與恢復

sky850623發表於2015-10-07
1.建立一個表空間
SQL> create tablespace asmtbs datafile '+dg1';
Tablespace created.
沒有指定大小,預設建立100m.
SQL> select * from v$dbfile;
     FILE# NAME
---------- ------------------------------------------------------------
         4 /u01/app/oracle/oradata/test/users01.dbf
         3 /u01/app/oracle/oradata/test/sysaux01.dbf
         2 /u01/app/oracle/oradata/test/undotbs01.dbf
         1 /u01/app/oracle/oradata/test/system01.dbf
         5 /u01/app/oracle/oradata/test/test01.dbf
         6 /u01/app/oracle/oradata/test/mgmt.dbf
         7 /u01/app/oracle/oradata/test/mgmt_ecm_depot1.dbf
         8 +DG1/test/datafile/asmtbs.256.891217415
8 rows selected.
2.在表空間建立一張表
SQL> create table t (id number,name varchar2(10)) tablespace asmtbs;
Table created.
SQL> select segment_name,tablespace_name from user_segments where segment_name='T';
SEGMENT_NA TABLESPACE_NAME
---------- ------------------------------
T          ASMTBS
3.備份ASM後設資料
[oracle@ocp ~]$ dd if=/dev/oracleasm/disks/VOL1 of=/home/oracle/vol1.bak bs=4096 count=1
1+0 records in
1+0 records out
4.破壞ASM後設資料
[oracle@ocp ~]$ dd if=/dev/zero of=/dev/oracleasm/disks/VOL1 bs=4096 count=1
1+0 records in
1+0 records out
[oracle@ocp ~]$ kfed read /dev/oracleasm/disks/VOL1  --後設資料被破壞
kfbh.endian:                          0 ; 0x000: 0x00
kfbh.hard:                            0 ; 0x001: 0x00
kfbh.type:                            0 ; 0x002: KFBTYP_INVALID
kfbh.datfmt:                          0 ; 0x003: 0x00
kfbh.block.blk:                       0 ; 0x004: T=0 NUMB=0x0
kfbh.block.obj:                       0 ; 0x008: TYPE=0x0 NUMB=0x0
kfbh.check:                           0 ; 0x00c: 0x00000000
kfbh.fcn.base:                        0 ; 0x010: 0x00000000
kfbh.fcn.wrap:                        0 ; 0x014: 0x00000000
kfbh.spare1:                          0 ; 0x018: 0x00000000
kfbh.spare2:                          0 ; 0x01c: 0x00000000
5.插入資料
SQL> select * from t;
no rows selected

SQL> insert into t values(1,'a');  
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t;
        ID NAME
---------- ------------------------------------------------------------
         1 a
6.關閉資料庫例項和ASM例項
SQL> select status from v$instance;
STATUS
------------
OPEN
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> select status from v$instance;
STATUS
------------
STARTED
SQL> shutdown immediate;   --關閉ASM例項
ASM diskgroups dismounted
ASM instance shutdown
SQL> startup  --啟動ASM例項
ASM instance started

Total System Global Area   83886080 bytes
Fixed Size                  1217836 bytes
Variable Size              57502420 bytes
ASM Cache                  25165824 bytes
ORA-15110: no diskgroups mounted
SQL> alter diskgroup dg1 mount;  --掛載磁碟組
alter diskgroup dg1 mount
*
ERROR at line 1:
ORA-15032: not all alterations performed
ORA-15063: ASM discovered an insufficient number of disks for diskgroup "DG1"

7.恢復
[oracle@ocp ~]$ dd if=/home/oracle/vol1.bak of=/dev/oracleasm/disks/VOL1 bs=4096 count=1
1+0 records in
1+0 records out
SQL> alter diskgroup dg1 mount;   --磁碟組mount成功
Diskgroup altered.
SQL> startup 
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  1218992 bytes
Variable Size             117442128 bytes
Database Buffers          163577856 bytes
Redo Buffers                2973696 bytes
Database mounted.
Database opened.
資料庫也能正常啟動

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

相關文章