Oracle每天自动备份脚本

[root@localhost ~] # chown oracle:oinstall /data/backup/oracle_backup

在修改完以上的步骤后,再把Oracle用户下的bash_profile配置文件中在安装时定义好的环境变量拷贝到脚本中,在定义好脚本的执行时间就可以了,脚本的实现比较简单,如下:

#!/bin/bash
#oracle_backup.sh version1.0 chmod 700
#writer jim
#00 00 * * * /usr/local/scripts/oracle_backup.sh
#chmod 700 /usr/local/scripts/oracle_backup.sh
#You must first import the environment variables in the Oracle user's bash_profile file
#Must be used to define the DBA account first dpdata1 path and authorized directory to read and write, modify the dpdata1 group
#history
#2017.07.01
export  ORACLE_BASE= /usr/local/u01/oracle
export  ORACLE_HOME= /usr/local/u01/oracle/product/11 .2.0 /dbhome_1
export  ORACLE_SID=oracle11
export  NLS_LANG= "american_america.ZHS16GBK"
export  NLS_DATE_FORMAT= "YYYY-MM-DD HH24:Mi:SS"
export  LD_LIBRARY_PATH=$ORACLE_HOME /lib
export  PATH=$ORACLE_HOME /bin :$PATH
datetime=$( date  + "%Y%m%d" )
dpdata1_dir= "/data/backup/oracle_backup"
oracle_u01= "u01"
oracle_u02= "u02"
oracle_password1= "u01_password"
oracle_password2= "u02_password"
  
expdp ${oracle_u01}/${oracle_password1} directory=dpdata1 dumpfile=${oracle_u01}_${datetime} logfile=${oracle_u01}_${datetime}.log
  
if  [ $? - ne  0 ]; then
    echo  "$(date +" %Y-%m-%d_%H:%M:%S ")oracle_${oracle_u01}_backup_file!"  > ${dpdata1_dir}/${datetime}_err.log
fi
  
expdp ${oracle_u02}/${oracle_password2} directory=dpdata1 dumpfile=${oracle_u02}_${datetime} logfile=${oracle_u02}_${datetime}.log
  
if  [ $? - ne  0 ]; then
    echo  "$(date +" %Y-%m-%d_%H:%M:%S ")oracle_${oracle_u02}_backup_file!"  >> ${dpdata1_dir}/${datetime}_err.log
fi
  
/usr/bin/bzip2  -z ${dpdata1_dir}/*${datetime}*
find  $dpdata1_dir - type  f -ctime +30 -name  "*.bz2"  - exec  rm  -vf {} \;

当然,也可以把失败的地方换成写好的发邮件的function,在失败的时候发一封邮件也可以。

猜你喜欢

转载自www.linuxidc.com/Linux/2017-07/145355.htm