oracle数据库备份任务

备份脚本如下:

1.0 expdp
1.1导出某些schema

#!/bin/bash

ORACLE_BASE=/oracle/product
export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/db
export ORACLE_HOME
ORACLE_SID=xxxxx
export ORACLE_SID
NLS_LANG=AMERICAN_AMERICA.zhs16gbk
export NLS_LANG
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
PATH=$PATH:/usr/bin:sbin:/bin:/usr/sbin:/opt/bin:/usr/local/bin:$ORACLE_HOME/bin:/usr/contrib/bin
export PATH

cd /datapool/oracle/tmp/expdp
mkdir $ORACLE_SID+'7schemas+expdp'+`date +%Y+%m+%d`

expdp system/manager1  directory=ora_back dumpfile=$ORACLE_SID+'7schemas'+`date +%Y+%m+%d+%H+%M+%S`.dmp    cluster=n      schemas=ygcg_ndmain,bjdjy_data,ygcg_lx,ygcg_ht,ygcg_trade,ygcg_jianguan,zhgldata   logfile=$ORACLE_SID+'7schemas'+`date +%Y+%m+%d+%H+%M+%S`.log
mv $ORACLE_SID+'7schemas'+`date +%Y+%m+%d`*.dmp $ORACLE_SID+'7schemas+expdp'+`date +%Y+%m+%d`

1.2 全库导出

#!/bin/bash


ORACLE_BASE=/oracle/product
export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/db
export ORACLE_HOME
ORACLE_SID=xxxxx
export ORACLE_SID
NLS_LANG=AMERICAN_AMERICA.zhs16gbk
export NLS_LANG
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
PATH=$PATH:/usr/bin:sbin:/bin:/usr/sbin:/opt/bin:/usr/local/bin:$ORACLE_HOME/bin:/usr/contrib/bin
export PATH

cd /datapool/oracle/tmp/expdp
mkdir $ORACLE_SID+'full'+`date +%Y+%m+%d`

expdp system/manager1  directory=ora_back dumpfile=$ORACLE_SID+'full'+`date +%Y+%m+%d+%H+%M+%S`.dmp cluster=n  full=y          logfile=$ORACLE_SID+'full'+`date +%Y+%m+%d+%H+%M+%S`.log
#mv $ORACLE_SID+'full'+`date +%Y+%m+%d`*.dmp $ORACLE_SID+'full'+`date +%Y+%m+%d`

 

2.0 rman

2.1 0级备份脚本

#!/bin/bash
#set env



ORACLE_BASE=/oracle/product
export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/db
export ORACLE_HOME
ORACLE_SID=xxxxx
export ORACLE_SID
NLS_LANG=AMERICAN_AMERICA.zhs16gbk
export NLS_LANG
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
PATH=$PATH:/usr/bin:sbin:/bin:/usr/sbin:/opt/bin:/usr/local/bin:$ORACLE_HOME/bin:/usr/contrib/bin
export PATH

ARC_PATH=/datapool/oracle/backup/arch
export ARC_PATH
RMAN_BAK_PATH=/datapool/oracle/backup/rman_backup
export rman_bak_path
DATE=`date +%Y%m%d-%H:%M:%S`
export DATE
 
rman target / log /datapool/oracle/backup/rman_backup/log/L0_bk_$DATE.log << EOF

run {
allocate channel c1 type disk ;
allocate channel c2 type disk ;
allocate channel c3 type disk ;
backup incremental level 0  tag 'dbL0' format '$RMAN_BAK_PATH/L0_%U_%t.bak' database ;
sql 'alter system archive log current';
backup filesperset 3  format '$ARC_PATH/arch%t.arc' archivelog all delete input ;
delete noprompt obsolete ;
release channel c1;
release channel c2;
release channel c3;
 }
exit;


2.2 1级备份脚本

#!/bin/bash
#set env



ORACLE_BASE=/oracle/product
export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/db
export ORACLE_HOME
ORACLE_SID=xxxxx
export ORACLE_SID
NLS_LANG=AMERICAN_AMERICA.zhs16gbk
export NLS_LANG
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
PATH=$PATH:/usr/bin:sbin:/bin:/usr/sbin:/opt/bin:/usr/local/bin:$ORACLE_HOME/bin:/usr/contrib/bin
export PATH

ARC_PATH=/datapool/oracle/backup/arch
export ARC_PATH
RMAN_BAK_PATH=/datapool/oracle/backup/rman_backup
export RMAN_BAK_PATH
DATE=`date +%Y%m%d-%H:%M:%S`
export DATE
 
