Technical posts/마이그

오라클 서버에 여유공간이 없을때 exp받으면서 ftp전송하기

ODB 2014. 12. 20. 13:53

오라클 서버에 여유공간이 없을때 exp받으면서 ftp전송하기


혹시나 PIPE로 하는줄 알고 오셨다면 정중히 '뒤로가기'를 눌러주시기 바랍니다.


금일 특정 사이트에서 이관작업을 하는데 AS-IS에는 여유공간이 없고 이관할 DB는 700G...

NFS물려서 작업하자고 했다가 서버에 HANG이 걸린다고.....  GG

그런다고 신규서버에 9i을 깔수가 없다 OS버전이 높아서 ㅜ.ㅜ

9i를 깔았다면 tns를 이용하여 원격에서 export를 exp system/password@ASIS file=dump.dmp log=log.log feedback=10000 full=y 로 했겠지만 ㅎㅎ

망했다


갑님이 갑질하면 어쩔수 없는 인생이다..

'NFS는 해줄수 없다'는 소리에 곰곰히 생각을 해보니

급 즐거워서 쉘을 급하게 짰다..


방식은


AS-IS에 export를 filesize를 주고 특정사이즈에 맞게 계속 떨군다

떨구는 파일을 순서대로 ftp로 TO-BE에 전송을 한다

TO-BE에서 파일을 다 받아서 import를 한다



send_ftp.sh

file_check.sh

두개를 만들었는데 간략히 설명하고 소스를 첨부한다


send_ftp.sh은 소스파일 타겟파일 의 경로를 argument로 받아서 전송한다

file_check.sh while문을 돌려서 특정 컨디션이 되면 send_ftp.sh를 호출한다


send_ftp.sh

  ftp -n -v 10.10.10.10<<EOF

   user oracle oracle

   verbose

   binary

   prompt off

   put $1 $2

   bye

  EOF


file_check.sh

   #!/bin/sh

  

  file_head='/imsi/oracle/dump'

  file_head_ftp='./dump'

  file_tail='.dmp'

  a=$1

  b=`expr $a + 1`

  file_full=$file_head$a$file_tail

  file_full_next=$file_head$b$file_tail

  file_ftp=$file_head_ftp$a$file_tail

  

  while [ 1 ]

  do

  if [ -f $file_full_next ];

  then

     echo "---------file exist!--------------"

     echo "current file is "$file_full

      sh send_ftp.sh $file_full /ora_exp/$file_ftp 

      sleep 10

     echo "delete old file"

     rm -f $file_full

     echo "deleted!"

     echo "next file is "$file_full_next

     echo "-----------------------------------"

     a=`expr $a + 1`

     b=`expr $a + 1`

     file_full=$file_head$a$file_tail

     file_full_next=$file_head$b$file_tail

     file_ftp=$file_head_ftp$a$file_tail

     sleep 5

  else

  

  echo "#############try next time#############"

  sleep 10

  fi

  done


참... 조잡하다

깔끔하게 소스를 수정할 생각은 없다.. 필요한 사람들만 수정해 쓰도록 하자

file_full 은 현재파일 file_full_next는 다음파일

a가 1일때 b는 항상 a+1이다.. 다음파일을 찾아야 하니까

다음 file_ftp가 있는이유는 원격지 경로가 안맞는 경우를 위해서 하나더 만들어줌


while은 항상 실행되도록 1을 넣어주고

while이 계속 돌아가면서 if조건에 맞으면 전송 아니면 try next time에 걸려서 잠깐쉬고 다시 loop를 돈다


while로 도는 도중에 $file_full_next 변수가 다음파일을 체크해서 조건을 맞춘다..

설명하기가 힘드네..


간단하게 하면 dump1.dmp(file_full)가 다받아지고 dump2.dmp(file_full_next) 가 생성되면 dump1.dmp(file_full)를 전송한다

dump3.dmp가 생기면 dump2.dmp를 전송한다.. 는 식..


sh send_ftp.sh $file_full /ora_exp/$file_ftp 줄은

조건 충족시 파일전송만 해준다 put $1 $2에서 $1을 $2로 보내주는 거다

