Disk Backup Location /u01/app/oracle/flash_recovery_area
冷备份
cp -rf db1 db1.bak
du -sm db1 db1.bak
oerr ora +错误号显示ora的错误信息
1.sqlplus sys/oracle@db2 as sysdba 以dba的身份登录数据库
rman target sys/oracle@db2 登录目标数据库
rman catalog rman/cat@db2 登陆目录数据库
rman target sys/oracle@db1 catalog rman/cat@db2 同时登陆
只有此时才可以创建scripts;要直接登录这两个必须先都登录过(一般需要登录的是目录数据库)
2.关于丢失表空间的恢复
删除的不是备份分表空间不能进行恢复
没有关闭数据库的恢复方法:
备份表空间
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4> tag users
5> format '/u01/app/oracle/oracle/admin/db2/backups_users_t%t_s%s'
6> (tablespace users)
7>
进行恢复:
RMAN> run{
2> allocate channel dev1 type disk;
3> restore tablespace users;
4> recover tablespace users;
5> release channel dev1;
6> }
using target database control file instead of recovery catalog
allocated channel: dev1
channel dev1: sid=137 devtype=DISK
Starting restore at 06-NOV-12
released channel: dev1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 11/06/2012 17:16:04
RMAN-06026: some targets not found - aborting restore
RMAN-06023: no backup or copy of datafile 4 found to restore
方法:
ps -ef | grep dbw 查看进程
cd /proc/5128/fd 进入进程查看缺失文件
ls-l
cp 23 /u01/app/oracle/oradata/db2/users01.dbf 没有shutdown的恢复cp
数据文件恢复
3.关于不确定时间flashback快闪后可能丢失数据文件的恢复:
SYS@db1> !rman target sys/oracle@db1 catalog rman/cat@db2
Recovery Manager: Release 10.2.0.1.0 - Production on Mon Nov 12 16:44:04 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: DB1 (DBID=1386705937)
connected to recovery catalog database
RMAN> run{
2> allocate channel dev1 type disk;
3> restore datafile 4;
4> recover datafile 4;
5> release channel dev1;
6> }
allocated channel: dev1
channel dev1: sid=133 devtype=DISK
Starting restore at 12-NOV-12
channel dev1: starting datafile backupset restore
channel dev1: specifying datafile(s) to restore from backup set
restoring datafile 00004 to /u01/app/oracle/oradata/db1/users01.dbf
channel dev1: reading from backup piece /u01/app/oracle/admin/db2/backups_users_t798652847_s12
channel dev1: restored backup piece 1
piece handle=/u01/app/oracle/admin/db2/backups_users_t798652847_s12 tag=TAG20121106T160047
channel dev1: restore complete, elapsed time: 00:00:09
Finished restore at 12-NOV-12
Starting recover at 12-NOV-12
starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished recover at 12-NOV-12
released channel: dev1
快闪后导致表的不可用,我做的scott用户下的emp表,属于user表空间
此时查询
SYS@db1> select * from scott.emp where rownum<4;
select * from scott.emp where rownum<4
*
ERROR at line 1:
ORA-00376: file 4 cannot be read at this time
ORA-01110: data file 4: '/u01/app/oracle/oradata/db1/users01.dbf'
首先:SYS@db1> select tablespace_name,status from dba_tablespaces;
通过查询表空间的状态来看文件所属的表空间
TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
UNDOTBS1 ONLINE
SYSAUX ONLINE
TEMP ONLINE
USERS OFFLINE
UNDOTBS2 ONLINE
EXAMPLE ONLINE
INVENTORY ONLINE
TBSADDM ONLINE
user表空间不在线,
SYS@db1> alter tablespace USERS online;
Tablespace altered.使得user表空间状态为在线。
select file#,name,status,enabled from v$datafile;
查询所属数据文件的状态
FILE#
----------
NAME
-------------------------------------------------------------------------------------------------
STATUS ENABLED
------- ----------
1
/u01/app/oracle/oradata/db1/system01.dbf
SYSTEM READ WRITE
2
/u01/app/oracle/oradata/db1/undotbs01.dbf
ONLINE READ WRITE
3
/u01/app/oracle/oradata/db1/sysaux01.dbf
ONLINE READ WRITE
4
/u01/app/oracle/oradata/db1/users01.dbf
ONLINE READ WRITE
5
/u01/app/oracle/oradata/db1/example01.dbf
ONLINE READ WRITE
6
/u01/app/oracle/oradata/db1/inventory
ONLINE READ WRITE
7
/u01/app/oracle/product/10.2.0/db_1/dbs/addm1.dbf
ONLINE READ WRITE
此时都为ONLINE READ WRITE状态,如果是recover则需要做恢复,我是先做的恢复,因此这里的状态是ONLINE READ WRITE。
这时在查询便可以正常了emp表。
4.指定系统默认表空间
ALTER DATABASE DEFAULT TABLESPACE <tsname>;
改变数据库中除system和sysaux外任意一个表空间的名字
ALTER TABLESPACE <oldname> RENAME TO <newname>;
5.数据库完全备份
RMAN> run {
# backup the complete database to disk
allocate channel dev1 type disk;
backup
full
tag full_db_backup
format '/u01/app/oracle/admin/db2/backups_t%t_s%s_p%p'
(database);
release channel dev1;
}
6.关于对备份文件的删除
在os上手工删除备份后,rman仍然认为是available,rman还是认为那文件存在,只有执行了crosscheck才会将available转化为expired,delete expired后,rman就不会觉得那空间还没占用。
7.oracle_BASE 是orace的根目录,ORACLE_BASE是oracle产品的目录。