rman  生产全备脚本 expdp备份用户脚本


expdp逻辑备份脚本:

#!/bin/bash

ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

export ORACLE_HOME

ORACLE_SID=DAAS2

export ORACLE_SID

PATH=$PATH:$HOME/bin:/usr/bin:/bin:/usr/sbin:/usr/local/bin:$ORACLE_HOME/bin

export PATH


schmasname=(gsinfo datamart)

name=$(date +%Y%m%d)

DATE=$(date +%Y%m%d --date '7 days ago')

for user in ${schmasname[*]}

do 

expdp \'/ as sysdba\' directory=dudir dumpfile=$user-$name.dmp logfile=$user-$name.log  schemas=$user

cd /backup/data

tar zcvf $user-$name.tar.gz $user-$name.dmp

rm -rf $user-$name.dmp

rm $user-$DATE.tar.gz

rm $user-$DATE.log

done


rman物理备份脚本:


source /home/oracle/.bash_profile

name=$(date +%Y%m%d)

DATE=$(date +%Y%m%d --date '3 days ago')


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

######################create directory #####################

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

cd /backup/RmanBackup

if  [ -d $name ];

then

rm -rf $name

fi

if [ ! -d $name ];then

mkdir $name

fi

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

##################backup database ############################

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

source /home/oracle/.bash_profile

rman target /  log /backup/RmanBackup/rman_full_$name.log<

run {

allocate channel c1 type disk;

allocate channel c2 type disk;

allocate channel c3 type disk;

allocate channel c4 type disk;

backup database format '/backup/RmanBackup/$name/full_%d_%t_%s_%p';

sql'alter system archive log current';

backup archivelog all format '/backup/RmanBackup/$name/arch_%d_%t_%s_%p';

backup current controlfile format '/backup/RmanBackup/$name/ctl_%d_%t_%s_%p';

crosscheck backup;

crosscheck archivelog all;

delete noprompt archivelog until time 'sysdate-7';

delete noprompt  obsolete;

}

exit;

EOF

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

##record SCN

#---------------------------------------------------------------------------

sqlplus '/ as sysdba' << EOF

set linesize 200

spool /backup/RmanBackup/$name/report$name.txt

select to_char(dbms_flashback.get_system_change_number, '9999999999999999') from dual;

spool off

exit

EOF


#############################manual backup controlfile##############

sqlplus '/ as sysdba' <

alter database backup  controlfile to '/backup/controlfile/control_$name.bak';

exit;

EOF

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

#####################compress and  delete ##################

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


cd /backup/RmanBackup

tar -zcvf $name.tar.gz $name

rm -rf $name

scp $name.tar.gz [email protected]:/backup/RmanBackup

cd /backup/RmanBackup

rm -rf $DATE.tar.gz

cd /backup/controlfile

rm -rf control_$DATE.bak






rman 备份可以排除备份某个表空间

配置如下:

rman target /

configure exclude for tablespace DATAMART; #排除备份DATAMART表空间

show exclude;  #查看排除的表空间

configure exclude for tablespace DATAMART clear;  #清除排除备份的表空间


在进行数据库进行备份

##注释:出来DATAMART 表空间备份外其他的全部备份

rman target /  <

run {

allocate channel c1 type disk;

allocate channel c2 type disk;

allocate channel c3 type disk;

allocate channel c4 type disk;

backup database format '/backup/full_%d_%t_%s_%p';

sql'alter system archive log current';

backup archivelog all format '/backup/arch_%d_%t_%s_%p';

backup current controlfile format '/backup/ctl_%d_%t_%s_%p';

crosscheck backup;

crosscheck archivelog all;

}

EOF




恢复排除DATAMART 表空间的备份集


rman target /


RMAN> startup nomount

RMAN> restore controlfile from '/backup/ctl_OEM_914692212_78_1';

RMAN> alter database mount;

RMAN> restore database skip tablespace DATAMART ;

RMAN>recover database skip tablespace DATAMART ;

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of recover command at 06/17/2016 12:00:57

RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 13 and starting SCN of 967071

RMAN>recover database skip tablespace DATAMART  until scn 967071;

RMAN>  alter database open RESETLOGS;

详情见一下链接:

http://blog.itpub.net/29487349/viewspace-1284163/