恢复处于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