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

利用dbmsbackuprestore恢復數據庫

2022-06-13   來源: Oracle 

  進行測試之前先將數據庫做全備

  引用

  RMAN> run {

  > allocate channel ch device type disk;

  > backup database include current controlfile format /backup/full%t tag=FULLDB;

  > sql alter system archive log current;

  > backup archivelog all format /backup/arch%t tag=ARCHIVELOG;

  > release channel ch;

  > }

  allocated channel: ch

  channel ch: sid= devtype=DISK

  Starting backup at JAN

  channel ch: starting full datafile backupset

  channel ch: specifying datafile(s) in backupset

  including current controlfile in backupset

  input datafile fno= name=/app/oracle/oradata/orai/systemdbf

  input datafile fno= name=/app/oracle/oradata/orai/undotbsdbf

  input datafile fno= name=/app/oracle/oradata/orai/exampledbf

  input datafile fno= name=/app/oracle/oradata/orai/STREAMdbf

  input datafile fno= name=/app/oracle/oradata/orai/xdbdbf

  input datafile fno= name=/app/oracle/oradata/orai/indxdbf

  input datafile fno= name=/app/oracle/oradata/orai/usersdbf

  input datafile fno= name=/app/oracle/oradata/orai/cwmlitedbf

  input datafile fno= name=/app/oracle/oradata/orai/drsysdbf

  input datafile fno= name=/app/oracle/oradata/orai/odmdbf

  input datafile fno= name=/app/oracle/oradata/orai/toolsdbf

  channel ch: starting piece at JAN

  channel ch: finished piece at JAN

  piece handle=/backup/full comment=NONE

  channel ch: backup set complete elapsed time: ::

  Finished backup at JAN

  Starting Control File and SPFILE Autobackup at JAN

  piece handle=/app/oracle/product//dbs/c comment=NONE

  Finished Control File and SPFILE Autobackup at JAN

  sql statement: alter system archive log current

  Starting backup at JAN

  current log archived

  channel ch: starting archive log backupset

  channel ch: 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=

  channel ch: starting piece at JAN

  channel ch: finished piece at JAN

  piece handle=/backup/arch comment=NONE

  channel ch: backup set complete elapsed time: ::

  Finished backup at JAN

  Starting Control File and SPFILE Autobackup at JAN

  piece handle=/app/oracle/product//dbs/c comment=NONE

  Finished Control File and SPFILE Autobackup at JAN

  released channel: ch

  假設現在數據庫異常宕機

  引用

  SQL> shutdown abort

  ORACLE instance shut down

  啟動數據庫至nomount狀態

  引用

  SQL> startup nomount

  ORACLE instance started

  Total System Global Area bytes

  Fixed Size                   bytes

  Variable Size             bytes

  Database Buffers          bytes

  Redo Buffers                 bytes

  利用dbms_backup_restore恢復控制文件

  SQL> DECLARE

    devtype varchar();

    done boolean;

    BEGIN

    devtype := dbms_backup_restoreDeviceAllocate(type => ident => testctl);

    dbms_backup_restoreRestoresetdataFile;

    dbms_backup_restoreRestoreControlFileto(/app/oracle/oradata/orai/controlctl);

    dbms_backup_restoreRestoreBackupPiece(/backup/fulldone => done);

    dbms_backup_restoreRestoresetdataFile;

    dbms_backup_restoreRestoreControlFileto(/app/oracle/oradata/orai/controlctl);

    dbms_backup_restoreRestoreBackupPiece(/backup/fulldone => done);

    dbms_backup_restoreRestoresetdataFile;

    dbms_backup_restoreRestoreControlFileto(/app/oracle/oradata/orai/controlctl);

    dbms_backup_restoreRestoreBackupPiece(/backup/fulldone => done);

    dbms_backup_restoreDeviceDeallocate;

    END;

    /

  PL/SQL procedure successfully completed

  當然也已可用rman進行控制文件恢復

  引用

  RMAN> restore controlfile from /app/oracle/product//dbs/c′;

  Starting restore at JAN

  using channel ORA_DISK_

  channel ORA_DISK_: restoring controlfile

  channel ORA_DISK_: restore complete

  replicating controlfile

  input filename=/app/oracle/oradata/orai/controlctl

  output filename=/app/oracle/oradata/orai/controlctl

  output filename=/app/oracle/oradata/orai/controlctl

  Finished restore at JAN

  利用dbms_backup_restore恢復數據文件

  引用

  SQL> DECLARE

    devtype varchar();

    done boolean;

    BEGIN

    devtype := dbms_backup_restoreDeviceAllocate (type => ident => testdatafile);

    dbms_backup_restoreRestoreSetDatafile;

    dbms_backup_restoreRestoreDatafileTo(dfnumber => toname => /app/oracle/oradata/orai/systemdbf);

    dbms_backup_restoreRestoreDatafileTo(dfnumber => toname => /app/oracle/oradata/orai/undotbsdbf);

    dbms_backup_restoreRestoreBackupPiece(done => donehandle => /backup/full params => null);

    dbms_backup_restoreDeviceDeallocate;

    END;

    /

  PL/SQL procedure successfully completed

  利用dbms_backup_restore恢復歸檔日志

  引用

  SQL> DECLARE

    devtype varchar();

    done boolean;

    BEGIN

    devtype := dbms_backup_restoreDeviceAllocate (type => ident => testarchlog);

    dbms_backup_restoreRestoreSetArchivedLog(destination=>/app/oracle/product//dbs/arch);

    dbms_backup_restoreRestoreArchivedLog(thread=>sequence=>);

    dbms_backup_restoreRestoreArchivedLog(thread=>sequence=>);

    dbms_backup_restoreRestoreArchivedLog(thread=>sequence=>);

    dbms_backup_restoreRestoreBackupPiece(done => donehandle => /backup/arch params => null);

    dbms_backup_restoreDeviceDeallocate;

    END;

    /

  PL/SQL procedure successfully completed

  不完全恢復打開數據庫

  引用

  SQL> alter database mount;

  Database altered

  SQL> recover database using backup controlfile;

  ORA: change generated at // :: needed for thread

  ORA: suggestion : /app/oracle/product//dbs/arch/_dbf

  ORA: change for thread is in sequence #

  Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

  auto

  ORA: change generated at // :: needed for thread

  ORA: suggestion : /app/oracle/product//dbs/arch/_dbf

  ORA: change for thread is in sequence #

  ORA: log file /app/oracle/product//dbs/arch/_dbf no longer

  needed for this recovery

  ORA: change generated at // :: needed for thread

  ORA: suggestion : /app/oracle/product//dbs/arch/_dbf

  ORA: change for thread is in sequence #

  ORA: log file /app/oracle/product//dbs/arch/_dbf no longer

  needed for this recovery

  ORA: cannot open archived log

  /app/oracle/product//dbs/arch/_dbf

  ORA: unable to obtain file status

  Linux Error: : No such file or directory

  Additional information:

  SQL> recover database using backup controlfile until cancel;

  ORA: change generated at // :: needed for thread

  ORA: suggestion : /app/oracle/product//dbs/arch/_dbf

  ORA: change for thread is in sequence #

  Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

  /app/oracle/oradata/orai/redolog

  Log applied

  Media recovery complete


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