恢复处于NOARCHIVELOG模式的数据库
当数据库处于NOARCHIVELOG模式时,如果出现介质故障 ,则最后一次备份之后对数据库所做的任何操作都将丢失。通过RMAN执行恢复时,只需要执行restore命令将数据库文件修复到正确的位置,然后就可以打开数据库。也就是说,对于处于NOARCHIVELOG模式下的数据库,管理员不需要执行recover命令。
1.Sys登陆,并确认数据库属于NOARCHIVELOG模式
SQL> select log_mode from v$database;
LOG_MODE
------------
ARCHIVELOG
SQL>
SQL>
SQL>
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 2755870720 bytes
Fixed Size 2256432 bytes
Variable Size 671089104 bytes
Database Buffers 2063597568 bytes
Redo Buffers 18927616 bytes
Database mounted.
2.更改数据库为noarchivelog状态
SQL> alter database noarchivelog;
alter database noarchivelog
*
ERROR at line 1:
ORA-38774: cannot disable media recovery - flashback database is enabled
SQL> alter database flashback off;
Database altered.
SQL> alter database noarchivelog;
Database altered.
SQL> archive log list;
3.执行一下命令,备份整个数据库
RMAN> run{
2> allocate channel ch_1 type disk;
3> backup database
4> format '/u01/app/oracle/oradata/Backup/orcl_%t_%u.bak';
5> }
4.可以查看一下备份下来的文件,上边有路径,数据文件和控制文件
5.模拟users.dbf丢失,这里可以先查找数据文件的位置
SQL> select file_name,tablespace_name,bytes from dba_data_files;
[oracle@orcl Backup]$ cd /u01/app/oracle/oradata/orcl
[oracle@orcl orcl]$ rm users01.dbf
6.删除的时候数据库必须是关闭的,不然系统禁止删除正在使用的数据文件,现在到起库测试一下,提示找不到数据文件
RMAN> startup
database is already started
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 12/04/2019 03:39:53
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'
RMAN> run{
7.startup mount状态才能访问数据文件,就可以执行restore
RMAN> run{
2> allocate channel ch_1 type disk;
3> restore database;
4> }
这时候看一下数据文件是可以恢复到目录下的
8.起库看一下是可以起来的
RMAN> startup
database is already started
database opened
处于ARCHIVE模式
恢复处于archivelog模式的数据库
1.查看数据库是否处于归档
SQL> archive log list;
2.启动rman对目标表空间进行备份,然后模拟删除
[oracle@orcl Backup]$ ramn target /
RMAN> run{
2> allocate channel ch_1 type disk;
3> allocate channel ch_2 type disk;
4> backup tablespace users
5> format '/u01/app/oracle/oradata/Backup/users_tablespace.bak';
6> }
3.关闭数据库,然后模拟删除掉users.dbf,users.dbf的路径怎么找上边写的有命令
RMAN> shutdown immediate
database closed
database dismounted
Oracle instance shut down
RMAN> startup mount
RMAN> alter database open;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 12/04/2019 05:20:32
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'
4.数据库现在mount状态,恢复表空间
RMAN> run{
2> allocate channel ch_1 type disk;
3> restore tablespace users;
4> recover tablespace users;
5> }
5.更改成open状态是没有问题的,users的数据文件还是在的
RMAN> alter database open;
database opened
文章来源: 博客园
- 还没有人评论,欢迎说说您的想法!