oracle rman备份

时间:2021-08-07 06:06:09
rman  登录到cmd

打开cmd 输入 rman

connect target jhpt/1@orcl


oracle rman备份


C:\Documents and Settings\Administrator>rman catalog tangtang/lenovoE520 target system/lenovoE520@tang
RMAN>show all;
设置控制文件的自动备份和自动备份的目录(建议设置,备份目录自定)
RMAN>CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN>CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'F:\backup\%F';
RMAN>exit;
按如上设置后,控制文件和spfile就会随着数据库备份自动备份到d:/backup下;

建立脚本文件和批处理文件:
脚本文件,如文件名为orabackup.rcv,具体内容如下:
run {
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 0 database format 'F:\backup\level0_%d_%s_%p_%u.bak';
sql 'alter system archive log current';
backup archivelog all format 'F:\backup\log_%d_%s_%p_%u.bak' delete all input;
release channel d2;
release channel d1;
}
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
resync catalog;
exit

批处理文件,如文件名为orabackup.bat,具体内容如下
rman catalog rmanuser1/rmanuser1@orada target system/system@oradb CMDFILE 'F:\backup\orabackup.rcv' LOG ’F:\backup\oracl_%date'

将orabackup.bat和orabackup.rcv存放在同一目录下,执行orabackup.bat就可以调用orabackup.rcv备份数据库了,你可以再windows的计划任务里执行orabackup.bat就可以自动备份了;

编写自动处理脚本及dos批处理文件进行rman备份

1)确定备份策略及配置,编写rman备份脚本,保存至E:\rman_bak\rman_scr.sql

脚本代码:

run

{

configure retention policy to recovery window of 7 days;

configure controlfile autobackup on;

configure controlfile autobackup format for device type disk to 'F:\backup\%F';

allocate channel ch1 device type disk format 'F:\backup\%U';

backup database skip inaccessible filesperset 10

plus archivelog filesperset 20

delete all input;

release channel ch1;

}

allocate channel for maintenance device type disk;

crosscheck backupset;

delete noprompt obsolete;

2)编写dos批处理脚本 rman_src.bat

rman target / cmdfile='F:\backup\rman_scr.sql'>> F:\backup\log.txt

3)执行

可手工执行rman_src.bat进行备份;

或通过控制面板-> 任务计划中添加计划

WINDOWS 上做的

RMAN.sql内容如下:

run

{

configure retention policy to recovery window of 7 days;

configure controlfile autobackup on;

configure controlfile autobackup format for device type disk to 'c:\backupb\%F_%T';

allocate channel ch1 device type disk format 'C:\backupb\%T';

backup database skip inaccessible filesperset 10

plus archivelog filesperset 20

delete all input;

release channel ch1;

}

allocate channel for maintenance device type disk;

crosscheck backupset;

delete noprompt obsolete;

11.bat (批处理文件)

rman target / cmdfile='c:\backupb\rman.sql'>> c:\backupb\log.txt;

简单的注释

run

{

configure retention policy to recovery window of 7 days;

configure controlfile autobackup on;--控制文件的自动备份

configure controlfile autobackup format for device type disk to 'c:\backup\%F'; --控制文件目录

allocate channel ch1 device type disk format 'c:\backup\%U'; --备份集的目录

backup database skip inaccessible filesperset 10 --生成10个备份集

plus archivelog filesperset 20

delete all input;

release channel ch1; --释放备份通道

}

allocate channel for maintenance device type disk;

crosscheck backupset;

delete noprompt obsolete; --删除未找到已废弃的备份(根据备份策略 目前的策略是保存最近7天的)

在本机器上还原

RMAN> shutdown immediate

RMAN> startup mount;

RMAN>restore database; --还原  指物理意义的文件的还原

RMAN>recover database;--恢复 让数据一致

最后打开数据库

RMAN> alter database open

--还原某一个时期的备份

run{
allocate channel t1 device type disk;
set until time "to_date('2015-12-24 22:18:07','yyyy-mm-dd hh24:mi:ss')";
restore database;
recover database;}