使用RMAN備份與恢復數據庫(5)——表空間的備份與恢復

使用RMAN備份與恢復數據庫(5)——表空間的備份與恢復

一、使用RMAN備份表空間

1、備份表空間

RMAN> backup as compressed backupset tablespace data01 format '/home/oracle/rmanbak/ts_%d_%I_%s_%p_%T';

Starting backup at 2020-04-09 19:35:35
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=9 device type=DISK
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/usr/local/oradata/orcl/data01.dbf
channel ORA_DISK_1: starting piece 1 at 2020-04-09 19:35:36
channel ORA_DISK_1: finished piece 1 at 2020-04-09 19:35:37
piece handle=/home/oracle/rmanbak/ts_ORCL_1559168802_71_1_20200409 tag=TAG20200409T193536 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2020-04-09 19:35:37

2、查看錶空間備份信息

RMAN> list backup of tablespace data01;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
44      Full    17.80M     DISK        00:00:01     2020-04-09 18:17:19
        BP Key: 73   Status: AVAILABLE  Compressed: NO  Tag: TAG20200409T181718
        Piece Name: /home/oracle/rmanbak/data_ORCL_67_1_20200409
  List of Datafiles in backup set 44
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  5       Full 1655355    2020-04-09 18:17:18 /usr/local/oradata/orcl/data01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
45      Full    17.88M     DISK        00:00:03     2020-04-09 18:22:06
  List of Datafiles in backup set 45
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  5       Full 1655504    2020-04-09 18:22:03 /usr/local/oradata/orcl/data01.dbf

  Backup Set Copy #1 of backup set 45
  Device Type Elapsed Time Completion Time     Compressed Tag
  ----------- ------------ ------------------- ---------- ---
  DISK        00:00:03     2020-04-09 18:22:06 NO         TAG20200409T182203

    List of Backup Pieces for backup set 45 Copy #1
    BP Key  Pc# Status      Piece Name
    ------- --- ----------- ----------
    74      1   AVAILABLE   /home/oracle/rmanbak/ORCL_data_68_1_20200409
    75      2   AVAILABLE   /home/oracle/rmanbak/ORCL_data_68_2_20200409
    76      3   AVAILABLE   /home/oracle/rmanbak/ORCL_data_68_3_20200409
    77      4   AVAILABLE   /home/oracle/rmanbak/ORCL_data_68_4_20200409

BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
48      Full    3.26M      DISK        00:00:01     2020-04-09 19:35:37
        BP Key: 80   Status: AVAILABLE  Compressed: YES  Tag: TAG20200409T193536
        Piece Name: /home/oracle/rmanbak/ts_ORCL_1559168802_71_1_20200409
  List of Datafiles in backup set 48
  File LV Type Ckp SCN    Ckp Time            Name
  ---- -- ---- ---------- ------------------- ----
  5       Full 1718676    2020-04-09 19:35:36 /usr/local/oradata/orcl/data01.dbf

二、使用RMAN恢復表空間

1、修改數據

登錄scott,修改t1表的數據:

SQL> connect scott/tiger
Connected.
SQL> select * from t1;

	ID NAME
---------- --------------------
	 1 Jack
       333 Jerry
       444 John
	 2 Tome

Elapsed: 00:00:00.02
SQL> delete t1 where id>2;

2 rows deleted.

Elapsed: 00:00:00.04
SQL> commit;

Commit complete.

Elapsed: 00:00:00.01
SQL> select * from t1;

	ID NAME
---------- --------------------
	 1 Jack
	 2 Tome

2、刪除data01表空間對應的數據文件

刪除數據文件之後,數據庫無法啓動:

SQL> host rm /usr/local/oradata/orcl/data01.dbf

SQL> startup force;
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size		    2220200 bytes
Variable Size		  482348888 bytes
Database Buffers	  578813952 bytes
Redo Buffers		    5554176 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 5 - see DBWR trace file
ORA-01110: data file 5: '/usr/local/oradata/orcl/data01.dbf'

3、利用RMAN恢復表空間

RMAN> 

run {
    restore tablespace data01;
    recover tablespace data01;
    alter database open;
}

Starting restore at 2020-04-09 19:50:22
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00005 to /usr/local/oradata/orcl/data01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/ts_ORCL_1559168802_71_1_20200409
channel ORA_DISK_1: piece handle=/home/oracle/rmanbak/ts_ORCL_1559168802_71_1_20200409 tag=TAG20200409T193536
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 2020-04-09 19:50:26

Starting recover at 2020-04-09 19:50:26
using channel ORA_DISK_1

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

Finished recover at 2020-04-09 19:50:27

database opened

4、查看數據

SQL> connect scott/tiger
Connected.
SQL> select * from t1;

	ID NAME
---------- --------------------
	 1 Jack
	 2 Tome
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章