ITPub博客

首页 > Linux操作系统 > Linux操作系统 > rman备份脚本(转)

rman备份脚本(转)

原创 Linux操作系统 作者:xudemin618 时间:2012-05-05 23:10:27 0 删除 编辑
使用catalog服务器,rman备份流程:

target 端需要做的工作:

root用户登录:
1、创建文件夹
mkdir /home/oracle/rman_backup
2、赋值权限
chown oracle:oinstall /home/oracle/rman_backup
chmod 770 /home/oracle/rman_backup

catolog 端需要做的工作:

建立target端的net服务:

mahanso =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.87)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ora11)
)
)


root用户登录:
创建文件夹
mkdir /home/oracle/backup
mkdir /home/oracle/backup/script
mkdir /home/oracle/backup/log
mkdir /home/oracle/backup/export

chown oracle:oinstall /home/oracle/*
chmod 770 /home/oracle/*

Oracle的sys用户登录创建各个对象:
--创建表空间
CREATE TABLESPACE rman_data
DATAFILE '/oracle/oradata/ora11/rman_data.dbf' SIZE 1024M UNIFORM. SIZE 128k;
--修改表空间自动扩展
ALTER DATABASE DATAFILE '/oracle/oradata/ora11/rman_data.dbf'
AUTOEXTEND ON NEXT 1M
MAXSIZE 1000M;
--创建临时边空间
create temporary tablespace rman_tmp
tempfile '/oracle/oradata/ora11/rman_tmp.dbf'
size 100M
autoextend on
next 32m maxsize 2048m
extent management local;

--创建用户
create user rman identified by rman
default tablespace rman _data
temporary tablespace rman _tmp;

--赋值连接和开发权限
grant connect,resource ,recovery_catalog_owner to rman ;
--推出Oracle的sys用户
exit


Oracle的rman连接catalog服务器:
rman catalog rman/rman

create catalog tablespace rman_data;
--连接target服务器:
onnect target sys/sys@mahanso(数据库连接target端标识符)
--在catalog中注册target的数据库的DBID
register database;
--查看报表
report schema;

注:
--基于冗余数量的备份策略
configure retention policy to redundancy 2;
--基于时间的备份策略
configure retention policy to recovery window of 7 days;


脚本:

--倒出RMAN用户数据脚本exp_rman.par (即备份catalog库)


userid=rman/rman
file=/home/oracle/backup/export/rman.dmp
log=/home/oracle/backup/log/rman.log


-- 倒出RMAN数据SHELL脚本exp_rman.sh
#!/bin/bash
cd $HOME
. .bash_profile
cd $HOME/backup/script
exp parfile=exp_rman.par

-- 零级备份RMAN脚本level0_backup.rcv
connect catalog rman/rman
connect target sys/sys@mahanso(数据库连接target端标识符)
run {

CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE CONTROLFILE AUTOBACKUP ON;

allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 0 database format '/home/oracle/rman_backup/level0_%d_%s_%p_%u.bak'
tag='level 0' include current controlfile;
sql 'alter system archive log current';
backup archivelog all format '/home/oracle/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;

--零级备份SHELL脚本的level0_backup.sh
#!/bin/bash
cd $HOME
. .bash_profile
cd $HOME/backup/script
rman cmdfile=level0_backup.rcv msglog=$HOME/backup/log/level0_backup.log
. /home/oracle/backup/script/exp_rman.sh

--一级差异增量备份RMAN脚本 level1_backup.rcv
connect catalog rman/rman
connect target sys/sys@mahanso(数据库连接target端标识符)
run {
allocate channel d1 type disk;
backup incremental level 1 format '/home/oracle/rman_backup/level1_%d_%s_%p_%u.bak' tag = 'level 1' database;
sql 'alter system archive log current';
backup archivelog all format '/home/oracle/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;

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

#!/bin/bash
cd $HOME
. .bash_profile
cd /home/oracle/backup/script
rman cmdfile=level1_backup.rcv msglog=$HOME/backup/log/level1.log
. /home/oracle/backup/script/exp_rman.sh

--二级差异增量备份RMAN脚本 level2_backup.rcv
connect catalog rman/rman
connect target sys/sys@mahanso(数据库连接target端标识符)
run {
allocate channel d1 type disk;
backup incremental level 2 format '/home/oracle/rman_backup/level2_%d_%s_%p_%u.bak' tag = 'level 2' database;
sql 'alter system archive log current';
backup archivelog all format '/home/oracle/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;

--二级差异增量备份SHELL脚本level2_backup.sh
#!/bin/bash
cd $HOME
. .bash_profile
cd /home/oracle/backup/script
rman cmdfile=level2_backup.rcv msglog=$HOME/backup/log/level2.log
. /home/oracle/backup/script/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;

linux下定时执行备份脚本

crontab -e -u oracle
SHELL=/bin/bash --以下脚本在bash下执行
MAILTO=oracle --执行日志以邮件形式邮给oracle用户,可以/var/spool/mail/oracle下查收
10 1 * * 0 /home/oracle/backup/script/level0_backup.sh
10 1 * * 1 /home/oracle/backup/script/level2_backup.sh
10 1 * * 2 /home/oracle/backup/script/level2_backup.sh
10 1 * * 3 /home/oracle/backup/script/level1_backup.sh
10 1 * * 4 /home/oracle/backup/script/level2_backup.sh
10 1 * * 5 /home/oracle/backup/script/level2_backup.sh
10 1 * * 6 /home/oracle/backup/script/level2_backup.sh

一周差异备份策略:
备份目标库和catalog库
周日0级全备,周一周二为2级,周三为1级,周四周五周六为2级。
每天凌晨1点10分开始备份

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

请登录后发表评论 登录
全部评论

注册时间:2008-11-18

  • 博文量
    28
  • 访问量
    112531