send_ftp.sh 쉘의 내용을 보면 $1, $2가 있는데 요것들이 $file_full $file_ftp가 된다


아무튼 전송을 하고 

여유공간 확보를 위해 rm으로 전송이 완료된 파일을 지우고


a값과 b값을 하나씩 올린다

a와 b가 변경되었으니 파일명을 올라간 a와 b에 맞게 다시 넣어서 변수로 넣어주고


새로 while을 돈다..


으... 나의 엄청난 설명력에 죄송을 표한다 ㅜ.ㅜ

옆에있으면 그림으로 잘 설명해 주겠지만 글을 통해서 지식을 전달한다는건 정말 힘든일 같다

sql을 짜야하는데.. 무슨.. shell을 짜고 있는건지 ㅡㅡ;


실행은 nohup file_check.sh 1 & 으로 실행을한다

왜 1이 들어가는지는.. a값을 줘야하기 때문..

1을 안넣고 돌리면 안된다.. 



그럼 결과를 보도록 할까?


---------file exist!-------------- // file_full_next조건에 맞는 파일을 찾음

current file is /imsi/oracle/dump36.dmp // 전송대상 file_full파일명

Connected to 10.10.10.10.// send_ftp.sh에 변수를 넘김

220 (vsFTPd 2.2.2)

331 Please specify the password.

230 Login successful.

Verbose mode off.

Interactive mode off. // send_ftp.sh에서 돌아옴

delete old file // rm 전 

deleted!         // rm후

next file is /imsi/oracle/dump37.dmp //다음에 전송할 파일명

-----------------------------------

#############try next time############# // 다음파일이 아직 안생겼음

#############try next time#############

#############try next time#############

---------file exist!-------------- // 앗 생겼다! 전송하자

current file is /imsi/oracle/dump37.dmp //아까 본 그파일을 전송

Connected to 10.10.10.10.

220 (vsFTPd 2.2.2)

331 Please specify the password.

230 Login successful.

Verbose mode off.

Interactive mode off.

delete old file

deleted!

next file is /imsi/oracle/dump38.dmp

-----------------------------------



음... 급하게 만들었지만 나름 만족한다


갑님들 힘들게좀 만들지 마세요 ㅜ.ㅜ



오랫만에 업그레이드 버전을 소개한다


ora_user='ora10'


send_dir='/ora10/send/'

dest_dir='/ora10/recv/'


file_head='dump'

file_tail='.dmp'


current_num=1

next_num=`expr $current_num + 1`


current_file=$file_head$current_num$file_tail

next_file=$file_head$next_num$file_tail


isRunning=`ps -aef | grep $ora_user | grep exp | grep -v grep | wc -l`


while [ $isRunning -eq 1 ] || [ -f $send_dir$next_file ];

do

if [ -f $send_dir$next_file ];

then

  echo "---------- export file exist ----------"

  echo " current file is " $current_file

  sh send_ftp.sh $send_dir$current_file $dest_dir$current_file

  sleep 5

  echo "remove old file"

  rm -f $send_dir$current_file

  echo "removed!"

  echo "next file is "$next_file

  echo "----------------------------------------"

  sleep 1

  current_num=$next_num

  next_num=`expr $next_num + 1`

  current_file=$file_head$current_num$file_tail

  next_file=$file_head$next_num$file_tail

  sleep 5

else

  echo "### try next time ###"

  sleep 10

fi

isRunning=`ps -aef | grep $ora_user | grep exp | grep -v grep | wc -l`

done


isRunning=`ps -aef | grep $ora_user | grep exp | grep -v grep | wc -l`

if [ "$isRunning" = "0" ];

then

  echo "--------- last exp file exist ---------"

  echo " current file is " $current_file

  sh send_ftp.sh $send_dir$current_file $dest_dir$current_file

  echo "----------------------------------------"

fi


echo "export is done"


코드를 보면 알겠지만 가독성을 위해 변수들은 쉽게 파악이 가능하도록 이름을 줬고 

마지막파일까지 알아서 보낸다!! 

exp 프로세스가 종료되고 next_file이 존제하지 않으면 exp가 종료되었다고 판단해서 current_file을 전송한다




"이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다."