rman target / log /datapool/oracle/backup/rman_backup/log/L1_bk_$DATE.log << EOF

run {
allocate channel c1 type disk ;
allocate channel c2 type disk ;
allocate channel c3 type disk ;
backup incremental level 1  tag 'dbL1' format '$RMAN_BAK_PATH/L0_%U_%t.bak' database ;
sql 'alter system archive log current';
backup filesperset 3  format '$ARC_PATH/arch%t.arc' archivelog all delete input ;
delete noprompt obsolete ;
release channel c1;
release channel c2;
release channel c3;
 }
exit;


2.3 2级备份脚本

#!/bin/bash
#set env



ORACLE_BASE=/oracle/product
export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/db
export ORACLE_HOME
ORACLE_SID=xxxxx
export ORACLE_SID
NLS_LANG=AMERICAN_AMERICA.zhs16gbk
export NLS_LANG
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
PATH=$PATH:/usr/bin:sbin:/bin:/usr/sbin:/opt/bin:/usr/local/bin:$ORACLE_HOME/bin:/usr/contrib/bin
export PATH

ARC_PATH=/datapool/oracle/backup/arch
export ARC_PATH
RMAN_BAK_PATH=/datapool/oracle/backup/rman_backup
export rman_bak_path
DATE=`date +%Y%m%d-%H:%M:%S`
export DATE
 
rman target / log /datapool/oracle/backup/rman_backup/log/L2_bk_$DATE.log << EOF

run {
allocate channel c1 type disk ;
allocate channel c2 type disk ;
allocate channel c3 type disk ;
backup incremental level 2  tag 'dbL2' format '$RMAN_BAK_PATH/L0_%U_%t.bak' database ;
sql 'alter system archive log current';
backup filesperset 3  format '$ARC_PATH/arch%t.arc' archivelog all delete input ;
delete noprompt obsolete ;
release channel c1;
release channel c2;
release channel c3;
 }
exit;


2.4 定期删除归档

#!/bin/bash
#set env



ORACLE_BASE=/oracle/product
export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/db
export ORACLE_HOME
ORACLE_SID=xxxxx
export ORACLE_SID
NLS_LANG=AMERICAN_AMERICA.zhs16gbk
export NLS_LANG
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
PATH=$PATH:/usr/bin:sbin:/bin:/usr/sbin:/opt/bin:/usr/local/bin:$ORACLE_HOME/bin:/usr/contrib/bin
export PATH

ARC_PATH=/datapool/oracle/backup/arch
export ARC_PATH
RMAN_BAK_PAT=/datapool/oracle/backup/rman_backup
export RMAN_BAK_PAT
DATE=`date +%Y%m%d-%H:%M:%S`
export DATE

rman target / log /datapool/oracle/backup/rman_backup/log/rm_arch_$DATE.log << EOF

run {
crosscheck archivelog all;
delete archivelog all;
 }
exit;

3.0 linux平台的计划任务如下:

00 17 20 5  * su - oracle -c "/export/home/oracle/scripts/expdp-impdp/expdp_full.sh"
30 19 30 4 * su - oracle -c "/export/home/oracle/scripts/impdp.sh"
45 18 2 5 * su - oracle -c "/export/home/oracle/scripts/imdpdp_ygcg_trade.sh"
40 10  13 5 * su - oracle -c "/export/home/oracle/scripts/expdp0512.sh"


00 22 * * 1-5  su - oracle -c "/export/home/oracle/scripts/expdp-impdp/expdp_7schemas.sh"
* 01 * * 6 su - oracle -c "/export/home/oracle/scripts/expdp-impdp/expdp_full.sh"

#30 10 23 5 * su - oracle -c  "/export/home/oracle/scripts/expdp-impdp/impdp_0523.sh"

* 12 * * * su - oracle -c "/export/home/oracle/scripts/expdp-impdp/rm_redundancy.sh"

30    16    *    *    *      su - oracle -c "/export/home/oracle/scripts/rman/rm_arch.sh"
#*    0    *    *    5    su - oracle -c "/export/home/oracle/scripts/rman/l0_rman_bak.sh"
#*    0    *    *    0 1    su - oracle -c "/export/home/oracle/scripts/rman/l2_rman_bak.sh"
#*    0    *    *    2     su  - oracle -c "/export/home/oracle/scripts/rman/l1_rman_bak.sh"
#*    0    *    *    3 4   su - oracle -c "/export/home/oracle/scripts/rman/l2_rman_bak.sh"

 

 

 


~

转载于:https://www.cnblogs.com/iyoume2008/p/9077705.html

你可能感兴趣的:(oracle数据库备份任务)