oracle的备份和恢复

2014-04-30

1.控制文件路径

SQL>select name from v$controlfile;


NAME

------------------------------------------------------------------------------

/u01/app/oracle/oradata/orcl/control01.ctl

/u01/app/oracle/flash_recovery_area/orcl/control02.ctl

RMAN> show controlfile autobackup; --查看是否自动备份

2.控制文件的备份和恢复

1)备份

RMAN> list copy of controlfile;

specification does not match any control file copy in the repository

##image copy备份

RMAN> backup as copy current controlfile;

RMAN> backup as copy current controlfile format '/tmp/c1.bak'; --也可以指定路径,但不建议

RMAN> list copy of controlfile;

list copy of controlfile;


List of Control File Copies

===========================


Key     S Completion Time Ckp SCN    Ckp Time       

------- - --------------- ---------- ---------------

12      A 30-APR-14       2529561    30-APR-14      

        Name: /u01/app/oracle/flash_recovery_area/ORCL/controlfile/o1_mf_TAG20140430T081637_9p0j75dq_.ctl

        Tag: TAG20140430T081637

##backup set 备份

RMAN> backup as backupset current controlfile;

2)恢复

##移除控制文件

[oracle@oracle53 ~]$ cd /u01/app/oracle/oradata/orcl/

[oracle@oracle53 orcl]$ mv control01.ctl control0430.ctl 

[oracle@oracle53 orcl]$ cd /u01/app/oracle/flash_recovery_area/orcl/

[oracle@oracle53 orcl]$ mv control02.ctl control0430.ctl 

##关闭数据库

SYS@orcl 30-APR-14> shutdown immediate;

Database closed.

ORA-00210: cannot open the specified control file

ORA-00202: control file: '/u01/app/oracle/oradata/orcl/control01.ctl'

ORA-27041: unable to open file

Linux-x86_64 Error: 2: No such file or directory

Additional information: 3

----显示找不到控制文件错误----

SYS@orcl 30-APR-14> shutdow abort;

shutdow abort;

ORACLE instance shut down.

##恢复控制文件

RMAN> startup nomount;

RMAN> restore controlfile from autobackup;

RMAN> recover database;

显示错误:ORA-00210: cannot open the specified control file

解决方法:RMAN> mount database;

##打开数据库

RMAN> alter database open;

显示错误:ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

解决方法:RMAN> alter database open resetlogs;

3.recover database命令用法

1)recover database:用来对所有的数据文件进行恢复,并且只能使用保存在文件系统上的归档日志及在线日志,前提是归档日志不可以是还原和重建得来的.

2)recover database:用来对数据文件及控制文件进行恢复,并且可以使用增量备份,备份中的和文件系统上的归档日志,以及文件系统上的在线日志.

3)recover database using backup controlfile:用来对数据文件及控制文件进行恢复,并且只能使用保存在文件系统上的归档日志和在线日志.

resetlogs原因是recover命令只能修复控制文件中数据库物理结构信息,而无法修改控制文件中当前重做日志的序列号等信息.

//另一种rman实现控制文件的方法

run{

startup nomount;

restore controlfile from autobackup;

mount database;

recover database;

alter database open resetlogs;

}

4.三大文件

重做日志:在线重做日志,归档日志

数据文件

控制文件

5.关键数据文件的备份和还原

system表空间损坏

undo表空间   ---所有的变更类命令(DDL,DML,DCL)所产生的撤销数据.

shell> cd /u01/app/oracle/oradata/orcl/ --该目录下存放数据文件

##备份system,undotbs1表空间

RMAN> backup as backupset tablespace system,undotbs1;

---多通道备份-----

run {

allocate channel c1 device type disk;

allocate channel c2 device type disk;

backup (datafile '/u01/app/oracle/oradata/orcl/system01.dbf' channel c1)

(datafile '/u01/app/oracle/oradata/orcl/undotbs01.dbf' channel c2);

};

##删除数据文件

shell> cd /u01/app/oracle/oradata/orcl/

##还原system表空间

RMAN> run {

startup mount;

restore datafile 1;

recover database;

alter database open;

}

##还原undo表空间

RMAN>  run {

startup mount;

restore tablespace undotbs1;

recover database;

alter database open;

}

##还原步骤:

1)如果实例没有崩溃,使用shutdown abort/immediate命令关闭实例

2)执行startup mount 命令将数据库启动到mount阶段

3)使用rman执行restore或swith命令还原损失的关键数据文件

4)使用rman执行recover database命令,利用归档日志和在线日志恢复数据文件

5)执行alter database open 命令打开数据库,恢复完成

6.普通数据文件的备份和恢复

普通数据文件指非system表空间,undotbs表空间,临时表空间和只读表空间的数据文件.损坏最多导致用户数据不可访问,不会导致数据库实例崩溃等.可在open状态下进行.

普通文件损坏的几种情况:

1)实例启动时,若普通数据文件丢失,无法访问或头部损失,startup命令只能将数据库带到mount阶段.

2)实例启动时,若数据文件头部损坏,由于检查点无法在数据库头部完成,此数据库文件的状态在控制文件中会自动设置为offline.

3)实例启动时,若普通数据文件非头部数据块损坏,将导致需要访问受损数据块的命令无法执行,数据文件不会自动下线。

##备份example表空间

RMAN> backup as backupset tablespace example;

##还原example表空间,example表空间不存在

[oracle@oracle53 orcl]$ mv example01.dbf example0430.dbf 

RMAN> shutdown immediate;

RMAN> startup mount;

RMAN> restore tablespace example;

RMAN> recover database;

shell> cd /u01/app/oracle/oradata/orcl/    --验证恢复

##还原example表空间,example表空间损坏

[oracle@oracle53 orcl]$ echo "haha" >> example01.dbf 

SYS@orcl 14:04:30-09:49:54> startup force;

ORA-01157: cannot identify/lock data file 5 - see DBWR trace file

ORA-01110: data file 5: '/u01/app/oracle/oradata/orcl/example01.dbf'

RMAN> restore tablespace example; --open状态恢复

RMAN> recover database;

RMAN> startup force;

普通文件核心步骤:让普通文件先下线(alter database datafile 5 offline),从备份中还原(restore或swith),使用增量备份或重做日志(recover),最后让文件上线(alter database datafile 5 online);

RMAN> run {sql 'alter database datafile 5 offline';}  --recover状态

RMAN> restore tablespace example;        --recover状态

RMAN> recover tablespace example;        --offline状态

RMAN> run {sql 'alter database datafile 5 online';}     --online状态

##普通还原步骤

1)使用shutdown immediate命令关闭实例

2)执行startup mount命令将实例启动到mount阶段

3)使用rman执行restore或swith命令还原损失的普通数据文件

4)使用rman执行recover database命令,利用归档日志和在线日志恢复数据文件

5)执行alter database open 命令打开数据库,恢复完成


转载于:https://my.oschina.net/xiaoq6427/blog/228743

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值