RMAN常用命令汇总!
进入RMAN:
$ rman target sys/oracle@orcl --远程连接到rman
$ rman target sys/oracle@orcl @backup_db.ram --远程连接到rman并执行指定脚本
$ rman target sys/oracle@orcl cmdfile=backup_db.ram --远程连接到rman并执行指定脚本
$ rman target / log rman.log --记录rman的输出
RMAN> @backup_db.ram --rman里面执行脚本
备份命令:
RMAN> backup database format '.../%d_%U'; --备份数据库并指定备份路径
RMAN> backup database; --备份数据库
RMAN> backup database include current controlfile plus archivelog delete all input; --备份数据文件、控制文件、归档日志
RMAN> backup incremental level 0 database; --差异增量备份数据库
RMAN> backup incremental level 0 cumulative database; --累积增量备份数据库
RMAN> backup as compressed backupset database; --压缩备份数据库
RMAN> backup database include current controlfile; --备份数据库并备份控制文件
RMAN> backup tablespace users; --备份表空间
RMAN> backup datafile n; --备份数据文件
RMAN> backup datafiel '/opt/oracle/oradata/orcl/users01.dbf'; --备份数据文件
RMAN> backup current controlfile; --备份控制文件
RMAN> backup current controlfile plus archivelog; --备份控制文件并归档然后备份归档日志
RMAN> backup archivelog all; --备份归档日志
RMAN> backup archivelog all delete all input; --备份归档日志并删除
RMAN> backup spfile; --备份参数文件
RMAN> backup backupset all; --备份全部备份集
RMAN> backup backupset n; --备份指定备份集
还原、恢复命令:
RMAN> restore database; --还原数据库
RMAN> restore tablespace users; --还原表空间
RMAN> restore datafile n; --还原数据文件
RMAN> restore archivelog sequence between 10 and 20; --还原归档日志
RMAN> restore controlfile from autobackup; --还原控制文件
RMAN> restore spfile to '/tmp/spfile.ora' from autobackup; --还原参数文件
RMAN> recover database; --恢复数据库
RMAN> recover tablespace users; --恢复表空间
RMAN> recover datafile n; --恢复数据文件
RMAN> restore validate database; --验证数据库可恢复性
RMAN> restore validate controlfile; --验证控制文件可恢复性
RMAN> restore validate spfile; --验证参数文件可恢复性
查看备份集命令:
RMAN> list backup; --列出数据库中所有的备份集
RMAN> list backup of database; --查看数据库备份集
RMAN> list backup of tablespace users; --查看表空间备份集
RMAN> list backup of datafile n; --查看备份的数据文件
RMAN> list backup of controlfile; --查看控制文件备份集
RMAN> list backup of archivelog all; --查看归档日志备份集
RMAN> list archivelog all; --查看当前所有归档日志
RMAN> list expired backup; --列出所有无效备份
管理备份集命令:
RMAN> crosscheck backup; --检查所有备份集
RMAN> crosscheck archivelog all; --检查所有归档文件
RMAN> delete [noprompt] obsolete; --删除过期备份
RMAN> delete expired backup; --删除无效备份
RMAN> delete expired archivelog all; --删除所有无效归档文件
RMAN> delete backupset 1; --删除指定备份
RMAN> delete backup; --删除所有备份
RMAN> change backupset 3 unavailable; --更改备份集3为无效
RMAN> change backupset 3 available; --更改备份集3为有效
RMAN> change backup of controlfile unavailable; --更改控制文件为无效
RMAN> change backup of controlfile available; --更改控制文件为有效
RMAN> report schema; --查看数据库备份结构
RMAN> report need backup; --查看所以需要备份的文件
RMAN> report need backup tablespace system; --查看指定表空间是否需要备份
RMAN> report obsolete; --查看过期备份
LIST命令:
1.数据库拷贝列表:RMAN> list incarnation;
2.备份清单:RMAN> list backup summary;
说明:B表示backup,F表示FULL,A表示Archive log,0 1表示incremenal backup,
S说明备份状态(A:AVAILABLE, X:EXPIRED)
按备份类型:RMAN>list backup by file;
3.列出过期备份:RMAN> list expired backup;
4.列出备份集及数据文件副本
RMAN> list backup of database;
RMAN> list backup of datafile
"D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\EXAMPLE01.DBF";
5.列出指定表空间的备份集及数据文件副本
RMAN> list copy of tablespace "SYSTEM";
6.列出归档日志备份
RMAN>list archivelog all; --简要信息
RMAN>list backup of archivelog all; --详细信息
列出固定范围内的归档日志备份:
RMAN> list copy of database archivelog
from time='SYSDATE-7';
7.列出控制文件和服务器参数文件
RMAN>list backup of controfile;
RMAN>list backup of spfile;
*****************************************
REPORT命令:
1.数据库:RMAN> report schema;
RMAN> report schema;time ‘sysdate-10’;
RMAN> report schema at scn 100;
RMAN> report schema at sequence 100 thread 1;
2.哪些文件需要备份:RMAN> report need backup;
2.1恢复时需要的增量备份个数超过超过3次的数据文件列表:
RMAN> report need backup incremental (=) 3 (database);
2.2超过3天没有备份的文件列表:
RMAN> report need backup days (=) 3 (tablespace perfstat);
2.3备份文件低于2份的文件列表:
RMAN> report need backup redundancy (=) 2;
2.4恢复需要3超过3天的归档日志的数据文件列表:
RMAN> report need backup recovery window of 3 days;
3.无法恢复作业的列表:RMAN> report unrecoverable;
4.作废的备份列表:
RMAN> report obsolete;
RMAN> report
obsolete redundancy 2;-- 备份次数超过两次的陈旧备份列表
RMAN> report
obsolete recovery window of 3 days;
****************************************
DELETE命令
1.删除作废的备份:RMAN> delete obsolete;
RMAN>
delete obsolete redundancy 2;
2.删除过期副本:RMAN> delete (noprompt) expired copy;
3.删除特定备份集:RMAN> delete backupset 19;
4.删除特定备份片:RMAN> delete backuppiece “….bak”;
5.删除所以备份集:RMAN> delete backup;
6.删除特定映像副本:RMAN> delete datafilecopy “….bak”;
7.删除所有映像副本:MAN> delete copy;
8.删除备份集:RMAN> delete backupset 10;
9.备份后删除输入对象:RMAN> backup archivelog all delete input;
10.删除备份索引键为4的备份集:RMAN> delete backupset 4;
*********************************************
CROSSCHECK命令:校验备份信息
备份集有两种状态:A(AVAILABLE,RMAN认为该项存在于备份介质上),X(EXPIRED, 备份
存在于控制文件或恢复目录中,但并没有物理存在于备份介质上)。
CROSSCHECK的目的是检查RMAN的目录以及物理文件,如果物理文件不存在于介质上,
将标记为Expired;如果物理文件存在,将维持Available;如果原先标记为Expired的备份
集再次存在于备份介质上(如恢复力损坏的磁盘驱动器后),crosscheck将把状态重新从
Expired
标记回Available。
crosscheck 输出分两部分。第一部分列出确定存在于备份介质上的所有备份集片,
第二部分列出不存在于备份介质上的备份集片,并将其标记为Expired。当设置备份保存
策略后,一个备份过期,crosscheck之后标记为丢弃的备份状态依旧为availabel,要删除丢弃备份
delete obsolete。
1.RMAN>
crosscheck backup 核对所有备份集;
2.RMAN> crosscheck backup of database; -- 核对所有数据文件的备份集
3.RMAN> crosscheck backup of tablespace users;--核对特定表空间的备份集
4.RMAN> crosscheck backup of datafile 4;-- 核对特定数据文件的备份集
5.RMAN> crosscheck backup of controlfile;-- 核对控制文件的备份集
6.RMAN> crosscheck backup of spfile;-- 核对SPFILE的备份集
7.RMAN> crosscheck backup of archivelog sequence 3; -- 核对归档日志的备份集
8.RMAN> crosscheck copy;-- 核对所有映像副本
9.RMAN> crosscheck copy of database;-- 核对所有数据文件的映像副本
10.RMAN> crosscheck copy of tablespace users;-- 核对特定表空间的映像副本
11.RMAN> crosscheck copy of datafile 6; --核对特定数据文件的映像副本
12.RMAN> crosscheck copy of archivelog sequence 4;-- 核对归档日
志的映像副本
13.RMAN> crosscheck copy of controlfile;-- 核对控制文件的映像副本
14.RMAN> crosscheck backup tag='SAT_BACKUP';
15.RMAN> crosscheck backup completed after 'sysdate - 2'
16.RMAN> crosscheck backup completed between 'sysdate - 5' and
'sysdate -2 '
17.RMAN> crosscheck backup device type sBT;
18.RMAN> crosscheck archivelog all;
19.RMAN> crosscheck archivelog like '%ARC00012.001'
20.RMAN> crosscheck archivelog from sequence 12;
21.RMAN> crosscheck archivelog until sequence 522;
************************************************
VALIDATE命令
验证备份集片是否能够被还原:
RMAN> validate backupset 1;
可先执行RMAN> list backup summary;得到备份集索引键
**********************************************
CHANGE命令
改变备份记录的状态:
RMAN> backup as copy format='D:\oracle\product\10.2.0\oradata\
OMF\ORCL\backup\df_5.dbf' datafile 5;
RMAN> change datafilecopy 'D:\oracle\product\10.2.0\oradata\OM
F\ORCL\backup\df_5.dbf' unavailable;
RMAN>change backupset 2 unavailable;
RMAN>change backupset 10 keep forever logs;
RMAN>change backupset 200 keep until time ‘sysdate+60’ logs;
RMAN>change backupset 20 nokeep;
********************************************
CATALOG命令(需要建立了恢复目录数据库才可以使用)
追加备份记录到RMAN资料库
RMAN>catalog datafilecopy ‘….bak’;
RMAN>catalog backuppiece ‘….dbf’;
RMAN>catalog start with ‘d:\’;
#注销
RMAN>change datafilecopy ‘….bak’ uncatalog;
RMAN>change controlfilecopy ‘‘….ctl’ uncatalog;
RMAN>change backuppiece ‘….bak’ uncatalog;