数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

利用dbmsbackuprestore恢复数据库


发布日期:2022年06月15日
 
利用dbmsbackuprestore恢复数据库

进行测试之前先将数据库做全备

引用

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

上一篇:数据库完整性设计

下一篇:如何查看什么时间有哪些数据库对象结构被修改过