1. 程式人生 > >DB2備份所有表的方法

DB2備份所有表的方法

下面為您介紹的備份方法用於實現DB2備份所有表資料,如果您在DB2備份所有表方面遇到過類似的問題,不妨一看。

    ###cr by fubs  
    clear;  
    db2 connect to abbs>/tmp/null;  
    tbname=`db2 "list tables"|grep -v "record"|awk '{if(length($1)>0 && NR>3)print $1}'`;  
    ##宣告變數  
    s_date=`date +%Y-%m-%d,%H:%M:%S`  
    v_date=`date +%Y%m%d`  
    bkpath=$HOME/personal/fubs/bak/$v_date;  
    if [ ! -d $bkpath ];then  
    mkdir $bkpath;  
    echo "備份所有資料,確認嗎?\c"  
    else  
    echo "當天已備份,是否覆蓋?\c";  
    fi  
    read yn;  
    if [ -z "$yn" -o ! "$yn" = "y" ];then  
    echo "放棄操作!";  
    exit 0;  
    fi  
    cd $bkpath;  
    num=0;  
    for i in $tbname  
    do  
    db2 "Export to $i.del of del select * from $i";  
    num=`expr $num + 1`;  
    done  
    db2 connect reset>/tmp/null;  
    db2 terminate>/tmp/null;  
    echo "備份資料成功,共備份[$num]個庫表!"