shell脚本操作oracle表空间的导出,用户的删除,表空间删除,用户新建,表空间新建,数据导入

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/bin/sh
oraclehome=$ORACLE_HOME
echo $oraclehome
localdir="/oracle/data"
echo $localdir
#删除已经存在的临时dmp文件
rm -rf $localdir/$2temp.dmp
rmresult=$?
echo "rm $2temp.dmp result:$rmresult"
#将用户$1的表空间导出
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命令导出表空间数据到用户$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

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

相关文章

系ubuntu 下面打开终端输入:sudo apt-get install sendmail...
依家我有1个软件goagent目录(大家懂得) 放在/home/gateman/...
其实我想讲的是 cp -L关于-L参数的解释:-L, --dereferenc...
原地址:http://www.rjgc.net/control/content/content.php?...
chroot,即 change root directory (更改 root 目录)。在 li...
简单解析下, stdin就是标准输入, stdout就是标准。举个例子...