linux下的rman自动备份脚本,LINUX上RMAN自动备份脚本 - 一

1. 建备份目录 oradataback,2级目录archback(放归档日志)、rmanscripts(备份脚本),

在rmanscripts下面建  rmanlevel0.sh  rmanlevel1.sh  rmanlevel2.sh 文件:

mkdir oradataback

--home/oracle/app/oradataback

chmod 775 oradataback

chown -R oracle:oinstall /home/oracle/app/oradataback

touch  rmanlevel0.sh  rmanlevel1.sh  rmanlevel2.sh

赋权同上

2. vi 编辑3个文件:

0级备份文件:

--rmanlevel0.sh--

#!/bin/sh

source ~/.bash_profile

# set porfile_env

export ORACLE_SID=eytdbs # rman level0 backup

rman log='/home/oracle/app/oradataback/db_rman0.log' append <

connect target /;

run

{

allocate channel c1 type disk;

#allocate channel c2 type disk;

backup as compressed backupset incremental level=0 database format '/home/oracle/app/oradataback/db_level0_%T_%U' tag='level0';

sql 'alter system archive log current';

backup archivelog all format '/home/oracle/app/oradataback/archback/db_arch_%T_%U' delete input;

release channel c1;

#release channel c2;

}

EOF

1级备份文件:

--rmanlevel1.sh--

#!/bin/sh

source ~/.bash_profile

# set porfile_env

export ORACLE_SID=eytdbs  # rman level1 backup

rman log='/home/oracle/app/oradataback/db_rman1.log' append <

connect target /;

run

{

allocate channel c1 type disk;

#allocate channel c2 type disk;

backup incremental level= 1 database format '/home/oracle/app/oradataback/db_level1_%T_%U' tag='level1';

sql 'alter system archive log current';

backup archivelog all format '/home/oracle/app/oradataback/archback/db_arch_%T_%U' delete input;

release channel c1;

#release channel c2;

delete noprompt  obsolete;    # 删除过期的备份

}

EOF

2级备份文件:

--rmanlevel2.sh--

#!/bin/sh

source ~/.bash_profile

# set porfile_env

export ORACLE_SID=eytdbs  # rman level0 backup

rman log='/home/oracle/app/oradataback/db_rman2.log' append <

connect target /;

run

{

allocate channel c1 type disk;

#allocate channel c2 type disk;

backup incremental level=2 database format '/home/oracle/app/oradataback/db_level2_%T_%U' tag='level2';

sql 'alter system archive log current';

backup archivelog all format '/home/oracle/app/oradataback/archback/db_arch_%T_%U' delete input;

release channel c1;

#release channel c2;

}

EOF

#说明:在oracle用户下手动运行脚本的命令:sh rmanlevel2.sh

3. 加自动运行任务:

在root下设置,用vi编辑: #crontab -e

0 2 1 * * su � oracle -c /home/oracle/app/oradataback/rmanscripts/rmanlevel0.sh  //每月1日2:00运行 0级备份

0 2 * * 0 su � oracle -c /home/oracle/app/oradataback/rmanscripts/rmanlevel1.sh  //每周日2:00运行 1级备份

0 2 * * 1-6 su � oracle -c /home/oracle/app/oradataback/rmanscripts/rmanlevel2.sh  //每周一周六2:00运行 2级增量备份

--查看添加的任务: crontab   -l

--crontab的格式:

minutes|hours|day of month|month|day of week|

--启动crond:

/sbin/service crond start //启动服务

/sbin/service crond stop //关闭服务

/sbin/service crond restart //重启服务

/sbin/service crond reload //重新载入配置

4. 测试结果:

可以自动运行,能成功的备份数据。

--附加一个ftp.sh文件:

#!/bin/sh

cd /home/oracle/app/oradata    #本地目录

tar -czf oradata`date +%Y%m%d`_217.tar.gz  /home/oracle/app/oradata/

cd /home/oracle/app/fast_recovery_area/eytdbs  #本地目录

tar -czf oralog`date +%Y%m%d`_217.tar.gz  /home/oracle/app/fast_recovery_area/eytdbs/

#登陆远端机器

sftp oracle/@10.1.4.200 << EOF

cd /home/oracle   #远端目录

put /home/oracle/app/oradata/oradata`date +%Y%m%d`_217.tar.gz

put /home/oracle/app/fast_recovery_area/eytdbs/oralog`date +%Y%m%d`_217.tar.gz

quit

EOF

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值