Oracle table space Export, user deletion, table space deletion, user new, table space new, data import shell
Execute the script with a non-Oracle user
Parameter name
$1:base the user name of the table space
$: User name for synchronization table space
Working with scenes
Test, base table space is used to upgrade and build some solidified data. Synchronous table space for testing, leveling data each time and base table space
Copy Code code as follows:
#!/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"
#将用户 The table space export
SU-ORACLE-C "Exp dba/dba file= $localdir/$2temp.dmp owner=$1"
Expresult=$?
If ["$expresult"!= "0"];then
echo "EXP $ tablespace Failure!!!"
Fi
#先删除用户 $ and its tablespace, and then create a new user and table space
Su-oracle-c "${oracle_home}/bin/sqlplus/nolog" <<eof
Connect/as SYSDBA
Drop user $ cascade;
Drop tablespace $ including contents and datafiles;
Create Tablespace $ DataFile '/oracle/product/10.2.0/oradata/$2.dbf ' size 5M autoextend on;
Create user $ identified by "$" default tablespace $ temporary tablespace TEMP profile default;
Grant connect to $;
Grant resource to $;
Grant create any table to $;
Grant create any trigger to $;
Grant create any type to $;
Grant create any view to $;
Grant unlimited tablespace to $;
Exit
Eof
Crdrresult=$?
If ["$crdrresult"!= "0"];then
echo "Drop user and tablespace failure!!!"
echo "Create user and tablespace failure!!!"
Else
#刚建完的用户不能马上使用, wait 10 seconds.
Sleep 10s
#更换dmp文件中的表空间名
Sed-i ' s/tablespace ' $/tablespace ' $/g ' $localdir/$2temp.dmp
#使用imp命令导出表空间数据到用户 A $ table space
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