rman 笔记

来源:互联网 发布:淘宝店铺标语怎么改 编辑:程序博客网 时间:2024/06/02 03:06

1
target database   :sysdba privilege
recovery catalog  database: by default nocatalog mode,not by default 在control files 里
auxiliary辅助 database:

非catalog方式:
全备份
0级增量备份
1级增量备份
       find / -name rman
注意:
错linux中有两个rman 执行最上面的rman,必须设置path变量
对echo $PATH
echo $PATH
vi ./.bash_profile
PATH=$ORACLE_HOME/bin:$PATH
必须生效  exit   su - oracle 重新进去

//////////////
sqlplus /nolog
conn /as sysdba
archive log list
----start mount
----alter database archivelog
进入主题:
rman   回车
connect target/
rman nocatalog
list backupset;
backup database;full backup

2
show all;
quit
strings control.ctl
0级增量备份:和全备份的区别,几乎一样,全备份不能作为增量备份的基础,0级备份可以作为基础做1级增量备份
rman  nocatalog
connect target/
backup incremental level=0 database;
list backupset;

backup incremental level 1 database;
list backupset;
3

connect target user/passwd@sid如何配置TNSname.ora
connect target user/passwd
lsnrctl start  linux 下
lsnrctl service
connect target/代表当前数据库

startup rman下
备份archivelog
backup database plus archivelog delete input
备份tablespace
backup tablespace user

report schema
备份controlfile
backup current controlfile
backup database include current controlfile

backupset 备份集
image copies 镜像备份 copy datafile ...to ...
report schema

copy datafile 5 to '/u01/rmanbak/tbs01bak.dbf'
list copy;

4
单命令
backup database;
批命令
run{
allocate channel cha1 type disk;
backup
format "/u01/rmanbak/full_%t"
tag full-backup
database;
release chanel cha1;
}

df -h
ls -lh


5.
自动备份:备份脚本+crontab
bakl0
bakl1
ball2
执行脚本
rman target /msglog=bakl0.log cmdfile=bakl0
rman target /msglog=bakl1.log cmdfile=bakl1
rman target /msglog=bakl2.log cmdfile=bakl2
备份脚本:
vi :bakl0:
run{
allocate channel c1 type disk;
backup
incremental level 0
format "/u01/rmanbak/inc0_%u_%T"
tag monday_inc0
database;
release chanel c1;
}
vi :bakl1:
run{
allocate channel c1 type disk;
backup
incremental level 1
format "/u01/rmanbak/inc1_%u_%T"
tag monday_inc1
database;
release chanel c1;
}
vi :bakl2:
run{
allocate channel c1 type disk;
backup
incremental level 2
format "/u01/rmanbak/inc2_%u_%T"
tag monday_inc2
database;
release chanel c1;
}

rman target / msglog=/u01/rmanbak/bakl0.log cmdfile=/u01/rmanbak/script/bakl0

which rman
$ORALCE_HOME/product/10.2.0/db_1/bin/rman/rman

crontab -e -u oracle/编辑oracle用户的定时执行计划/rman中用到的路径尽量是全路径

whoami

45 23 * * 0 rman target / msglog=/u01/rmanbak/bakl0.log cmdfile=/u01/rmanbak/script/bakl0
45 23 * * 1 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/script/bakl2
45 23 * * 2 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/script/bakl2
45 23 * * 3 rman target / msglog=/u01/rmanbak/bakl1.log cmdfile=/u01/rmanbak/script/bakl1
45 23 * * 4 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/script/bakl2
45 23 * * 5 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/script/bakl2
45 23 * * 6 rman target / msglog=/u01/rmanbak/bakl2.log cmdfile=/u01/rmanbak/script/bakl2

重新启动crond
service crond restart

6.
catalog datadase/controlfile
nocatalog rman的恢复
1 Dbid
2 configure controlfile autobackup on;会备份spfile
2 backup database plus archivelog delete input;

rman target/出现DBID
show all;

list backup
delete backupset 24;


backup format '/u01/rman/bak/full_%T-%u.bak'database plus archivelog;

list backupset;
////////////////
恢复/
口令文件丢失
在linux中执行
orapwd file =orapwdsid  password=pass1234          entries=5

spfile丢失:在rman中执行
startup nomount;
set dbid 9815108
restore spfile from autobackup; restore spfile from 'u01/oracle/flash...bkp';
shutdown immediate;
set dbid 9815108;
startup;

 

controlfile丢失:
在rman中执行
shutdown abort;rman target/
startup nomount;
//set dbid 9815108
restore controlfile from autobackup;
alter database mount;
recover database;
alter database open resetlogs;

backup database;

 

rman >sql "select * from dual;";

 
online redolog file丢失:
在sqlplus /nolog中执行
shutdown immediate;
startup mount;
recover database until cancel;
alter database open resetlogs;


datafile丢失
rman target/
report schema;
3 是在rman backup里面的数字
sql"alter database datafile 3 offline";
restore datafile 3
recover datafile 3
sql"alter database datafile 3 online"

tablespace丢失
sql"alter tablespace users offline";sql"alter tablespace users offline immediate";
restore tablespace users
recover tablespace users
sql"alter tablespace users online"


select owner,table_name from all_tables where tablespace_name='TBS1'
非catalog 方式完全恢复
数据库出现问题
( startup nomount;
restore controlfile from autobackup;
alter database mount;
restore database;
recover database;online redolog file丢失:(create pfile from spfile;
vi pfile.ora
*._allow_resetlogs_corruption='TURE'
shutdown immediate
startup pfile=/u01/oracle/pu.../initsia.ora mount
alter database open resetlogs;)
alter database open resetlogs;)

///////////////
基于时间点的恢复
run{
set until time "to_date('07/01/02 15:00:00','mm/dd/yy hh24:mi:ss')'"
restore database;
recover database;
alter database open resetlogs;
}

基于SCN的恢复
startup mount;
restore database UNTIL SCN 10000;
recover database UNTIL SCN 10000;
alter database open resetlogs;

list backupset;
找个SCN

shutdown immediate
******
resetlogs 都是incompletely backup

基于日志序列的恢复
startup mount;
restore database UNTIL SEQUENCE 100 thread 1;
recover database UNTIL SEQUENCE 100 thread 1;
alter database open resetlogs;

select * from v$log; sequence#


report schema    rman --target database
list backup      rman --controlfile ,catalog database
crosscheck backup   ----list backup  auxiliary database /Disk/SBT Tape
delete backupset BKid

//////////////////
catalog mode:
创建catalog 所用的表空间
create tablespace rman_ts datafile '    ' size 20M;
create tablespace rman_ts datafile '    'reuse;
创建rman用户并授权
create user rman identified by rman default
tablespace rman_ts quota unlimited on rman_ts;
grant recovery_catalog_owner to rman;
---grant connect.resource to rman;
创建恢复目录
rman catalog rman/rman
create catalog tablespace rman_ts;
register database;
connect target/

quit
rman target / catalog rman/rman

backup format 'u01/rmanbak/full_%T_t.bak' database;


select * from dba_sys_privs where grantee='CONNECT'or grantee='RESOURCE';
select * from dba_sys_privs where grantee='RECOVERY_CATALOG_OWNER';

原创粉丝点击