DB_HOST="quiktrak.mysql.ukraine.com.ua";
DB_NAME="quiktrak_db";
DB_USER="quiktrak_db";
DB_PASS="gJRYgrRz";
BACKUP_HOME="/home/quiktrak/quiktrak.com.au/www/system/backup";

# "j, bz2, bzip2" == bzip2,
# "z, gz, gzip" == gzip,
# or empty
COMPRESS_TYPE="j";

VERBOSE_MODE="no";

# "xml" == xml dump
# "sql" == sql dump
# "files" == raw files backup
BACKUP_TYPE="sql";

# "yes|true|1" == no-data
NO_DATA="yes";

case "${COMPRESS_TYPE}" in
    j|bz2|bzip2) COMPRESS_SUFFIX=".bz2"; COMPRESS_TYPE="j"; ;;
    z|gz|gzip) COMPRESS_SUFFIX=".gz"; COMPRESS_TYPE="z"; ;;
    *) COMPRESS_SUFFIX=""; COMPRESS_TYPE=""; ;;
esac
case "${VERBOSE_MODE}" in
    [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) VERBOSE_KEY="v" ;;
    *) VERBOSE_KEY="" ;;
esac
case "${BACKUP_TYPE}" in
    xml) FILE_EXT="" ;;
    sql) ;;
    *) NO_DATA="" ;;
esac
case "${NO_DATA}" in
    [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) NO_DATA="--no-data" ;;
    *) NO_DATA="" ;;
esac


MYSQLDUMP_CMD="mysqldump --host=$DB_HOST --user=$DB_USER --password=$DB_PASS --add-locks --comments"

    TARCMD="tar -c${COMPRESS_TYPE}${VERBOSE_KEY}f";

    ARCDATE=`/bin/date "+%Y%m%d%H%M"`;
    DBNAME="${DB_NAME}-${ARCDATE}_Full";
    STRUCTNAME="${DB_NAME}-${ARCDATE}_Full.nodata.sql";
    XMLNAME="${DB_NAME}-${ARCDATE}_Full.nodata.xml";
    ARCNAME="${DB_NAME}-${ARCDATE}_Full.tar${COMPRESS_SUFFIX}";
    [ -d "${BACKUP_HOME}" ] || mkdir ${BACKUP_HOME};
    ${MYSQLDUMP_CMD} ${DB_NAME} > ${BACKUP_HOME}/${DBNAME}.sql;
    ${TARCMD} "${BACKUP_HOME}/${ARCNAME}" "${BACKUP_HOME}/${DBNAME}"*  >> /dev/null 2>&1;
	tmp=$?
	if [ $tmp -ne 0 ]; then {
#		echo "Fail ($tmp)";
		status=1;
	} else {
#		echo "OK ($tmp)";
#		rm "${BACKUP_HOME}/${DBNAME}.log";
		rm "${BACKUP_HOME}/${DBNAME}.sql";
	} fi
