ORACLE RMAN备份恢复
1、查询RMAN命令
find / -name rman
查看环境变量
su - oracle
echo $PATH
修改oracle环境变量,把linux的RMAN 路径修改到ORACLE后边
PATH=$ORACLE_HOME/bin:$PATH
2、重看oracle是否归档
SQL>sqlplus / nolog
conn / as sysdba
archive log list ;
修改为归档模式
首先数据库打开到mount
startup mount;
alter database archivedlog;
alter database open;
3、进入RMAN查看备份情况
rman nocatalog
connect target /
查看全备份
list backupset;
show all;查看db_db_unique_name为数据库RMAN配置的参数
4、0级备份(相当于全备)
backup incremental level=0 database;
backup incremental level 0 database;
1级备份
backup incremental level=1 database;
backup incremental level 1 database;
查看controlfile文件
$strings control01.ora
5、备份archivelog
backup database plus archivelog delete input;
6、备份表空间
查看有哪些user
report schema;
backup tablespace user;
7、备份控制文件
backup current controlfile;
backup database unclude current controlfile;(包括当前控制文件)
8、备份集
backupset
备份镜像
copy datafile 5 to '/u01/rmanbak/tbs01bak.dbf'
9、备份
单命令
backup database;
批命令
run{
allocate channel cha1 type disk;
backup
format '/u01/rmanbak/full_%T'
tag full_backup (tag 打个标签)
database;
release channel cha1
}
channel 通道 cha1 通道名字 fromat 备份路径、名字设定
10、备份脚本
自动备份:备份脚本+crontab定时任务
备份案例
星期天晚上 -levle 0 backup performed
星期一晚上 -level 2 backup performed
星期二晚上 -level 2 backup performed
星期三晚上 -level 1 backup performed
星期四晚上 -level 2 backup performed
星期五晚上 -level 2 backup performed
星期六晚上 -level 2 backup performed
脚本:bakl0、bakl1、bakl2
执行脚本
rman target / msglog=bakl0.log cmdfile=bakl0
rman target / msglog=bakl1.log cmdfile=bakl1
rman target / msglog=bakl2.log cmdfile=bakl2
bakl0(0级备份)
run{
allocate channel c1 type disk;
backup incremental level 0
format '/u01/rmanbak/inc0_%u_%T'
tag monday_inc0
database;
release channel c1
}
bakl1(1级备份)
run{
allocate channel c1 type disk;
backup incremental level 1
format '/u01/rmanbak/inc1_%u_%T'
tag monday_inc1
database;
release channel c1
}
bakl2(2级备份)
run{
allocate channel c1 type disk;
backup incremental level 2
format '/u01/rmanbak/inc2_%u_%T'
tag monday_inc2
database;
release channel c1
}
crontal 定时任务
root>#crontan -e -u oracle
45 23 * * 0 rman target / msglog=/u01/rmanbak/bakl0.log cmdfile=/u01/rmanbak/bakl0
45 23 * * 1 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/bakl2
45 23 * * 2 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/bakl2
45 23 * * 3 rman target / msglog=/u01/rmanbak/bakl1.log cmdfile=/u01/rmanbak/bakl1
45 23 * * 4 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/bakl2
45 23 * * 5 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/bakl2
45 23 * * 6 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/bakl2
启动
service crontab restart
11、恢复
1、口令文件丢失
$orapwd file=orapwdsid password=pass entries=5
2、spfile文件丢失
rman>shutdown immediate
startup nomount;
set dbid 15335399566
restore spfile from autobackup;
restore spfile from '/u01/rmanbak/备份路径'
关闭数据库
shutdown immediate
startup
不能正常启动 set dbid 15335399566
3、controlfile文件丢失
startup nomount;
restore controlfile from autobackup;
alter database mount;
recover database
alter database open resetlogs
4、redolog file丢失
SQL>shutdown abort
startup mount;
recover database until cancel
alter database open resetlogs;
5、datafile文件丢失
alter database datafile 3 offline;
rman target /
resport schema
sql "alter database datafile 5 offline";
restore datafile 5;
recover datafile 5;
sql "alter database datafile 5 online";
6、表空间丢失(1、首先使要恢复的表空间offline,然后进行restore、recover 最后表空间online)
RMAN>sql "alter tablespace users offline immediate";
restore tablespace users;
recover tablespace users;
sql "alter tablespace users online";
12、非catalog方式完全恢复
步骤1、先恢复controlfile2、restore 、recover 3、打开数据库
startup nomunt;
restore controlfile from autobackup;
alter database mount;
restore database;
recover database until cancel;
alter database open resetlogs;(在缺失redo在线日志情况下不能正常启动)需执行以下操作
在mount下
create pfile from spfile;
编辑pfile文件
*._allow_reserlogs_corruption='TURE'
存盘退出,进入SQL,关闭数据库,用pfile启动
shutdown immediate;
startup pfile=/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora mount
alter database open resetlogs;
13、基于时间点的恢复
run{
set until time "to_date('07/01/02 15:00:00','mm/dd/yy hh 24:mi:ss')"
restore database;
recover database until cancle
alter database open resetlogs;
}
14、基于scn的恢复(rman,会产生数据丢失)做完后需要进行全备份
startup mount;
restore database until scn ;
recover database until scn;
alter database open resetlog;
15、基于日志序列恢复
startup mount;
restore database until sequence 100 thread 1;
recover database until sequence 100 thread 1;
alter database open resetlogs;
16、catalog mode
创建catalog所用表空间
create tablespace rman_ts datafile '/u01/rman.dbf' size 20M;
创建RMAN用户并授权
create user rman indetified by rman default tablespace rman_ts quota unlimited on rman_ts;
grant recovery_catalog_owner to rman
grant connect to rman
创建恢复目录
rman catalog rman/rman
create catalog tablespace rman_ts;
register database;
怎么连接
rman target / catalog rman/rman
backup database;
backup format '/u01/rmanbak/full_%u_%t.bak' database
如有什么问题,欢迎评论讨论,谢谢!!!