多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
#### 备份脚本 - 修改SID,ORACLE_HOME,LOCAL_DIR(本地备份目录),REMOTE_DIR(NFS目录),用户,密码 ``` #!/bin/sh #Author:BrandynX #Date:2017-03-27 #Remark: FOracle backup scripts #Declare the oracle variable export ORACLE_BASE=/app/oracle11g export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1 export ORACLE_SID=dingdb export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK; #Declare the script variable NFS_SAVEDAYS="7" LOCAL_SAVEDAYS="1" TODAY=`date +%Y%m%d` LOCAL_BACKUPDIR_DAY=`date -d "-$LOCAL_SAVEDAYS days" +%Y%m%d` NFS_BACKUPDIR_DAY=`date -d "-$NFS_SAVEDAYS days " +%Y%m%d` LOCAL_DIR=/data/backup REMORT_DIR=/nfsdir/oracle LOG_DIR=/app/scripts # UID Check if [ $UID -ne 0 ];then echo "Please use root to execute the script." exit fi #Loacl backup file processing #Create today backupdir and backup if [ -d $LOCAL_DIR/$TODAY ];then echo "WARNING INFORMATION: $LOCAL_DIR/$TODAY Backup directory already exists" | tee -a $LOG_DIR/scripts.log exit else mkdir -p $LOCAL_DIR/$TODAY fi #Create today export log directory if [ ! -d $LOG_DIR/$TODAY-dingdb ];then mkdir -p $LOG_DIR/$TODAY-dingdb fi #Export oracle data exp ding/iC43sld7h@dingdb file=$LOCAL_DIR/$TODAY/$TODAY-dingdb.dmp log=$LOG_DIR/$TODAY-dingdb/$TODAY-dingdb.log #Compress backup file cd $LOCAL_DIR tar czf $LOCAL_DIR/$TODAY-dingdb.tar.gz $TODAY echo "####################" >> $LOG_DIR/scripts.log echo "BACKUP INFORMATION: LOCAL $TODAY bakcup is complete." | tee -a $LOG_DIR/scripts.log #Synchornize file to NFS #To determine whether there is a bakcup if [ -f $REMORT_DIR/$TODAY-dingdb.tar.gz ];then echo "WARNING INFORMATION: NFS already exists in $TODAY backup file." | tee -a $LOG_DIR/scripts.log exit else cp $LOCAL_DIR/$TODAY-dingdb.tar.gz $REMORT_DIR echo "BACKUP INFORMATION: Remote NFS $TODAY bakcup is complete." |tee -a $LOG_DIR/scripts.log fi #Delete local backup if [ -d $LOCAL_DIR/$LOCAL_BACKUPDIR_DAY ];then rm -rf $LOCAL_DIR/$LOCAL_BACKUPDIR_DAY rm -f $LOCAL_DIR/$LOCAL_BACKUPDIR_DAY-dingdb.tar.gz echo "DELETE INFORMATION: LOCALDIR DELETE $LOCAL_BACKUPDIR_DAY backup is delete. " |tee -a $LOG_DIR/scripts.log fi #Delete nfs backup rm -rf $LOG_DIR/$NFS_BACKUPDIR_DAY-dingdb rm -f $REMORT_DIR/$NFS_BACKUPDIR_DAY-dingdb.tar.gz echo "DELETE INFORMATION: REMOTE NFS DELETE $NFS_BACKUPDIR_DAY backup is delete. " |tee -a $LOG_DIR/scripts.log echo "####################" >> $LOG_DIR/scripts.log echo "" >> $LOG_DIR/scripts.log ``` ##### 增加定时任务 ```shell 50 23 * * * /bin/sh /app/scripts/oracle_bakcup.sh > /dev/null 2>&1 ```