国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > Linux Shell > 正文

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

2020-07-27 19:18:06
字體:
供稿:網(wǎng)友

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

復(fù)制代碼 代碼如下:

#!/bin/sh
oraclehome=$ORACLE_HOME
echo $oraclehome
localdir="/oracle/data"
echo $localdir
#刪除已經(jīng)存在的臨時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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 社旗县| 安徽省| 新密市| 正阳县| 任丘市| 巴彦县| 兰州市| 鄢陵县| 赤水市| 盘山县| 沂源县| 旌德县| 郴州市| 射洪县| 和政县| 扎囊县| 中山市| 阳朔县| 故城县| 常德市| 奈曼旗| 长泰县| 介休市| 师宗县| 南陵县| 开封县| 竹山县| 诸城市| 清远市| 洞口县| 黑水县| 崇信县| 三江| 玛多县| 云霄县| 秀山| 新巴尔虎左旗| 嵊泗县| 康马县| 旬阳县| 财经|