RMAN基本操作代码

LINUX>    rman
RMAN>    connect target /
RMAN>    connect catalog rman/rman@rmandb;
RMAN>    create catalog tablespace rman_data;
RMAN>    register database;
RMAN>    list incarnation;
RMAN>    report schema;
RMAN>    set snapshot controlfile name to '/opt/app/oracle/product/10.2.0/db_1/dbs/snap_terrydb1.ctl';
RMAN>    resync catalog;

#rman script
run{
allocate channel d1 type disk;
copy
datafile 1 to '/u04/terry/rmanstudy/rman_bk_copy/system01.dbf.bk',
datafile 2 to '/u04/terry/rmanstudy/rman_bk_copy/undotbs01.dbf.bk',
datafile 3 to '/u04/terry/rmanstudy/rman_bk_copy/sysaux01.dbf.bk',
datafile 4 to '/u04/terry/rmanstudy/rman_bk_copy/users01.dbf.bk',
datafile 5 to '/u04/terry/rmanstudy/rman_bk_copy/wip_tracking_data01a.dbf.bk',
datafile 6 to '/u04/terry/rmanstudy/rman_bk_copy/sfism4_data01a.dbf.bk',
current controlfile to '/u04/terry/rmanstudy/rman_bk_copy/backup.ctl';
}

#generate rman script. with sqlplus
set feedback off pagesize 0 heading off verify off
set linesize 100 trimspool on
define dir='/u04/terry/rmanstudy/rman_bk_copy/sqlscriptrman/'
define fil='/u04/terry/rmanstudy/rman_bk_copy/sqlscriptrman/rmanscript.ora'
define div='/'
spool &fil
prompt run {
prompt allocate channel d1 type disk;;
prompt copy
select 'datafile '||file#||' to '||'''&dir.'||substr(name,(instr(name,'&div',-1)+1))||'.bak.sql'',' from v$datafile;
prompt current controlfile to '&dir.backup.ctl.sql';};
spool off;

#incremental level 0
run {
allocate channel d1 type disk;
backup
  incremental level 0
  format '/u04/terry/rmanstudy/rman_bk_wholeinc0/db_%d_%s_%p_%t'
  tag='WHOLE_INC0'
database;
}

#backup close
shutdown immediate;
startup mount;
run {
allocate channel d1 type disk;
allocate channel d2 type disk;
backup
  incremental level 0
  format '/u04/terry/rmanstudy/rman_bk_close/db_%d_%s_%p_%t'
  tag = 'WHOLE_INC0_CLOSED'
database;
};
sql "alter database backup controlfile to ''/u04/terry/rmanstudy/rman_bk_close/backup.ctl''";
alter database open;

#rman archivelog
run {
  allocate channel d1 type disk;
  sql "alter system archive log current";
  backup
    format '/u04/terry/rmanstudy/rman_bk_arch/ar_%d_%s_%p_%t'
    tag = 'ARCH_LOG_ALL'
  archivelog all;
}
list backupset(backup) of archivelog all ;

#LIST command
RMAN> list backup;
RMAN> list backup of database;
RMAN> list backup of tablespace 'SYSTEM','USERS';
RMAN> list backup of datafile 1,3,7;
RMAN> list backup of datafile
2>    '/oradata/db/system01.dbf',
3>    '/oradata/db/user01.dbf';

RMAN> list copy;
RMAN> list copy of database;
RMAN> list copy of tablespace 'SYSTEM','USERS';
RMAN> list copy of datafile 1,3,7;
RMAN> list copy of datafile
2>    '/oradata/db/system01.dbf',
3>    '/oradata/db/user01.dbf';

RMAN> list copy of control file;

RMAN> list backup of archivelog all;
RMAN> list backup of archivelog like '%oradata%';
RMAN> list backup of archivelog from time 'sysdate-14';
RMAN> list backup of archivelog until time 'sysdate-7';
RMAN> list backup of archivelog from time 'sysdate-14' until time 'sysdate-7';
RMAN> list backup of archivelog from scn 100000;
RMAN> list backup of archivelog until scn 110000;
RMAN> list backup of archivelog from scn 100000 until scn 110000;
RMAN> list backup of archivelog from logseq 130;
RMAN> list backup of archivelog until logseq 139;
RMAN> list backup of archivelog from logseq 130 until logseq 139;

RMAN> list backup completed after 'sysdate-14';
RMAN> list backup completed before 'sysdate-7';
RMAN> list backup completed between 'sysdate-14' and 'sysdate-7';
RMAN> list backup tag=WHOLE_INC0;
RMAN> list backup recoverable;
RMAN> list backup device type disk;
RMAN> list copy like '%system%';
RMAN> list backup completed after 'sysdate-14'
2>    tag=WHOLE_INC0
3>    device type disk
4>    recoverable;
RMAN> list backup of tablespace 'RBS'
2>    completed after 'LAST_DAY(ADD_MONTHS(SYSDATE,-1))+1'
3>    tag=WHOLE_INC0
4>    device type disk;

RMAN> list backup completed after 'sysdate-21';
RMAN> list backup of controlfile completed after 'sysdate-21';
RMAN> list backup of archivelog all completed after 'sysdate-21';
RMAN> list backup of of archivelog from logseq 130 until logseq 139
2>    completed after 'sysdate-21';
RMAN> list backup recoverable until time 'sysdate-21';

#REPORT command
RMAN> report need backup days 2 database;
RMAN> report need backup incremental 3 database;
RMAN> report unrecoverable;
RMAN> report schema;
RMAN> report schema at time 'sysdate-7';
RMAN> report schema at time "to_date('20080101','yyyymmdd')";
RMAN> report schema at scn 1000;
RMAN> report schema at logseq 131;

#RMAN Skill

#caution
RESETLOGS option only valid after an incomplete database recovery

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10742223/viewspace-364838/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10742223/viewspace-364838/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值