Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1011423
  • 博文数量: 584
  • 博客积分: 2293
  • 博客等级: 大尉
  • 技术积分: 3045
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-28 11:15
文章分类

全部博文(584)

文章存档

2012年(532)

2011年(47)

2009年(5)

我的朋友

分类:

2012-02-03 13:41:45

原文地址:oracle rman 学习笔记 作者:极地冰山

 
RMAN> connect target /
————————————————————————
rman target /
————————————————————————
channel  (控制RMAN备份的行为)
在目标服务器启动个进程

limit read rate
limit kbytes
limit maxopenfiles
——————————————————————————————
RMAN> run{
allocate channel cha1 type disk;
backup format '/u01/rmanbackup/full_%t'
tag full_bakup_bat
database;
release channel cha1;
}
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
15      Full    500.02M    DISK        00:00:40     09-JUL-10     
        BP Key: 15   Status: AVAILABLE  Compressed: NO  Tag: FULL_BACKUP_BAT
        Piece Name: /u01/rmanbackup/full_723869971
  List of Datafiles in backup set 15
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 504103     09-JUL-10 /u01/app/oracle/oradata/orc1/system01.dbf
  2       Full 504103     09-JUL-10 /u01/app/oracle/oradata/orc1/undotbs01.dbf
  3       Full 504103     09-JUL-10 /u01/app/oracle/oradata/orc1/sysaux01.dbf
  4       Full 504103     09-JUL-10 /u01/app/oracle/oradata/orc1/users01.dbf
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
16      Full    6.80M      DISK        00:00:02     09-JUL-10     
        BP Key: 16   Status: AVAILABLE  Compressed: NO  Tag: FULL_BACKUP_BAT
        Piece Name: /u01/rmanbackup/full_723870017
  Control File Included: Ckp SCN: 504465       Ckp time: 09-JUL-10
  SPFILE Included: Modification time: 09-JUL-10
RMAN>
————————————————————————————————————
备份脚本
[oracle@redhat script]$ ls
bakl0  bakl1  bakl2
[oracle@redhat script]$ pwd
/u01/rmanbackup/script
[oracle@redhat script]$ more bakl0
run {
allocate channel c1 type disk;
backup
incremental  level 0
format "/u01/rmanbackup/incr0_%u_&T"
tag monday_incr
database;
release channel c1;
}
————————————————————————————————
[oracle@redhat script]$ more bakl1
run {
allocate channel c1 type disk;
backup
incremental  level 1
format "/u01/rmanbackup/incr1_%u_&T"
tag monday_incr
database;
release channel c1;
}
————————————————————————————————
[oracle@redhat script]$ more bakl2
run {
allocate channel c1 type disk;
backup
incremental  level 2
format "/u01/rmanbackup/incr2_%u_&T"
tag monday_incr
database;
release channel c1;
}
——————————————————————————————————
[oracle@redhat script]$
 
执行脚本
[oracle@redhat script]$ which rman
/u01/app/oracle/product/10.2.0/db_1/bin/rman
————————————————————————————————————
 rman target / msglog=/u01/rmanbackup/bakl0.log cmdfile=/u01/rmanbackup/script/bakl0

————————————————————————————————————————
自动执行

crontab -e -u oracle

50 03 * * * rman target / msglog=/u01/rmanbackup/bakl1.log cmdfile=/u01/rmanbackup/script/bakl1
~
——————————————————————————————————————
service crond restart

————————————————————————————————————
恢复
show all;
—————————————————————————————————————
RMAN> configure controlfile autobackup off;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
new RMAN configuration parameters are successfully stored
——————————————————————————————————————
RMAN> configure controlfile autobackup on;
old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
—————————————————————————————————————
list backup;
——————————————————
delete backupset 20;
————————————————————
RMAN> backup format '/u01/rmanbackup/bak_%T_%u.bak' database plus archivelog;

