ablog

不器用で落着きのない技術者のメモ

スキーマ単位で export する単純な bash スクリプト

Oracle Database のデータをスキーマ単位で export する単純な bash スクリプトを作ってみた。

#!/bin/bash
export LANG=C
export NLS_LANG=American_America.JA16SJISTILDE
BASE_DIR=$(cd $(dirname $0);pwd)
CURR_TS=`date '+%Y%m%d%H%M%S'`
 
ORA_USER=system
ORA_PASS=manager
ORA_SCHEMA=scott
DMP_FILE=exp_${ORACLE_SID}_${CURR_TS}.dmp
LOG_FILE=exp_${ORACLE_SID}_${CURR_TS}.log
 
cd ${BASE_DIR}
nohup exp ${ORA_USER}/${ORA_PASS} owner=${ORA_SCHEMA} consistent=y direct=y recordlength=65536 file=${DMP_FILE} > ${LOG_FILE} 2>&1 &
 
echo "[`date '+%Y-%m-%d %H:%M:%S'`] Exporting ${ORA_SCHEMA} schema to ${BASE_DIR}/${DMP_FILE} ..."
echo "[`date '+%Y-%m-%d %H:%M:%S'`] Please check ${BASE_DIR}/${LOG_FILE} for more details."
echo "[`date '+%Y-%m-%d %H:%M:%S'`] Exp proccess -> `ps -f|egrep \" [e]xp \"`"
 
exit
  • 実行例
$ ./ora_exp_dmp.sh 
[2010-02-02 11:44:39] Exporting scott schema to /home/oracle/dump/exp_scott_20100202114439.dmp ...
[2010-02-02 11:44:39] Please check /home/oracle/dump/exp_scott_20100202114439.log for more details.
[2010-02-02 11:44:39] Exp proccess -> oracle     24039 24034  0 11:44 pts/9    00:00:00 exp                owner=scott consistent=y direct=y recordlength=65536 file=exp_scott_20100202114439.dmp
$ ls -l
total 61188
-rw-rw-r-- 1 oracle oinstall 62582784 Feb  2 11:44 exp_scott_20100202114439.dmp 
-rw-rw-r-- 1 oracle oinstall     3669 Feb  2 11:44 exp_scott_20100202114439.log 
-rwxr-xr-x 1 oracle oinstall      698 Feb  2 11:44 ora_exp_dmp.sh