echo "select ${fields} from ${table}${where}order by ${table}.${primary_key}" | eval "${mysql_cmd} -t" | grep -v '^+' | sed -e 's/ | /|/g' -e '1,1s/^| /FIELDS|/g' -e '2,$s/^| /ROW |/g' -e 's/ |$/|/g'
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ] || [ -z "$5" ] || [ -z "$6" ]; then
./export_data.sh -hhost -Pport -uroot -p<password> <DB name> ZBX_DATA > ../src/data.tmpl
./export_data.sh -hhost -Pport -uroot -p<password> <DB name> ZBX_TEMPLATE > ../src/templates.tmpl
./export_data.sh -hhost -Pport -uroot -p<password> <DB name> ZBX_DASHBOARD > ../src/dashboards.tmpl
The script generates data file out of existing MySQL database." && exit 1
mysql_cmd="mysql $1 $2 $3 $4 $5"
schema=$basedir/../src/schema.tmpl
-- Copyright (C) 2001-2022 Zabbix SIA
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
for tbl_line in `grep "^TABLE.*${dbflag}" "${schema}"`; do
primary_key=${tbl_line%%|*}
total_count=`echo "select count(*) from ${table}" | eval ${mysql_cmd} | tail -1`
for fld_line in `sed -n "/^TABLE|${table}|/,/^$/ p" "${schema}" | grep "^FIELD" | sed 's/[ \t]//g'`; do
field_type=${fld_line%%|*}
default_val=${fld_line%%|*}
ref_table=${fld_line%%|*}