——————————————————————————————————————
密码恢复
rmanbackup]$ cd /u01/app/oracle/product/10.2.0/db_1/dbs/
[oracle@redhat dbs]$ ls
hc_orc1.dat  init.ora      lkORC1     snapcf_orc1.f
initdw.ora   initORC1.ora  orapworc1  spfileorc1.ora
[oracle@redhat dbs]$ more orapworc1

ORACLE Remote Password file

————————————————————————————————————
[oracle@redhat dbs]$ mv orapworc1 passwd
[oracle@redhat dbs]$ orapwd file=orapworc1 password=orc1 entries=5
[oracle@redhat dbs]$ ls
hc_orc1.dat  init.ora      lkORC1     passwd         spfileorc1.ora
initdw.ora   initORC1.ora  orapworc1  snapcf_orc1.f
————————————————————————————————————
SPFILE恢复 ORC1 (DBID=1355614192)
[oracle@redhat dbs]$ ls
hc_orc1.dat  init.ora      lkORC1     passwd         spfile.1
initdw.ora   initORC1.ora  orapworc1  snapcf_orc1.f
[oracle@redhat dbs]$ pwd
/u01/app/oracle/product/10.2.0/db_1/dbs
(mv spfile)
————————————————————————
RMAN> shutdown immediate;
RMAN> startup nomount;
connected to target database (not started)
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initorc1.ora'
starting Oracle instance without parameter file for retrival of spfile
Oracle instance started
Total System Global Area     159383552 bytes
Fixed Size                     1218268 bytes
Variable Size                 54528292 bytes
Database Buffers             100663296 bytes
Redo Buffers                   2973696 bytes
————————————————————
RMAN> set dbid 1355614192
executing command: SET DBID
————————————————————————
RMAN> restore spfile from autobackup;
Starting restore at 09-JUL-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=34 devtype=DISK
channel ORA_DISK_1: looking for autobackup on day: 20100709
channel ORA_DISK_1: looking for autobackup on day: 20100708
channel ORA_DISK_1: looking for autobackup on day: 20100707
channel ORA_DISK_1: looking for autobackup on day: 20100706
channel ORA_DISK_1: looking for autobackup on day: 20100705
channel ORA_DISK_1: looking for autobackup on day: 20100704
channel ORA_DISK_1: looking for autobackup on day: 20100703
channel ORA_DISK_1: no autobackup in 7 days found
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 07/09/2010 03:57:29
RMAN-06172: no autobackup found or specified handle is not a valid copy or piece
————————————————————————————————
RMAN> restore spfile from '/u01/app/oracle/flash_recovery_area/ORC1/autobackup/2010_07_09/o1_mf_s_723873026_63dc03xh_.bkp'
2> ;
Starting restore at 09-JUL-10
using channel ORA_DISK_1
channel ORA_DISK_1: autobackup found: /u01/app/oracle/flash_recovery_area/ORC1/autobackup/2010_07_09/o1_mf_s_723873026_63dc03xh_.bkp
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 09-JUL-10
————————————————————————————————————
RMAN> startup
connected to target database (not started)
Oracle instance started
database mounted
database opened
Total System Global Area     167772160 bytes
Fixed Size                     1218316 bytes
Variable Size                 75499764 bytes
Database Buffers              88080384 bytes
Redo Buffers                   2973696 bytes
——————————————————————————————————
恢复控制文件
dbs]$ cd /u01/app/oracle/oradata/orc1/
[oracle@redhat orc1]$ ls
control01.ctl  redo01.log  sysaux01.dbf  undotbs01.dbf
control02.ctl  redo02.log  system01.dbf  users01.dbf
control03.ctl  redo03.log  temp01.dbf
[oracle@redhat orc1]$ rm *.ctl
[oracle@redhat orc1]$ ls
redo01.log  redo03.log    system01.dbf  undotbs01.dbf
redo02.log  sysaux01.dbf  temp01.dbf    users01.dbf
[oracle@redhat ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Fri Jul 9 04:07:40 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-06003: ORACLE error from target database:
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/app/oracle/oradata/orc1/control01.ctl'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
[oracle@redhat ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jul 9 04:08:00 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
SQL> conn /as sysdba
Connected.
SQL> shutdown immediate;
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/app/oracle/oradata/orc1/control01.ctl'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3
SQL> shutdown abort;
ORACLE instance shut down.
SQL>
[oracle@redhat ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Fri Jul 9 04:08:55 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database (not started)
RMAN>
RMAN> startup nomount;
Oracle instance started
Total System Global Area     167772160 bytes
Fixed Size                     1218316 bytes
Variable Size                 75499764 bytes
Database Buffers              88080384 bytes
Redo Buffers                   2973696 bytes
RMAN> restore controlfile from  autobackup;
Starting restore at 09-JUL-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
recovery area destination: /u01/app/oracle/flash_recovery_area
database name (or database unique name) used for search: ORC1
channel ORA_DISK_1: autobackup found in the recovery area
channel ORA_DISK_1: autobackup found: /u01/app/oracle/flash_recovery_area/ORC1/autobackup/2010_07_09/o1_mf_s_723873026_63dc03xh_.bkp
channel ORA_DISK_1: control file restore from autobackup complete
output filename=/u01/app/oracle/oradata/orc1/control01.ctl
output filename=/u01/app/oracle/oradata/orc1/control02.ctl
output filename=/u01/app/oracle/oradata/orc1/control03.ctl
Finished restore at 09-JUL-10
————————————————————————————————
[oracle@redhat orc1]$ ls
control01.ctl  redo01.log  sysaux01.dbf  undotbs01.dbf
control02.ctl  redo02.log  system01.dbf  users01.dbf
control03.ctl  redo03.log  temp01.dbf
————————————————————————————————
RMAN> alter database open resetlogs;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 07/09/2010 04:11:22
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/u01/app/oracle/oradata/orc1/system01.dbf'
—————————————————————————————————
RMAN> recover database ;
Starting recover at 09-JUL-10
Starting implicit crosscheck backup at 09-JUL-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
Crosschecked 3 objects
Finished implicit crosscheck backup at 09-JUL-10
。。。。。。。。。。。
————————————————————————————————————
RMAN> alter database open resetlogs;
database opened
————————————————————————————————————
SQL> select  * from dual;
D
-
X
————————————————————————————————————
rodulog 丢失恢复
orc1]$ ls
control01.ctl  redo01.log  sysaux01.dbf  undotbs01.dbf
control02.ctl  redo02.log  system01.dbf  users01.dbf
control03.ctl  redo03.log  temp01.dbf
[oracle@redhat orc1]$ rm *.log
[oracle@redhat orc1]$ ls
control01.ctl  control03.ctl  system01.dbf  undotbs01.dbf
control02.ctl  sysaux01.dbf   temp01.dbf    users01.dbf
[oracle@redhat orc1]$
————————————————————————————
[oracle@redhat ~]$ sqlplus  "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jul 9 04:19:32 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
——————————————
SQL> shutdown immediate;
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
————————————————
SQL> startup mount;
ORACLE instance started.
Total System Global Area  167772160 bytes
Fixed Size                  1218316 bytes
Variable Size              75499764 bytes
Database Buffers           88080384 bytes
Redo Buffers                2973696 bytes
Database mounted.
————————————————
SQL> recover database until cancel;
Media recovery complete.
————————————————
SQL> alter database open resetlogs;
Database altered.
SQL>
————————————————————
SQL> select * from dual;
D
-
X
————————————————————————————————————————
[oracle@redhat orc1]$ ls
control01.ctl  redo01.log  sysaux01.dbf  undotbs01.dbf
control02.ctl  redo02.log  system01.dbf  users01.dbf
control03.ctl  redo03.log  temp01.dbf
[oracle@redhat orc1]$
——————————————————————
数据文件丢失恢复
list schema;
report schema;
__________________________________
[oracle@redhat orc1]$ mv sysaux01.dbf sysaux01.dbf.bak
[oracle@redhat orc1]$ ls
control01.ctl  redo01.log  sysaux01.dbf.bak  undotbs01.dbf
control02.ctl  redo02.log  system01.dbf      users01.dbf
control03.ctl  redo03.log  temp01.dbf
_______________________________
[oracle@redhat ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Fri Jul 9 04:28:37 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: ORC1 (DBID=1355614192)
RMAN> report schema;
using target database control file instead of recovery catalog
Report of database schema
List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    480      SYSTEM               ***     /u01/app/oracle/oradata/orc1/system01.dbf
2    25       UNDOTBS1             ***     /u01/app/oracle/oradata/orc1/undotbs01.dbf
3    0        SYSAUX               ***     /u01/app/oracle/oradata/orc1/sysaux01.dbf
4    5        USERS                ***     /u01/app/oracle/oradata/orc1/users01.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    20       TEMP                 32767       /u01/app/oracle/oradata/orc1/temp01.dbf
______________________________________________________
RMAN> sql "alter database datafile 3 offline";
sql statement: alter database datafile 3 offline
___________________________________
MAN> restore datafile 3;
Starting restore at 09-JUL-10
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00003 to /u01/app/oracle/oradata/orc1/sysaux01.dbf
channel ORA_DISK_1: reading from backup piece /u01/rmanbackup/bak_20100709_0rliar6i.bak
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/rmanbackup/bak_20100709_0rliar6i.bak tag=TAG20100709T034938
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 09-JUL-10
________________________________________________
RMAN> recover datafile 3;
Starting recover at 09-JUL-10
using channel ORA_DISK_1
starting media recovery
archive log thread 1 sequence 6 is already on disk as file /u01/app/oracle/flash_recovery_area/ORC1/archivelog/2010_07_09/o1_mf_1_6_63dd957f_.arc
archive log thread 1 sequence 7 is already on disk as file /u01/app/oracle/flash_recovery_area/ORC1/archivelog/2010_07_09/o1_mf_1_7_63dd959b_.arc
archive log filename=/u01/app/oracle/flash_recovery_area/ORC1/archivelog/2010_07_09/o1_mf_1_6_63dd957f_.arc thread=1 sequence=6
archive log filename=/u01/app/oracle/flash_recovery_area/ORC1/archivelog/2010_07_09/o1_mf_1_7_63dd959b_.arc thread=1 sequence=7
unable to find archive log
archive log thread=1 sequence=1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/09/2010 04:30:17
RMAN-06054: media recovery requesting unknown log: thread 1 seq 1 lowscn 507813
RMAN>
__________________________________________________________
3> sql "alter database datafile 3 online";
__________________________________________________________
表空间恢复
sql "alter tablespace users offline";
restore tablespace users;
recover tablespace users;
sql "alter tablespace users online";
___________________________________________
sql "alter tablespace tabs1 offline immediate";
restore tablespace tbs1;
recover tablespace tbs1:
sql "alter tablespace tbs1 online";
select * from user1.tables1;
__________________________________________________________________

report schema

___________________________
完全恢复
rman target /
______
sqlplus /nolog
shutdown about;
____
{rman target /
startup nomount;
restore controlfile form autobackup;
alter database mount;
restore database;
recover database;不成功
 sqlplus /nolog
 conn /as sysdba
 create pfile from spfile;
  在PFILE里加 allow_resetlogs_corruption=true
 shutdown immediate
 startup pfile=/u01/oracle/product/10.2.0....*.ora  mount
 alter database open resetlogs;
}
 
________________________________________________
scn 恢复
shutdown immediate
startup mount
restore database until scn 643309;
recover database until scn 643309;
alter database open resetlogs;
___________________________________________
sequence:恢复
select * from v$log; 
——————————————————————————————————
总结命令
report schema
list backup
crosscheck backup
delete
 
_____________________________________
catlog database for rman
create talbespace rman_ts datafile"..." size=20M;
create user rman identifide by rman default tablespace rman_ts  quota unlimited
on rman_ts;
grant recovery_catalog_owner to rman;
create catalog tablespace rman_ts;
register database;
_______________________________
select * from dba_sys_prives where grantee='connect';

rman target / catalog rman/rman

 
阅读(763) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~