分类: Oracle
2012-08-13 11:33:38
建立Recovery Catalog的步骤
1,create tablespace
2,create catalog owner
3,grant privileges
4,check space
5,create catalog
6,connect with target database
7,register target database;
1,[oracle@oracle ~]$sql "/as sysdba"
[oracle@oracle ~]$create tablespace rman_ts datafile '/robotdata/ROBOT/datafile/rman.dbf';
[oracle@oracle ~]$create user rman identified by rman default tablespace rman_ts;
[oracle@oracle ~]$grant sysdba,resource,recovery_catalog_owner to rman;
[oracle@oracle ~]$rman
RMAN>connect catalog
RMAN>create catalog;
RMAN>EXIT;
[oracle@oracle ~]$rman target catalog ;
RMAN>register database;
RMAN>list incarnation of database;
CATALOG
SQL>alter tablespace users begin backup;
SQL>host cp /robotdata/ROBOT/datafile/o1_mf_users_6s88yww2_.dbf /robotdata/rman/
SQL>alter tablespace user end backup;
RMAN>catalog datafilecopy '/robotdata/rman/o1_mf_users_6s88yww2_.dbf';
RMAN>list copy of database;
CHANGE
RAN> run
{allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
copy
datafile 6 to '/robotdata/rman/taobao01.bak',
datafile 5 to '/robotdata/rman/getrobot01.bak',
datafile 4 to '/robotdata/rman/user01.bak';
}
RMAN>list copy of database;
List of Datafile Copies
Key File S Completion Time Ckp SCN Ckp Time Name
------- ---- - --------------- ---------- --------------- ----
313 4 A 09-MAY-11 4424943 09-MAY-11 /robotdata/rman/user01.bak
302 4 A 09-MAY-11 4424497 09-MAY-11 /robotdata/rman/o1_mf_users_6s88yww2_.dbf
315 5 A 09-MAY-11 4424942 09-MAY-11 /robotdata/rman/getrobot01.bak
314 6 A 09-MAY-11 4424941 09-MAY-11 /robotdata/rman/taobao01.bak
RMAN>change datafilecopy 302 delete;(delete一个数据文件的copy)
List of Datafile Copies
Key File S Completion Time Ckp SCN Ckp Time Name
------- ---- - --------------- ---------- --------------- ----
302 4 A 09-MAY-11 4424497 09-MAY-11 /robotdata/rman/o1_mf_users_6s88yww2_.dbf
Do you really want to delete the above objects (enter YES or NO)? yes
deleted datafile copy
datafile copy filename=/robotdata/rman/o1_mf_users_6s88yww2_.dbf recid=1 stamp=750706625
Deleted 1 objects
RMAN> list copy of database;
List of Datafile Copies
Key File S Completion Time Ckp SCN Ckp Time Name
------- ---- - --------------- ---------- --------------- ----
313 4 A 09-MAY-11 4424943 09-MAY-11 /robotdata/rman/user01.bak
315 5 A 09-MAY-11 4424942 09-MAY-11 /robotdata/rman/getrobot01.bak
314 6 A 09-MAY-11 4424941 09-MAY-11 /robotdata/rman/taobao01.bak
RMAN> create script robot_bk
{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup
incremental level 0
format '/robotdata/rman/db_%d_%s_%p.bak'
filesperset 4
(database include current controlfile);
sql 'alter system archive log current';
}
RMAN>created script robot_bk
RMAN> run {execute script robot_bk;}
REPORT
RMAN>report need backup days 5 database;(最近5天内database没有备份的文件)
RMAN>report obsolete;(可以删除的backup)
RMAN>delete obsolete;(删除过期备份)
RMAN> report unrecoverable;
RMAN> report need backup incremental 3 database;(进行level=3的增量备份,所需备份的文件)
RMAN> report need backup redundancy 2;(备份冗级别为2,那些文件没有2个以上的数据备份)
Report of files with less than 2 redundant backups
File #bkps Name
---- ----- -----------------------------------------------------
1 1 /robotdata/ROBOT/datafile/o1_mf_system_6s88ywsx_.dbf
2 1 /robotdata/ROBOT/datafile/o1_mf_undotbs1_6s88ywvv_.dbf
3 1 /robotdata/ROBOT/datafile/o1_mf_sysaux_6s88ywt9_.dbf
4 1 /robotdata/ROBOT/datafile/o1_mf_users_6s88yww2_.dbf
5 1 /robotdata/ROBOT/datafile/GETROBOT01.DBF
6 1 /robotdata/ROBOT/datafile/TAOBAO01.DBF
7 1 /robotdata/ROBOT/datafile/rman.dbf
MAN> report schema;(数据库的物理架构)
Report of database schema
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 1024 SYSTEM YES /robotdata/ROBOT/datafile/o1_mf_system_6s88ywsx_.dbf
2 100 UNDOTBS1 YES /robotdata/ROBOT/datafile/o1_mf_undotbs1_6s88ywvv_.dbf
3 1024 SYSAUX NO /robotdata/ROBOT/datafile/o1_mf_sysaux_6s88ywt9_.dbf
4 1024 USERS NO /robotdata/ROBOT/datafile/o1_mf_users_6s88yww2_.dbf
5 5120 GETROBOT NO /robotdata/ROBOT/datafile/GETROBOT01.DBF
6 5120 TAOBAO NO /robotdata/ROBOT/datafile/TAOBAO01.DBF
7 100 RMAN_TS NO /robotdata/ROBOT/datafile/rman.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 127 TEMP 32767 /robotdata/ROBOT/datafile/o1_mf_temp_6s88zzdy_.tmp
VIEWS
SQL>conn ;
SQL>select * from rc_database;
DB_KEY DBINC_KEY DBID NAME RESETLOGS_CHANGE# RESETLOGS
---------- ---------- ---------- -------- ----------------- ---------
1 2 95797240 ROBOT 446075 31-MAR-11
SQL>col text format a30;
SQL>col script_name for a10;
SQL> select * from rc_stored_script;
DB_KEY DB_NAME SCRIPT_NAM SCRIPT_COMMENT
---------- ---------- ---------- --------------------
########## ROBOT robot_bk
SQL> select text from rc_stored_script_line;
TEXT
--------------------------------------------------------------------------------
{allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup
incremental level 0
format '/robotdata/rman/db_%d_%s_%p.bak'
filesperset 4
(database include current controlfile);
sql 'alter system archive log current';
}
10 rows selected
oracle恢复目录模式的RCVER版本:
SQL>select * from rcver;
查看日志文件来监控RMAN操作
SQL> select output from v$rman_output order by stamp;
allocate channel命令定义给定通道所分配到的设备(type disk or type sbt)
exp:allocate channel t1 type disk maxpiecesize=100m format='/robotdata/rman/robot_%U.bak';
RMAN增量备份
1,差异备份是RMAN生存的增量备份的默认类型。RMAN会备份自上一次同级或低级差异增量备份以来所有发生变化的数据块。
exp:
0-2-2-1-2-2-0
backup incremental level = 1 database;
2,累计备份
累计备份可以使备份集备份前面所有级别的备份以及此次要备份的所有发生变化的数据块。并要求在backup命令中使用cumulative关键字。
exp:
0-2-2-1-2-2-0
在linux下编辑脚本备份
#########
#!/bin/sh
rman target
backup database tag "yang0510" format='/robotdata/rman/db_%U.bak';
quit
EOF
##########
crosscheck命令来校检控制文件或恢复目录中的RMAN信息是否与备份介质上的实际物理备份集片相同;
用于备份集片的v$backup_set视图和用于副本的v$datafile_copy视图中的status列出了每个备份集或副本的状态码,如果使用恢复目录,则在rc_backup_set和副本rc_datafile_copy上列出了每个备份集或副本的状态码。
crosscheck检查所有备份集的状态
RMAN>crosscheck backup;
EXP:
crosscheck backup of datafile 1;
crosscheck backup of tablespace users;
crosscheck backup of controlfile;
crosscheck backup of spfile;
crosscheck backup tag "yang0510"
crosscheck backup device type disk;
校检归档日志
crosscheck archivelog all;
crosscheck copy命令校验副本
exp:
crosscheck copy of datafile 5;
RMAN备份验证
RMAN提供validate允许查看给定的备份集和进行验证以确保这个备份集能够被还原。
validate命令需要备份集的主键并验证该备份集,通过list backupset summary来获取;
RMAN> list backupset summary;
List of Backups
===============
Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
371 B 0 A DISK 09-MAY-11 1 1 NO TAG20110509T180819
373 B 0 A DISK 09-MAY-11 1 1 NO TAG20110509T180819
658 B F A DISK 10-MAY-11 1 1 NO YANG0510
RMAN> validate backupset 658;
using channel ORA_DISK_1
channel ORA_DISK_1: starting validation of datafile backupset
channel ORA_DISK_1: reading from backup piece /robotdata/rman/db_0kmbvnru_1_1.bak
channel ORA_DISK_1: restored backup piece 1
piece handle=/robotdata/rman/db_0kmbvnru_1_1.bak tag=YANG0510
channel ORA_DISK_1: validation complete, elapsed time: 00:00:18
创建存储脚本
create script my_backup_script comment 'this script backup the database robot'
{backup database plus archivelog;}
修改存储脚本
replace script my_backup_script comment 'this script backup the database robot'
{backup database plus archivelog delete input;}
删除存储脚本
delete script my_backup_script;
使用存储脚本
run{execute script my_backup_script;}
run{execute script rman_2;}
打印存储脚本
print script my_backup_script;
查看脚本内容
select script_name,text from rc_stored_script_line order by script_name,line;