熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

完整的oracle rman備份恢復的例子

2022-06-13   來源: Oracle 

   建rman庫作為repository
  $more createrman_dbsh
  set echo on
  spool makedblog
  create database rman
  datafile /export/home/oracle/oradata/rman_data/systemdbf size m autoextend
  on next K
  logfile /export/home/oracle/oradata/rman_data/redolog SIZE M
  /export/home/oracle/oradata/rman_data/redolog SIZE M
  maxdatafiles
  maxinstances
  maxlogfiles
  character set USASCII
  national character set USASCII
  ;
  disconnect
  spool off
  exit
  
  @/export/home/oracle//rdbms/admin/catalogsql;
  
  REM ********** ALTER SYSTEM TABLESPACE *********
  ALTER TABLESPACE SYSTEM
  DEFAULT STORAGE ( INITIAL K NEXT K MINEXTENTS MAXEXTENTS UNLIMITED PCTINCR
  EASE );
  ALTER TABLESPACE SYSTEM
  MINIMUM EXTENT K;
  
  REM ********** TABLESPACE FOR ROLLBACK **********
  CREATE TABLESPACE RBS DATAFILE /export/home/oracle/oradata/rman_data/rbsdbf s
  ize m
  AUTOEXTEND ON NEXT K
  MINIMUM EXTENT K
  DEFAULT STORAGE ( INITIAL K NEXT K MINEXTENTS MAXEXTENTS UNLIMITED PC
  TINCREASE );
  
  REM ********** TABLESPACE FOR TEMPORARY **********
  CREATE TABLESPACE TEMP DATAFILE /export/home/oracle/oradata/rman_data/tempdbf
  size m
  AUTOEXTEND ON NEXT K
  MINIMUM EXTENT K
  DEFAULT STORAGE ( INITIAL K NEXT K MINEXTENTS MAXEXTENTS UNLIMITED PCTINCR
  EASE ) TEMPORARY;
  
  REM **** Creating four rollback segments ****************
  CREATE PUBLIC ROLLBACK SEGMENT RBS_ TABLESPACE RBS
  STORAGE ( OPTIMAL K );
  ALTER ROLLBACK SEGMENT RBS_ ONLINE;
  
  
  REM **** SYS and SYSTEM users ****************
  alter user sys temporary tablespace TEMP;
  alter user system temporary tablespace TEMP;
  disconnect
  spool off
  exit
  
  $more createrman_dbsh
  spool crdblog
  @/export/home/oracle//rdbms/admin/catprocsql
  @/export/home/oracle//rdbms/admin/cathssql
  @/export/home/oracle//rdbms/admin/otrcsvrsql
  connect system/manager
  @/export/home/oracle//sqlplus/admin/pupbldsql
  
  disconnect
  spool off
  exit
  
  建repository存放的表空間和rman用戶
  $more createrman_dbsh
  connect internal
  create tablespace rman_ts
  datafile /export/home/oracle/oradata/rman_data/rman_tsdbf
  size M default storage (initial K next K pctincrease );
  create user rman_hainan identified by rman_hainan
  temporary tablespace TEMP
  default tablespace rman_ts quota unlimited on
  rman_ts;
  grant recovery_catalog_owner to rman_hainan;
  grant connect resource to rman_hainan;
  
  建catalog注冊目標數據庫
  $more createrman_dbsh
  rman catalog rman_hainan/rman_hainan@rman msglog=rmanlog
  create catalog ;
  exit;
  rman target sys/oracle@db
  connect catalog rman_hainan/rman_hainan@rman
  register database;
  exit;
  
  可以開始做備份了
  做全備
  $more rmanshell
   /export/home/oracle/profile
  rman rcvcat rman_hainan/rman_hainan@rman target / cmdfile /export/home/oracle/ba
  ckup_levelrcv log /export/home/oracle/backuplog
  
  $more backup_levelrcv
  resync catalog;
  run {
  allocate channel t type disk;
  backup
  incremental level
  skip inaccessible
  tag hot_db_bk_level
  filesperset
  format /export/home/oracle/bk_%s_%p_%tbk
  (database);
  sql alter system archive log current;
  backup
  filesperset
  format /export/home/oracle/a_%s_%p_%tac
  (archivelog all delete input);
  backup
  format /export/home/oracle/df_t%t_s%s_p%pct
  current controlfile ;
  }
  
  做增備
  $more rmanshell
  rman rcvcat rman_hainan/rman_hainan@rman target / cmdfile backup_levelrcv log
  backuplog
  
  $more backup_levelrcv
  resync catalog;
  run {
  allocate channel t type disk;
  backup
  incremental level
  skip inaccessible
  tag hot_db_bk_level
  filesperset
  format bk_%s_%p_%tbk
  (database);
  sql alter system archive log current;
  backup
  filesperset
  format a_%s_%p_%tac
  (archivelog all delete input);
  backup current controlfile;
  }
  
   刪除舊的全備
  $rman rcvcat rman_hainan/rman_hainan@rman target /
  
  Recovery Manager: Release Production
  
  RMAN: connected to target database: TEST (DBID=)
  RMAN: connected to recovery catalog database
  
  RMAN> list backupset;
  
  RMAN: compiling command: list
  
  List of Backup Sets
  Key Recid Stamp LV Set Stamp Set Count Completion Time
  
   JUN
  
  根據key來刪除舊的備份
  
  RMAN> allocate channel for maintenance type disk;
  RMAN> change backupset delete; THIS IS THE COMMAND TO REMOVE THE ENTRY & OS FILE
  
  做完後可以看到list backupset和操作系統的文件都沒有了
  
   恢復
  () 將數據庫啟動到nomount狀態
  $svrmgrl
  
  Oracle Server Manager Release Production
  
  Copyright (c) Oracle Corporation All Rights Reserved
  
  Oraclei Enterprise Edition Release bit Production
  With the Partitioning option
  JServer Release Production
  
  SVRMGR> connect internal
  Connected
  SVRMGR> startup nomount;
  ORACLE instance started
  Total System Global Area bytes
  Fixed Size bytes
  Variable Size bytes
  Database Buffers bytes
  Redo Buffers bytes
  SVRMGR> exit
  Server Manager complete
  () 恢復控制文件
  $rman rcvcat rman_hainan/rman_hainan@rman target /
  
  Recovery Manager: Release Production
  
  RMAN: connected to target database: test (not mounted)
  RMAN: connected to recovery catalog database
  
  RMAN> run {
  > allocate channel d type disk;
  > restore controlfile;
  > release channel d;
  > }
  
  () 恢復數據文件
  
  RMAN> run {
  > allocate channel d type disk;
  > sql alter database mount;
  > restore datafile ;
  > restore datafile ;
  > restore datafile ;
  > restore datafile ;
  > release channel d;
  > }
  
  () 恢復日志文件
  
  RMAN> run {
  > set archivelog destination to /export/home/oracle/admin/test/arch;
  > allocate channel d type disk;
  > restore archivelog all;
  > release channel d;
  > }
  會把所有的日志文件恢復
  
  () 根據日志做recover
  $svrmgrl
  
  Oracle Server Manager Release Production
  
  Copyright (c) Oracle Corporation All Rights Reserved
  
  Oraclei Enterprise Edition Release bit Production
  With the Partitioning option
  JServer Release Production
  
  SVRMGR> connect internal
  Connected
  SVRMGR> recover database using backup controlfile until cancel;
  ORA: change generated at // :: needed for thread
  ORA: suggestion : /export/home/oracle/admin/test
From:http://tw.wingwit.com/Article/program/Oracle/201311/17348.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.