oracle %p%u,Linux下自动执行Oracle数据库的备份

备份策略:

星期天 0 级

星期一,二,四,五,六 2 级

星期三 1 级

--创建本地管理路径

mkdir -p /dinglp/ora_managed/backup

mkdir -p /dinglp/ora_managed/backup

mkdir -p /dinglp/ora_managed/backup/export-

mkdir -p /dinglp/ora_managed/backup/log

mkdir -p /dinglp/ora_managed/backup/rman_backup

mkdir -p /dinglp/ora_managed/scripts

--创建rman表空间和rman用户

create tablespace rman_tbs datafile '/oradata/luke/rman_tbs01.dbf' size 1024M;

create user rman_dlp identified by dlp default tablespace rman_tbs temporary tablespace temp;

grant connect,resource ,recovery_catalog_owner to rman;

--注册catalog 数据库

rman catalog rman_dlp/dlp

create catalog tablespace rman_tbs;

connect target sys/dg@priamry

register database;

report schema;

--设置备份参数

configure retention policy to redundancy 2;

configure retention policy to recovery window of 7 days;

--以下是备份脚本(可以通过vi进行编辑)

dlp-> touch exp_rman.par

dlp-> touch exp_rman.sh

dlp-> touch rman_bk_LEVEL0.rcv   (数据库0级备份)

dlp-> touch rman_bk_LEVEL0.sh

dlp-> touch rman_bk_LEVEL1.rcv (数据库1级备份)

dlp-> touch rman_bk_LEVEL1.sh

dlp-> touch rman_bk_LEVEL2.rcv   (数据库2级备份www.linuxidc.com)

dlp-> touch rman_bk_LEVEL2.sh

--倒出RMAN用户数据脚本exp_rman.par

##################################################

###               exp_rman.par                 ###

##################################################

userid=rman_dlp/dlp

file=/dinglp/ora_managed/backup/export/rman.dmp

log=/dinglp/ora_managed/backup/log/rman.log

--倒出RMAN数据SHELL脚本exp_rman.sh

##################################################

###                 exp_rman.sh                ###

##################################################

#!/bin/bash

source /home/Oracle/.bash_profile

cd /dinglp/ora_managed/scripts

exp parfile=exp_rman.par

--零级备份RMAN脚本rman_bk_LEVEL0.rcv

connect catalog rman_dlp/dlp

connect target sys/dg@primary

run {

allocate channel d1 type disk;

allocate channel d2 type disk;

backup incremental level 0 database format '/dinglp/ora_managed/backup/rman_backup/level0_%d_%s_%p_%u.bak'

tag='level 0' include current controlfile;

sql 'alter system archive log current';

backup archivelog all format '/dinglp/ora_managed/backup/rman_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;

--零级备份SHELL脚本的rman_bk_LEVEL0.sh

#####################################################################

###                   rman_bk_LEVEL0.sh                           ###

#####################################################################

#!/bin/bash

source /home/Oracle/.bash_profile

cd /dinglp/ora_managed/scripts

rman cmdfile=rman_bk_LEVEL0.rcv msglog=$HOME/backup/log/rman_bk_LEVEL0.log

./dinglp/ora_managed/script/exp_rman.sh

--一级差异增量备份RMAN脚本rman_bk_LEVEL1.rcv

connect catalog rman_dlp/dlp

connect target sys/dg@primary

run {

allocate channel d1 type disk;

backup incremental level 1 format '/dinglp/ora_managed/backup/rman_backup/level1_%d_%s_%p_%u.bak' tag = 'level 1' database;

sql 'alter system archive log current';

backup archivelog all format '/dinglp/ora_managed/backup/rman_backup/log_%d_%s_%p_%u.bak' delete all input;

release channel d1;

}

crosscheck backup;

delete noprompt expired backup;

delete noprompt obsolete;

resync catalog;

exit;

--一级差异增量备份SHELL脚本rman_bk_LEVEL1.sh

#####################################################################

###                   rman_bk_LEVEL1.sh                           ###

#####################################################################

#!/bin/bash

source /home/Oracle/.bash_profile

cd /dinglp/ora_managed/scripts

rman cmdfile=rman_bk_LEVEL1.rcv msglog=/dinglp/ora_managed/backup/log/rman_bk_LEVEL1.log

. /dinglp/ora_managed/scripts/exp_rman.sh

--二级差异增量备份RMAN脚本rman_bk_LEVEL2.rcv

connect catalog rman_dlp/dlp

connect target sys/dg@primary

run {

allocate channel d1 type disk;

backup incremental level 2 format '/dinglp/ora_managed/backup/rman_backup/level2_%d_%s_%p_%u.bak' tag = 'level 2' database;

sql 'alter system archive log current';

backup archivelog all format '/dinglp/ora_managed/backup/rman_backup/log_%d_%s_%p_%u.bak' delete all input;

release channel d1;

}

crosscheck backup;

delete noprompt expired backup;

delete noprompt obsolete;

resync catalog;

exit;

--二级差异增量备份SHELL脚本rman_bk_LEVEL2.sh

#####################################################################

###                   rman_bk_LEVEL2.sh                           ###

#####################################################################

#!/bin/bash

source /home/Oracle/.bash_profile

cd /dinglp/ora_managed/scripts

rman cmdfile=rman_bk_LEVEL2.rcv msglog=/dinglp/ora_managed/backup/log/rman_bk_LEVEL2.log

. /dinglp/ora_managed/scripts/exp_rman.sh

--提高RMAN增量备份性能

alter database enable block change tracking using file '/u01/app/Oracle/admin/devdb/bdump/luke.log';

desc v$block_change_tracking;

--RMAN 动态视图

V$ARCHIVED_LOG             显示在数据库中已经创建、备份或清除的归档文件。

V$BACKUP_CORRUPTION    显示在备份集的备份过程中找到的损坏块。

V$COPY_CORRUPTION    显示映像复制过程中找到的损坏块。

V$BACKUP_DATAFILE    用于通过确定各数据文件中的块数来创建大小相同的备份集。通过它也可以找出数据文件中已损坏的块数。    V$BACKUP_REDOLOG    显示在备份集中存储的归档日志。

V$BACKUP_SET     显示已经创建的备份集。

V$BACKUP_PIECE    显示为备份集创建的备份片。

--如何监视复制进程

使用 SET COMMAND ID 命令可将服务器会话与通道联系起来。

查询 V$PROCESS 和 V$SESSION,可以确定会话与哪些 RMAN 通道对应。

查询 V$SESSION_LONGOPS,可以监视备份和复制的进度。

--linux下自动运行备份脚本

crontab格式简介

第1列分钟1~59

第2列小时1~23(0表示子夜)

第3列日1~31

第4列月1~12

第5列星期0~6(0表示星期天)

第6列要运行的命令

[root@dlp ~]# vi /etc/crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

HOME=/

# run-parts

01 * * * * root run-parts /etc/cron.hourly

02 4 * * * root run-parts /etc/cron.daily

22 4 * * 0 root run-parts /etc/cron.weekly

42 4 1 * * root run-parts /etc/cron.monthly

00 22 * * 0 root /dinglp/ora_managed/scripts/rman_bk_LEVEL0.sh

00 22 * * 3 root /dinglp/ora_managed/scripts/rman_bk_LEVEL1.sh

00 22 * * 1,2,4,5,6 root /dinglp/ora_managed/scripts/rman_bk_LEVEL2.sh

--完毕,RYOHEI,2010-08-04。

本文出自:亿恩科技【www.enkj.com】

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值