oracle exp 备份脚本
#!/bin/bash
#Oracle 环境变量 NLS_LANG=AMERICAN_AMERICA.AL32UTF8 ORACLE_SID=zgw ORACLE_BASE=/opt/oracle ORACLE_HOME=/opt/oracle/11g PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin export ORACLE_SID ORACLE_BASE ORACLE_HOME NLS_LANG PATH
#取时间戳 export BAKUPTIME=`date +%Y%m%d%H%M%S`
#dump生成目录 export DATA_DIR=/home/oracle/backup/dump
#压缩文件存放目录 export TAR_DIR=/home/oracle/backup/tars mkdir -p $DATA_DIR mkdir -p $TAR_DIR cd $DATA_DIR echo "Starting bakup..." echo "Bakup file path $DATA_DIR/SCOTT_$BAKUPTIME.dmp"
#具体备份语句 exp scott/scott file=$DATA_DIR/SCOTT_$BAKUPTIME.dmp log=$DATA_DIR/SCOTT_$BAKUPTIME.log echo "Starting tar..." echo "Tar file path $TAR_DIR/SCOTT_$BAKUPTIME.tar.gz" tar -zcvf $TAR_DIR/SCOTT_$BAKUPTIME.tar.gz SCOTT* echo "Bakup job is done!" #删除7天前的dump文件 find $DATA_DIR -type f -mtime +7 -exec rm -rf {} \;
任务计划设定:
#每天01:30执行自动备份,并将任务计划产生的日志信息和错误信息输出到backup.log日志中 30 01 * * * /home/oracle/scripts/backup.sh >>/home/oracle/scripts/backup.log 2>&1