#!/bin/bash
EXPORT_LIST=("DRC" "ECOPRO" "QUALAB" "XINNONG" "CASIA" "XIAOSHOUYI" "MATERCHEM" "DETONFAN" "VOITH" "YINGJIA" "EPM" "SGB" "SILVERWING")
OUTPUT='/BACKUP/data/SCHEMA_EPM/HOURLY'
dateStr=`date '+%F_%H'`
echo "Date: $dateStr"


for schema in ${EXPORT_LIST[@]}
do
	 echo "exporting $schema"

    if test -e $OUTPUT/$schema
    then
       echo 'schema dir exist'
    else
       echo 'schema dir does not exist, create it'
       mkdir $OUTPUT/$schema
    fi

    case $schema in
	EPM)
	   password='Kingsoft@2019'
	    ;;
	SGB)
       password='SGB_user_2019'
	    ;;
	SILVERWING)
       password='Yinyi_2021'
	    ;;
	*)
       password='EPM_user_2017'
	esac

    hdbsql -i 01 -u $schema -p $password "EXPORT $schema.\"*\" AS BINARY INTO '$OUTPUT/$schema/$dateStr' WITH REPLACE"
    if [ $? != "0" ]; then
          echo "exporting fails"
    else
          echo "exporting success"
    fi
done

echo "export end"