oracle 备份脚步

 1 #!/bin/sh
 2 # Date: 2016-08-13 15:34
 3 # Author: chzh
 4 # Version: 0.0.1
 5 # Update: Add copy db backup file to remote back server
 6 
 7 export ORACLE_BASE=/u01/app/oracle
 8 export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
 9 export PATH=$ORACLE_HOME/bin:$PATH
10 export ORACLE_OWNER=oracle
11 export ORACLE_SID=orcl
12 export NLS_LANG=American_America.ZHS16GBK
13 export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
14 
15 cd /home/oracle/db_backup_188
16 exptime=`date +%Y-%m-%d_%H`
17 nfs_mount_dir=`df -h | grep -i '211.153.66.111' | awk '{print $6}'`
18 [ -n $nfs_mount_dir ] && remote_back_dir=${nfs_mount_dir}/db_backup_oracle_6.174
19 
20 echo "backup the log file"
21 [ -d script_execute_log ] || mkdir script_execute_log
22 mv exp.log script_execute_log/exp_`date +%Y-%m-%d`.log
23 
24 cat exp.list | while read dbUser dbPasswd
25 do
26         echo $dbUser
27         exp $dbUser/$dbPasswd GRANTS=Y file=$dbUser"_"$exptime.dmp
28         if [ "0" == $? ]
29         then
30                 tar -zcvf $dbUser"_"$exptime.dmp.tar.gz $dbUser"_"$exptime.dmp
31         [ -d ${remote_back_dir}/`date +%Y-%m` ] || mkdir ${remote_back_dir}/`date +%Y-%m`
32         /bin/cp $dbUser"_"$exptime.dmp.tar.gz ${remote_back_dir}/`date +%Y-%m`
33                 rm $dbUser"_"$exptime.dmp
34         fi
35 done
36 
37 # 10 mean 3 day ago, Because have to user exported tables.
38 if [ `ls -l *.tar.gz | wc -l` -gt 6 ]; then
39     find . -mtime +2 -name "*.dmp.tar.gz" |xargs /bin/rm -f > /dev/null
40 fi

同目录下exp.list文件存放帐户名和密码。

 

posted @ 2016-11-02 12:02  杨小愚  阅读(341)  评论(0编辑  收藏  举报