Chinaunix首页 | 论坛 | 博客
  • 博客访问: 58615
  • 博文数量: 31
  • 博客积分: 25
  • 博客等级: 民兵
  • 技术积分: 280
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-28 06:36
个人简介

还在学习oracle的路上。

文章分类

全部博文(31)

文章存档

2020年(9)

2018年(3)

2017年(6)

2016年(11)

2015年(2)

我的朋友

分类: Oracle

2016-06-24 14:20:14

前提,rman  备份的设置中有一个保留备份份数的设置,请自行根据您的orale环境进行设置。我的默认的是设置了15份。

rman    配置保留的备份数
rman   target   /
configure   retention  policy  to redundancy 15;---(默认是1)

先是Linux 版本的

#!/bin/bash
source ~/.bash_profile
backuptime='date+"20%y%m%d%H%M%S"'
rman target / log=/dbbackup/log/backupall_$backuptime.log < run{
sql 'alter system switch logfile';
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
allocate channel c5 device type disk;
crosscheck   backup;
sql 'alter system archive log current';
backup database format '/dbbackup/db/db__%d_%T_%U';
sql 'alter system archive log current ';
backup spfile format '/dbbackup/spfile/spfile_%d_%T_%U';
backup archivelog all format '/dbbackup/logback/arc_%d_%T_%U' delete all input;
backup current controlfile format '/dbbackup/controlfileback/cntrl_%d_%T_%U';
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt obsolete;
delete noprompt backup of  database completed before 'sysdate - 30' ;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
}
exit
EOF
echo "backup is  completer!"



以下是 Windows 版本的



bat 文件内容
set NLS_DATE_FORMAT=yyyy-mm-dd  hh24:mi:ss
set currenttime=%date:~0,4%%date:~5,2%%date:~8,2%
set logtime=%date:~0,4%_%date:~5,2%_%date:~8,2%_%time:~0,2%_%time:~3,2%_%time:~6,2%
set oracle_sid=orcl
rman target  /  cmdfile=c:\oracle\run.txt  log=c:\oracle\%logtime%.log
pause

run.txt   内容
run{
allocate  channel   c1  device type disk;
allocate  channel   c2  device type disk;
backup database  tag 'dbfull' format  'c:\oracle\db_%T_%U.bak';
backup archivelog all  format 'c:\oracle\log_%T_%U.bak' delete all input;
delete noprompt  obsolete;
release channel c1;
release channel c2;
}
exit;


新版run内容

run{
allocate  channel   c1  device type disk;
allocate  channel   c2  device type disk;
allocate  channel   c3  device type disk;
sql 'alter system switch logfile';
backup database  tag 'dbfull' format  'C:\app\rman\dbbackup\bbmsdb_%T_%U.bak';
backup pluggable database pb1 tag 'pb1' format  'C:\app\rman\dbbackup\pb1_%T_%U.bak';
backup pluggable database pb2 tag 'pb2' format  'C:\app\rman\dbbackup\pb2_%T_%U.bak';
backup archivelog all  format 'C:\app\rman\dbbackup\bbms_log_%T_%U.bak' delete all input;
BACKUP SPFILE  format 'C:\app\rman\dbbackup\SPFILE_%T_%U.bak';
BACKUP CURRENT CONTROLFILE  format 'C:\app\rman\dbbackup\CONTROLFILE_%T_%U.bak';
delete noprompt  obsolete;
release channel c1;
release channel c2;
release channel c3;
}
exit;



总结:以上两个脚本,一个是Linux的,linux的那个我已经测试过了,运行没有问题,如果您要使用我的脚本,建议您先在测试库上测试一遍,因为环境不同,可能运行起来还是会有一定问题的。
那个Windows版本的是我们生产上使用的脚本。先要把bat内容写入到一个文件中,然后去调用run的文件。根据您的环境请自行设置。



阅读(609) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~