npotorino / zabbix-backup

Backup script for Zabbix configuration data (MySQL/PostgreSQL)
MIT License
67 stars 30 forks source link

${VERSION} is returning string with new lines #16

Open okay-scam opened 1 year ago

okay-scam commented 1 year ago

zabbix-dump is saving my filename with new lines which renders it unusable until I rename it

ls -lah /mnt/Data/backup/
total 181M
drwxr-xr-x 2 root root 4.0K Nov 22 14:04  .
drwxr-xr-x 7 root root 4.0K Nov 22 14:01  ..
-rw-r--r-- 1 root root  91M Nov 22 13:56 'zabbix_cfg_localhost_20221122-1356_db-psql-5050006'$'\n''5050006'$'\n''5050006'$'\n''5050006'$'\n''5050006'$'\n''5050006'$'\n''5050006'$'\n''5050006'$'\n''5050006'$'\n''5.5.6.sql'
-rw-r--r-- 1 root root  91M Nov 22 14:04 'zabbix_cfg_localhost_20221122-1404_db-psql-5050006'$'\n''5050006'$'\n''5050006'$'\n''5050006'$'\n''5050006'$'\n''5050006'$'\n''5050006'$'\n''5050006'$'\n''5050006'$'\n''5.5.6.sql'

sudo ./zabbix-dump -t psql -H localhost -P 5432 -o /mnt/Data/backup/ -i -0
Reading database options from /etc/zabbix/zabbix_server.conf...
Configuration:
 - type:     psql
 - host:     localhost (localhost)
 - port:     5432
 - socket:   /var/run/postgresql/.s.PGSQL.5432
 - schema:   public
 - database: zabbix
 - user:     zabbix
 - output:   /mnt/Data/backup/
Fetching list of existing tables...

Unknown tables found in database:
 - history_log_old
 - history_old
 - history_str_old
 - history_text_old
 - history_uint_old
They will be ignored as -i was specified

Starting table backups...

For the following large tables only the schema (without data) was stored:
 - acknowledges
 - alerts
 - auditlog
 - auditlog_details
 - event_recovery
 - event_suppress
 - event_tag
 - events
 - history
 - history_log
 - history_str
 - history_text
 - history_uint
 - problem
 - problem_tag
 - task
 - task_acknowledge
 - task_check_now
 - task_close_problem
 - task_remote_command
 - task_remote_command_result
 - trends
 - trends_uint

Compressing backup file...
Backup Completed
/mnt/Data/backup//zabbix_cfg_localhost_20221122-1404_db-psql-5050006
5050006
5050006
5050006
5050006
5050006
5050006
5050006
5050006
5.5.6.sql

Printing ${VERSION} returns zabbix_cfg_localhost_20221122-1403_db-psql-5050006 5050006 5050006 5050006 5050006 5050006 5050006 5050006 5050006 5.5.6.sql

My best guess is this is the culprit. I'm not that well versed in databases and I'm actually trying to dump from an upgrade that has a database which is missing primary keys, so this may just be an anomaly of my busted DB.

sudo -u postgres psql zabbix -c "select optional from dbversion;"
 optional
----------
  5050006
  5050006
  5050006
  5050006
  5050006
  5050006
  5050006
  5050006
  5050006
  5050006
(10 rows)
ironbishop commented 1 year ago

Can you test by changing this line?

- DB_VER=$(psql "${DB_OPTS_BATCH[@]}" -c "select optional from dbversion;" 2>/dev/null)
+ DB_VER=$(psql "${DB_OPTS_BATCH[@]}" -c "select optional from dbversion limit 1;" 2>/dev/null)
invisibleninja06 commented 6 months ago

Having had the same issue i can confirm that changing the line as you described does indeed fix the issue.