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-2025 Zabbix SIA
-- This program is free software: you can redistribute it and/or modify it under the terms of
-- the GNU Affero General Public License as published by the Free Software Foundation, version 3.
-- 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 Affero General Public License for more details.
-- You should have received a copy of the GNU Affero General Public License along with this program.
-- If not, see <https://www.gnu.org/licenses/>.
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%%|*}
ref_field=${fld_line%%|*}
if [[ "$flags" =~ ZBX_NODATA ]]; then
if [[ "$field_type" =~ ^t_(shorttext|text|longtext)$ ]]; then
[[ -n "$default_val" ]] || default_val="''"