RMAN
$ sqlplus '/as sysdba'
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
备份时,数据库模式必须是归档必须是enabled的。
SQL> startup mount
SQL> alter database archivelog 切换到归档模式
===========================================================================================
$ rman或rman nocatalog
RMAN> connect target /
RMAN> list backupset;
打出为空就是没有备份。
RMAN> backup database; 全备份full backup database;
RMAN> show all;显示所有默认参数
============================================================================================
$ strings control03.ctl查看二进制文件,查看非catalog备份方式的日志。
============================================================================================
0级增量备份
RMAN> backup incremental level=0 database;
1级增量备份
RMAN> backup incremental level 1 database;
备份archivelog
RMAN> backup database plus archivelog delete input; (delete input的意思是,备份完成后,删除这个archivelog,plus archivelog是归档参数)
备份表空间
RMAN> report schema;(查看表空间)
RMAN> backup tablespace users
备份控制文件
RMAN>backup current controlfiles;(只备份控制文件)
RMAN>backup database include current controlfile;
===========================================================================================
RMAN的备份方式
备份集 backupset
镜像备份 Image copies
例: copy datafile ... to ...
============================================================================================
RMAN> copy datafile 5 to '/u01/rmanbak/tbs01bak.dbf';(此例中的5是对应的表空间编号,'/u01/rmanbak/tbs01bak.dbf'这个是为备份到的路径和名称)
RMAN> list copy;
============================================================================================
批命令
RMAN> run{
allocate channel cha1 type disk; (创建通道,type disk是指放到磁盘上,)
backup
format "/u01/rmanbak/full_%t"(指定存放目录 ,%t是指年月日)
tag full-backup (是指打一个标签)
database;
release channel cha1;
}
============================================================================================
format
%c 备份片的拷贝数(从1开始编号);
%d 数据库名称;
%D 位于该月中的天数 (DD);
%M 位于该年中的月份 (MM);
%F 一个基于DBID唯一的名称,这个格式的形式为c-xxx-YYYYMMDD-QQ,其中xxx为该数据库的DBID,YYYYMMDD为日期,QQ是一个1-256的序列;
%n 数据库名称,并且会在右侧用x字符进行填充,使其保持长度为8;
%u 是一个由备份集编号和建立时间压缩后组成的8字符名称。利用%u可以为每个备份集生成一个唯一的名称;
%p 表示备份集中备份片段的编号,从1开始编号;
%U 是%u_%p_%c的简写形式,利用它可以为每一个备份片段(即磁盘文件)生成一个唯一名称,这是最常用的命名方式;
%s 备份集的号;
%t 备份集时间戳;
%T 年月日格式(YYYYMMDD);
============================================================================================
密码文件丢失
$orapwd file=orapwherming password=password entries=5
============================================================================================
RMAN恢复
spfile丢失
RMAN> shutdown immediate;
RMAN> startup nomount;
RMAN> set dbid (dbid号)
RMAN> restore spfile from autobackup;(restore spfile from '/u01spfile备份文件路径)
RMAN> shutdown immeediate;
RMAN> set dbid (dbid号)
RMAN> startup;
============================================================================================
RMAN恢复
controlfile丢失
RMAN> shutdown immediate;
RMAN> startup nomount;
RMAN> set dbid (dbid号) (恢复controlfile可以不用)
RMAN> restore controlfile from autobackup;
RMAN> alter database mount;
RMAN> recover database;
RMAN> alter database open resetlogs;
redolog file丢失
RMAN> shutdown immediate;
RMAN> startup mount;
RMAN> alter database open resetlogs;
如果RMAN不成功可以使用sqlplus下恢复
sql> shutdown immediate;
SQL> startup mount;
SQL> recover database until cancel;
SQL> alter database open resetlogs;(清空后,最好做一次full backup database)
datafile 丢失
rman target /
RMAN> list scheam;
RMAN> report schema;
RMAN> sql "alter database datafile 5 offline";
RMAN> restore datafile 5;
RMAN> recover datafile 5;
RMAN> sql "alter database datafile 5 online";
表空间恢复
RMAN> sql "alter tablespace users offline";
RMAN> restore tablespace users;
RMAN> recover tablespace users;
RMAN> sql "alter tablespace users online";
实验
sql> select owner,table_name from all_tables where tablespace_name='表空间名';(查看有什么表)
sql> select * from 表;
RMAN> sql "alter tablespace tbs1 offline';(此句不成功,使用以下强制语句)
RMAN> sql "alter tablespace tbs1 offline immediate';
RMAN> restore tablespace tbs1;
RMAN> recover tablespace tbs1;
RMAN> sql "alter tablespace tbs1 online";
============================================================================================
非cactlog方式完全恢复
sqlplus '/as sysdba'
sql> shtudown abort;
$rman target /
RMAN> startup nomount;
RMAN> restore controlfile from autobackup;
RMAN> alter database mount;
RMAN> restore database;
RMAN> recover database;
RMAN> alter databse open resetlogs;
RMAN> recover database;出现问题,没有redo*.log时的恢复。
sql> create prifle from spfile;
*._allow_resetlogs_corruption='TURE' (initSID.ora)
SQL> shutdown immediate;
sql> startup pfile=/目录/insid.ora mount
sql> alter database open resetlogs;
============================================================================================
RMAN恢复
基于时间点的恢复
run{
set until time "to_date('07/01/02
15:00:00','mm/dd/yy hh24:mi:ss')"
restore dtabase;
recover database;
alter database open resetlogs;
}
============================================================================================
基于SCN的恢复
RMAN> startup mount;
RMAN> restore database UNTIL SCN 10000;
RMAN> recover database UNTIL SCN 10000;
RMAN> alter database open resetlogs;
基于日志序列恢复
SQL> select * from v$log;
RMAN>startup mount;
RMAN>restore database until sequence 100 thread 1;
RMAN>recover databae until sequence 100 thread 1;
RMAN> alter database open resetlogs;
============================================================================================
RMAN 恢复命令介绍
report schema
list backup
crosscheck backup
delete
============================================================================================
catalog备份方式
创建catalog所用表空间
SQL> create tablespace rman_ts datafile '' size 20M;
创建RMAN用户并授权
SQL> create user rman identified by rman default tablespace rman_ts quota unlimited on rman_ts;
SQL> grant recovery_catalog_owner to rman;
创建恢复目录
rman catalog rman/rman
RMAN> create ctatlog tablespace rman_ts;
RMAN> register database;
设置非归档方式
1 sql> archive log list; #查看是否是归档方式
2 sql> alter system set log_archive_start=false scope=spfile; #禁用自动归档
3 sql> shutdown immediate;
4 sql> startup mount; #打开控制文件,不打开数据文件
5 sql> alter database noarchivelog; #将数据库切换为非归档模式
6 sql> alter database open; #将数据文件打开
7 sql> archive log list; #查看此时便处于非归档模式
阅读(898) | 评论(0) | 转发(0) |