#!/bin/bash
# fix 2006/11/21 by [email protected]
# use ssh no password to login
set -x

export LANG=C

host_name="waptst"
host_ip="192.168.2.1"
host_dir="/cygdrive/d/bk_ora/"

exp_exe="/cygdrive/d/oracle/ora81/bin/exp.exe"

ora_user="wifly"
ora_pass="wifly123456"
db_name="mindwin"

bac_dir="/var/bac/$host_name"
[ -d $bac_dir ] || mkdir -p $bac_dir
cd $bac_dir
# only wifly exp
#if [ 6 = 6 ]; then
if [ `date +%w` = 6 ]; then
        echo "cd $host_dir ; rm $host_name.wifly-`date –date="7 day ago" +%F`.dmp" | ssh cross@$host_ip
        echo "cd $host_dir ; rm $host_name.wifly-`date –date="6 day ago" +%F`.dmp" | ssh cross@$host_ip
        echo "cd $host_dir ; rm $host_name.wifly-`date –date="5 day ago" +%F`.dmp" | ssh cross@$host_ip
        echo "cd $host_dir ; rm $host_name.wifly-`date –date="4 day ago" +%F`.dmp" | ssh cross@$host_ip
        echo "cd $host_dir ; rm $host_name.wifly-`date –date="3 day ago" +%F`.dmp" | ssh cross@$host_ip
        echo "cd $host_dir ; rm $host_name.wifly-`date –date="2 day ago" +%F`.dmp" | ssh cross@$host_ip
        echo "cd $host_dir ; rm $host_name.wifly-`date –date="1 day ago" +%F`.dmp" | ssh cross@$host_ip
        rm $host_name.wifly-`date –date="7 day ago" +%F`.dmp.tar.gz
        rm $host_name.wifly-`date –date="6 day ago" +%F`.dmp.tar.gz
        rm $host_name.wifly-`date –date="5 day ago" +%F`.dmp.tar.gz
        rm $host_name.wifly-`date –date="4 day ago" +%F`.dmp.tar.gz
        rm $host_name.wifly-`date –date="3 day ago" +%F`.dmp.tar.gz
        rm $host_name.wifly-`date –date="2 day ago" +%F`.dmp.tar.gz
        rm $host_name.wifly-`date –date="1 day ago" +%F`.dmp.tar.gz
        echo exp
        echo "cd $host_dir ; $exp_exe $ora_user/$ora_pass@$db_name file=$host_name.wifly-`date +%F`.dmp" | ssh cross@$host_ip
        scp -rp cross@$host_ip:$host_dir/$host_name.wifly-`date +%F`.dmp $bac_dir
        tar zcvf $host_name.wifly-`date +%F`.dmp.tar.gz $host_name.wifly-`date +%F`.dmp
        rm $host_name.wifly-`date +%F`.dmp
else
         echo "cd $host_dir ; [ -f $host_name.wifly-`date +%F`.dmp ] && exit 0" | ssh cross@$host_ip
         if [ $? = 0 ]; then
                echo out
                :
         else
                echo exp
                echo "cd $host_dir ; $exp_exe $ora_user/$ora_pass@$db_name file=$host_name.wifly-`date +%F`.dmp" | ssh cross@$host_ip
                scp -rp cross@$host_ip:$host_dir/$host_name.wifly-`date +%F`.dmp $bac_dir
                tar zcvf $host_name.wifly-`date +%F`.dmp.tar.gz $host_name.wifly-`date +%F`.dmp
                rm $host_name.wifly-`date +%F`.dmp
         fi
fi

# full exp
oraF_user="superfate"
oraF_pass="superfate"
#if [ 6 = 6 ]; then
if [ `date +%w` = 6 ]; then
        echo "cd $host_dir ; rm $host_name.Full-`date –date="7 day ago" +%F`.dmp" | ssh cross@$host_ip
        echo "cd $host_dir ; rm $host_name.Full-`date –date="6 day ago" +%F`.dmp" | ssh cross@$host_ip
        echo "cd $host_dir ; rm $host_name.Full-`date –date="5 day ago" +%F`.dmp" | ssh cross@$host_ip
        echo "cd $host_dir ; rm $host_name.Full-`date –date="4 day ago" +%F`.dmp" | ssh cross@$host_ip
        echo "cd $host_dir ; rm $host_name.Full-`date –date="3 day ago" +%F`.dmp" | ssh cross@$host_ip
        echo "cd $host_dir ; rm $host_name.Full-`date –date="2 day ago" +%F`.dmp" | ssh cross@$host_ip
        echo "cd $host_dir ; rm $host_name.Full-`date –date="1 day ago" +%F`.dmp" | ssh cross@$host_ip
        echo "cd $host_dir ; [ -f $host_name.Full-`date +%F`.dmp ] && exit 0" | ssh cross@$host_ip
        rm $host_name.Full-`date –date="7 day ago" +%F`.dmp.tar.gz
        rm $host_name.Full-`date –date="6 day ago" +%F`.dmp.tar.gz
        rm $host_name.Full-`date –date="5 day ago" +%F`.dmp.tar.gz
        rm $host_name.Full-`date –date="4 day ago" +%F`.dmp.tar.gz
        rm $host_name.Full-`date –date="3 day ago" +%F`.dmp.tar.gz
        rm $host_name.Full-`date –date="2 day ago" +%F`.dmp.tar.gz
        rm $host_name.Full-`date –date="1 day ago" +%F`.dmp.tar.gz
        echo exp
        echo "cd $host_dir ; $exp_exe $oraF_user/$oraF_pass@$db_name inctype=complete file=$host_name.Full-`date +%F`.dmp" | ssh cross@$host_ip
        scp -rp cross@$host_ip:$host_dir/$host_name.Full-`date +%F`.dmp $bac_dir
        tar zcvf $host_name.Full-`date +%F`.dmp.tar.gz $host_name.Full-`date +%F`.dmp
        rm $host_name.Full-`date +%F`.dmp
else
        echo "cd $host_dir ; [ -f $host_name.Full-`date +%F`.dmp ] && exit 0" | ssh cross@$host_ip
        if [ $? = 0 ]; then
                echo out
                :
        else
                echo exp
                echo "cd $host_dir ; $exp_exe $oraF_user/$oraF_pass@$db_name inctype=complete file=$host_name.Full-`date +%F`.dmp" | ssh cross@$host_ip
                scp -rp cross@$host_ip:$host_dir/$host_name.Full-`date +%F`.dmp $bac_dir
                tar zcvf $host_name.Full-`date +%F`.dmp.tar.gz $host_name.Full-`date +%F`.dmp
                rm $host_name.Full-`date +%F`.dmp
        fi
fi

Related posts 相關文章

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。