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

RMAN的備份及恢復-丟失所有控制文件

2013-11-13 16:22:30  來源: Oracle 

  數據庫基本信息

  [oracle@standby oracle]$ sqlplus / as sysdba

  SQL*Plus: Release Production on Wed Mar ::

  Copyright (c) Oracle Corporation  All rights reserved

  Connected to:
  Oraclei Enterprise Edition Release Production
  With the Partitioning option
  JServer Release Production

  SQL> select name from v$datafile;

  NAME
  
  /opt/oracle/oradata/primary/systemdbf
  /opt/oracle/oradata/primary/undotbsdbf
  /opt/oracle/oradata/primary/usersdbf

  SQL> archive log list;
  Database log mode        Archive Mode
  Automatic archival       Enabled
  Archive destination      /opt/oracle/oradata/primary/archive
  Oldest online log sequence    
  Next log sequence to archive  
  Current log sequence    
  SQL> select name from v$archived_log;

  NAME
  
  /opt/oracle/oradata/primary/archive/_dbf
  /opt/oracle/oradata/primary/archive/_dbf
  /opt/oracle/oradata/primary/archive/_dbf
  /opt/oracle/oradata/primary/archive/_dbf
  /opt/oracle/oradata/primary/archive/_dbf
  /opt/oracle/oradata/primary/archive/_dbf
  /opt/oracle/oradata/primary/archive/_dbf
  /opt/oracle/oradata/primary/archive/_dbf
  /opt/oracle/oradata/primary/archive/_dbf
  /opt/oracle/oradata/primary/archive/_dbf
  /opt/oracle/oradata/primary/archive/_dbf

  NAME
  
  /opt/oracle/oradata/primary/archive/_dbf
  /opt/oracle/oradata/primary/archive/_dbf
  /opt/oracle/oradata/primary/archive/_dbf
  /opt/oracle/oradata/primary/archive/_dbf

   rows selected

  SQL> select name from v$controlfile;

  NAME
  
  /opt/oracle/oradata/primary/controlctl
  /opt/oracle/oradata/primary/controlctl
  /opt/oracle/oradata/primary/controlctl

  SQL> exit
  Disconnected from Oraclei Enterprise Edition Release Production
  With the Partitioning option
  JServer Release Production

  啟用控制文件的自動備份

  [oracle@standby oracle]$ rman target /

  Recovery Manager: Release Production

  Copyright (c) Oracle Corporation  All rights reserved

  connected to target database: PRIMARY (DBID=)

  RMAN> configure controlfile autobackup on;

  using target database controlfile instead of recovery catalog
  new RMAN configuration parameters:
  CONFIGURE CONTROLFILE AUTOBACKUP ON;
  new RMAN configuration parameters are successfully stored

  RMAN> exit

  Recovery Manager complete

  執行RMAN全備份

  [oracle@standby oracle]$ ls
  g  admin  dictionaryora  initprimaryora  jre  oradata  oraInventory  oui
  [oracle@standby oracle]$ mkdir orabak
  [oracle@standby oracle]$ rman target /

  Recovery Manager: Release Production

  Copyright (c) Oracle Corporation  All rights reserved

  connected to target database: PRIMARY (DBID=)

  RMAN> run {
  > backup database
  > format /opt/oracle/orabak/full_%d_%T_%s
  > plus archivelog
  > format /opt/oracle/orabak/arch_%d_%T_%s
  > delete all input; }

  Starting backup at MAR
  current log archived
  using target database controlfile instead of recovery catalog
  allocated channel: ORA_DISK_
  channel ORA_DISK_: sid= devtype=DISK
  channel ORA_DISK_: starting archive log backupset
  channel ORA_DISK_: specifying archive log(s) in backup set
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  input archive log thread= sequence= recid= stamp=
  channel ORA_DISK_: starting piece at MAR
  channel ORA_DISK_: finished piece at MAR
  piece handle=/opt/oracle/orabak/arch_PRIMARY__ comment=NONE
  channel ORA_DISK_: backup set complete elapsed time: ::
  channel ORA_DISK_: deleting archive log(s)
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  Finished backup at MAR

  Starting backup at MAR
  using channel ORA_DISK_
  channel ORA_DISK_: starting full datafile backupset
  channel ORA_DISK_: specifying datafile(s) in backupset
  input datafile fno= name=/opt/oracle/oradata/primary/systemdbf
  input datafile fno= name=/opt/oracle/oradata/primary/undotbsdbf
  input datafile fno= name=/opt/oracle/oradata/primary/usersdbf
  channel ORA_DISK_: starting piece at MAR
  channel ORA_DISK_: finished piece at MAR
  piece handle=/opt/oracle/orabak/full_PRIMARY__ comment=NONE
  channel ORA_DISK_: backup set complete elapsed time: ::
  Finished backup at MAR

  Starting backup at MAR
  current log archived
  using channel ORA_DISK_
  channel ORA_DISK_: starting archive log backupset
  channel ORA_DISK_: specifying archive log(s) in backup set
  input archive log thread= sequence= recid= stamp=
  channel ORA_DISK_: starting piece at MAR
  channel ORA_DISK_: finished piece at MAR
  piece handle=/opt/oracle/orabak/arch_PRIMARY__ comment=NONE
  channel ORA_DISK_: backup set complete elapsed time: ::
  channel ORA_DISK_: deleting archive log(s)
  archive log filename=/opt/oracle/oradata/primary/archive/_dbf recid= stamp=
  Finished backup at MAR

  Starting Control File and SPFILE Autobackup at MAR
  piece handle=/opt/oracle/product//dbs/c comment=NONE
  Finished Control File and SPFILE Autobackup at MAR

  RMAN> exit

  Recovery Manager complete

  移除所有控制文件及數據文件

  [oracle@standby oracle]$ sqlplus / as sysdba

  SQL*Plus: Release Production on Wed Mar ::

  Copyright (c) Oracle Corporation  All rights reserved

  Connected to:
  Oraclei Enterprise Edition Release Production
  With the Partitioning option
  JServer Release Production

  SQL> shutdown immediate;
  Database closed
  Database dismounted
  ORACLE instance shut down
  SQL> exit
  Disconnected from Oraclei Enterprise Edition Release Production
  With the Partitioning option
  JServer Release Production
  [oracle@standby oracle]$ cd oradata/
  [oracle@standby oradata]$ ls
  primary

  [oracle@standby oradata]$ mv primary/ primarybak
  [oracle@standby oradata]$ mkdir primary
  [oracle@standby oradata]$ ls
  primary  primarybak

  從自動備份中恢復控制文件

  [oracle@standby oradata]$ rman target /

  Recovery Manager: Release Production

  Copyright (c) Oracle Corporation  All rights reserved

  connected to target database (not started)

  RMAN> startup nomount;

  Oracle instance started

  Total System Global Area     bytes

  Fixed Size          bytes
  Variable Size     bytes
  Database Buffers        bytes
  Redo Buffers        bytes

  RMAN> restore controlfile to /opt/oracle/oradata/controlctl from autobackup;

  Starting restore at MAR

  using target database controlfile instead of recovery catalog
  allocated channel: ORA_DISK_
  channel ORA_DISK_: sid= devtype=DISK
  RMAN: ===========================================================
  RMAN: =============== ERROR MESSAGE STACK FOLLOWS ===============
  RMAN: ===========================================================
  RMAN: failure of restore command at // ::
  RMAN: must explicitly specify DBID with SET DBID command

  RMAN> set DBID=

  executing command: SET DBID

  RMAN> restore controlfile to /opt/oracle/oradata/controlctl from autobackup;

  Starting restore at MAR

  using channel ORA_DISK_
  channel ORA_DISK_: looking for autobackup on day:
  channel ORA_DISK_: autobackup found: c
  channel ORA_DISK_: controlfile restore from autobackup complete
  Finished restore at MAR

  RMAN> exit

  Recovery Manager complete

  你可能需要修改spfile文件

  當然如果文件位置等信息沒有變化就無需修改

  [oracle@standby oradata]$ sqlplus / as sysdba

  SQL*Plus: Release Production on Wed Mar ::

  Copyright (c) Oracle Corporation  All rights reserved

  Connected to:
  Oraclei Enterprise Edition Release Production
  With the Partitioning option
  JServer Release Production

  SQL> create pfile from spfile;

  File created

  SQL> !
  [oracle@standby oradata]$ cd $ORACLE_HOME/dbs
  [oracle@standby dbs]$ vi initprimaryora

  *aq_tm_processes=
  *background_dump_dest=/opt/oracle/admin/primary/bdump
  patible=
  ntrol_files=/opt/oracle/oradata/controlctl
  re_dump_dest=/opt/oracle/admin/primary/cdump
  *db_block_size=
  *db_cache_size=
  *db_domain=
  *db_file_multiblock_read_count=
  *db_name=primary
  *fast_start_mttr_target=
  *hash_join_enabled=TRUE
  *instance_name=primary
  *java_pool_size=
  *job_queue_processes=
  *large_pool_size=
  *log_archive_dest_=LOCATION=/opt/oracle/oradata/primary/archive
  *log_archive_format=%t_%sdbf
  *log_archive_start=true
  *open_cursors=
  *pga_aggregate_target=
  *processes=
  *query_rewrite_enabled=FALSE
  *remote_login_passwordfile=EXCLUSIVE
  *resource_manager_plan=SYSTEM_PLAN
  *shared_pool_size=
  *sort_area_size=
  *star_transformation_enabled=FALSE
  *timed_statistics=TRUE
  *undo_management=AUTO
  *undo_retention=
  *undo_tablespace=UNDOTBS
  *user_dump_dest=/opt/oracle/admin/primary/udump
  *utl_file_dir=/opt/oracle
  ~
  ~
  ~
  ~
  ~
  initprimaryora L C written
  [oracle@standby dbs]$ exit
  exit

  SQL> shutdown immediate;
  ORA: database not mounted

  ORACLE instance shut down
  SQL> create spfile from pfile;

  File created

  SQL> startup mount;
  ORACLE instance started

  Total System Global Area  bytes
  Fixed Size       bytes
  Variable Size       bytes
  Database Buffers     bytes
  Redo Buffers     bytes
  Database mounted
  SQL> exit
  Disconnected from Oraclei Enterprise Edition Release Production
  With the Partitioning option
  JServer Release Production

  使用rman進行恢復

  [oracle@standby oradata]$ rman target /

  Recovery Manager: Release Production

  Copyright (c) Oracle Corporation  All rights reserved

  connected to target database: PRIMARY (DBID=)

  RMAN> restore database;

  Starting restore at MAR

  using target database controlfile instead of recovery catalog
  allocated channel: ORA_DISK_
  channel ORA_DISK_: sid= devtype=DISK
  channel ORA_DISK_: starting datafile backupset restore
  channel ORA_DISK_: specifying datafile(s) to restore from backup set
  restoring datafile to /opt/oracle/oradata/primary/systemdbf
  restoring datafile to /opt/oracle/oradata/primary/undotbsdbf
  restoring datafile to /opt/oracle/oradata/primary/usersdbf
  channel ORA_DISK_: restored backup piece
  piece handle=/opt/oracle/orabak/full_PRIMARY__ tag=TAGT params=NULL
  channel ORA_DISK_: restore complete
  Finished restore at MAR

  RMAN> recover database;

  Starting recover at MAR
  using channel ORA_DISK_

  starting media recovery

  channel ORA_DISK_: starting archive log restore to default destination
  channel ORA_DISK_: restoring archive log
  archive log thread= sequence=
  channel ORA_DISK_: restored backup piece
  piece handle=/opt/oracle/orabak/arch_PRIMARY__ tag=TAGT params=NULL
  channel ORA_DISK_: restore complete
  archive log filename=/opt/oracle/oradata/primary/archive_dbf thread= sequence=
  unable to find archive log
  archive log thread= sequence=
  RMAN: ===========================================================
  RMAN: =============== ERROR MESSAGE STACK FOLLOWS ===============
  RMAN: ===========================================================
  RMAN: failure of recover command at // ::
  RMAN: media recovery requesting unknown log: thread scn

  RMAN> alter database open resetlogs;

  database opened

  RMAN>

  至此恢復完成


From:http://tw.wingwit.com/Article/program/Oracle/201311/18221.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.