RMAN 常用场景及命令
1. Rman catalog
Catalog 命令可用于注册特定的备份集片。 如:
RMAN>catalog backuppiece 'F:/BACKUP/ORCL_11LH4449_1_1.BAK';
注册归档的重做日志
RMAN>catalog archivelog 'D:/archivelog/ORCL_1_102_719615012.ARC';
如文件太多
(1)recovery area 或者 db_recovery_file_dest
(2)Start with
RMAN>catalog start with 'D:/archivelog';
recovery area 和 db_recovery_file_dest 功能相同,他们是RMAN对整个FRA 编目录,如果RMAN 发现已经对一些文件编目录,它就会跳过这些文件并继续对控制文件中的剩余文件编目录。如:
RMAN>catalog recovery area;
2. 常用场景
2.1 数据文件损坏
RMAN>run {
startup force mount;
sql 'alter database datafile 4 offline';
sql 'alter database open';
set newname for datafile 4 to 'c:\demo\user01.dbf';
restore datafile 4;
switch datafile 4;
recover datafile 4;
Sql 'alter database datafile 4 online'; }
2.2 数据文件丢失
RMAN>run {
sql 'alter database datafile 4 offline';
restore datafile 4;
recover datafile 4;
sql 'alter database datafile 4 online';
}
2.3 恢复表空间
RMAN> run {
sql 'alter tablespace users offline for recover';
restore tablespace users;
recover tablespace users;
sql 'alter tablespace users online'; }
2.4 数据块恢复
RMAN> blockrecover datafile 5 block 20,21,100;
2.5 不完全恢复
restore database;
recover database;
sql 'alter database open resetlogs'; }
run {
sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"';
2.6 恢复spfile或controlfile到指定位置
restore spfile to '/home/oracle/spfile' from '/opt/oracle/db10/dbs/0ipbc7o9_1_1';restore controlfile to '/home/oracle/control' from '/opt/oracle/db10/dbs/0hpbc75v_1_1';
2.7 全库备
3. 日志的备份和恢复
backup ARCHIVELOG all delete input;backup archivelog from time "sysdate-1" delete input;
-- 恢复日志
run
allocate channel ch1 type disk;
restore archivelog from logseq 9;
release channel ch1;
Run
sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"';
restore archivelog time between '2010-11-11 09:00:00' and '2010-11-11 22:00:00';
-- 删除归档日志:
$ cat /oradata/backup/scripts/deletearch.sh
source ~/.bash_profile
rman target / log=del_arch.log <<EOF
run{
allocate channel c1 type disk ;
delete noprompt archivelog until time "sysdate-1";
release channel c1;
}
exit;
EOF
4.RMAN LIST
List backup summary;
List backup by file;
List backup of tablespace users;
List backup of datafile 3;
List archivelog all;
List backup of controlfile;
list archivelog from time 'sysdate-1';
list archivelog from sequence 7;
5.Delete backups
Delete obsolete redundancy=3;
Delete obsolete recovery window of 7 days;
6.Monitoring RMAN Through V$ Views
Status information for jobs in progress and completed jobs is stored in V$RMAN_STATUS.V$RMAN_OUTPUT contains the text ouptut of all RMAN jobs.
To see status information on jobs in V$RMAN_STATUS use the following query:
SELECT OPERATION, STATUS, MBYTES_PROCESSED, START_TIME, END_TIME from V$RMAN_STATUS;
To correlate a channel with a process, run the following query in SQL*Plus while the RMAN job is executing:
SQL> COLUMN CLIENT_INFO FORMAT a30
SQL> COLUMN SID FORMAT 999
SQL> COLUMN SPID FORMAT 9999
SQL> SELECT s.SID, p.SPID, s.CLIENT_INFO FROM V$PROCESS p, V$SESSION s WHERE p.ADDR = s.PADDR
AND CLIENT_INFO LIKE 'rman%';
To calculate the progress of an RMAN job, run the following query in SQL*Plus while the RMAN job is executing:
SQL> SELECT SID, SERIAL#, CONTEXT, SOFAR, TOTALWORK, ROUND(SOFAR/TOTALWORK*100,2) "% COMPLETE"
FROM V$SESSION_LONGOPS
WHERE OPNAME LIKE 'RMAN%' AND OPNAME NOT LIKE '%aggregate%'
AND TOTALWORK != 0 AND SOFAR <> TOTALWORK;
浙公网安备 33010602011771号