溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何編寫shell腳本操作oracle刪除表空間、創(chuàng)建表空間、刪除用戶

發(fā)布時(shí)間:2021-10-08 11:43:19 來源:億速云 閱讀:136 作者:iii 欄目:開發(fā)技術(shù)

本篇內(nèi)容介紹了“如何編寫shell腳本操作oracle刪除表空間、創(chuàng)建表空間、刪除用戶”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

oracle下表空間的導(dǎo)出,用戶的刪除,表空間刪除,用戶新建,表空間新建,數(shù)據(jù)導(dǎo)入的shell
使用非oracle用戶執(zhí)行該腳本
參數(shù)說名
$1:base表空間的用戶名
$2:同步表空間的用戶名
使用場(chǎng)景
測(cè)試用,base表空間用于升級(jí)建立一些固化數(shù)據(jù)。同步表空間用于測(cè)試用,每次去和base表空間拉平數(shù)據(jù)

代碼如下:

#!/bin/sh
oraclehome=$ORACLE_HOME
echo $oraclehome
localdir="/oracle/data"
echo $localdir
#刪除已經(jīng)存在的臨時(shí)dmp文件
rm -rf $localdir/$2temp.dmp
rmresult=$?
echo "rm $2temp.dmp result:$rmresult"
#將用戶$1的表空間導(dǎo)出
su - oracle -c "exp dba/dba file=$localdir/$2temp.dmp owner=$1"
expresult=$?
if [ "$expresult" != "0" ];then
        echo "exp $1 tablespace failure!!!"
fi
#先刪除用戶$2及其表空間,然后再新建該用戶及表空間
su - oracle -c "${ORACLE_HOME}/bin/sqlplus /nolog" <<EOF
connect / as sysdba
drop user $2 cascade;
drop tablespace $2 including contents and datafiles;
create tablespace $2 datafile '/oracle/product/10.2.0/oradata/$2.dbf' size 5M autoextend on;
create user $2 identified by "$2" default tablespace $2 temporary tablespace TEMP profile DEFAULT;
grant connect to $2;
grant resource to $2;
grant create any table to $2;
grant create any trigger to $2;
grant create any type to $2;
grant create any view to $2;
grant unlimited tablespace to $2;
exit
EOF

crdrresult=$?
if [ "$crdrresult" != "0" ];then
        echo "drop user and tablespace failure!!!"
        echo "create user and tablespace failure!!!"
else
#剛建完的用戶不能馬上使用,等候10秒
        sleep 10s
#更換dmp文件中的表空間名
        sed -i 's/TABLESPACE "$1"/TABLESPACE "$2"/g' $localdir/$2temp.dmp
#使用imp命令導(dǎo)出表空間數(shù)據(jù)到用戶$2的表空間
        su - oracle -c "imp dba/dba file=$localdir/$2temp.dmp  fromuser=$1 touser=$2"
        impresult=$?
        if [ "$impresult" != "0" ];then
                echo "imp failure!!!"
        else
                echo "imp success!!!"
        fi
fi

“如何編寫shell腳本操作oracle刪除表空間、創(chuàng)建表空間、刪除用戶”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI