Mittwoch, 1. Juni 2016

Oracle Database Export Import

Export


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh
#exec >/tmp/export.log
#exec 2>&1
 
# set environment
. ~oracle/env
 
 
DIR=/oracle/tmp_dump
DD=DATAPUMPDIR
 
sqlplus / as sysdba < Abbruch!"  exit 1  # rm $DIR/$DUMP
fi
 
if [ -f $DIR/$LOG ];then
  rm $DIR/$LOG
fi
 
P=`dd if=/dev/urandom bs=512 count=1 2>/dev/null | tr -dc "a-zA-Z0-9-_\.\+\$\?" | fold -w 15 | head -1`
echo "alter user system identified by \"$P\";" | sqlplus -S "/ as sysdba"
 
expdp system/"$P" full=yes DIRECTORY=$DD DUMPFILE=$DUMP logfile=$LOG METRICS=YES
#  STATUS=120
 
 
sqlplus / as sysdba <<EOF
set echo on
drop directory $DD;
exit
EOF 

echo "-----[ Done ]-----"

Import

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#!/bin/sh
 
  sqlplus / as sysdba <<EOF
  set echo on
  create or replace directory DUMP_DIR as '/oracle/tmp_dump/';
  GRANT read, write ON DIRECTORY DUMP_DIR to system;
  select * from dba_directories;
        exit
EOF
 
# -----
# generate a random password for SYSTEM
 
P=`dd if=/dev/urandom bs=512 count=1 2>/dev/null | tr -dc "a-zA-Z0-9-_\.\+\$\?" | fold -w 15 | head -1`
echo "alter user system identified by \"$P\";" | sqlplus -S "/ as sysdba"
 
 
impdp system/"$P"  directory=DUMP_DIR schemas=test_1,test_2 table_exists_action=replace dumpfile=full.dmp logfile=imp.log

Keine Kommentare:

Kommentar veröffentlichen