Shell Script Operations Oracle Delete tablespace, create tablespace, delete user _linux shell

Source: Internet
Author: User
Tags dba

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.