Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zabbix 3.0 #5

Open
wants to merge 140 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
371beaf
CHG Backup of Zabbix 1.9.x / 2.0.0
maxhq Mar 16, 2012
e0b97c2
Update zabbix-mysql-backupconf.sh
maxhq May 13, 2013
273166c
Update zabbix-mysql-backupconf.sh
dre- Sep 15, 2014
5ec901c
Merge pull request #2 from dre-/patch-2
maxhq Sep 17, 2014
19fdbd2
Delete zabbix-mysql-autopartitioning.sql
maxhq Sep 17, 2014
3759abf
Update README
maxhq Sep 17, 2014
ffea98a
REV Ignore Eclipse .project file
maxhq Sep 17, 2014
6de48f2
NEW Script to load database table names for each Zabbix version from …
maxhq Sep 18, 2014
d93522d
FIX Corrected sorting of versions like "1.8.1rc1" (own sort routine)
maxhq Sep 18, 2014
ab265e6
DOC Added table headers for output
maxhq Sep 18, 2014
372bc02
NEW Added file containing table list up to Zabbix 2.4.0
maxhq Sep 18, 2014
5668edb
DOC Added script description
maxhq Sep 18, 2014
fd60e6a
ENH Complete overhaul so that script works with all previous Zabbix v…
maxhq Oct 2, 2014
bd56ead
REV Show backup progress percentage instead of each table name
maxhq Oct 2, 2014
796d9f5
REV Show backup progress percentage instead of each table name
maxhq Oct 2, 2014
7ef7136
Merge branch 'master' of [email protected]:maxhq/zabbix-backup.git
maxhq Oct 2, 2014
aa225d7
REV Removed spacing and changed password
maxhq Oct 2, 2014
1d23e1d
REV Rearranged some code
maxhq Oct 2, 2014
b9578ab
REV Removed two spaces in output of get-table-list.pl
maxhq Oct 2, 2014
8e2bbcb
DOC Updated README.txt
maxhq Oct 2, 2014
c2d92ca
DOC Updated README (reference to Github wiki)
maxhq Oct 2, 2014
08bc7e3
DOC +"MySQL"
maxhq Oct 2, 2014
a41feda
DOC Added ".0" to version number in script
maxhq Oct 2, 2014
9b11a37
NEW Parsing of commandline arguments implemented
maxhq Jan 27, 2015
139e036
REV Stop if database password is wrong
maxhq Jan 27, 2015
cf69f01
ENH Try reverse lookup of IPs and include hostname/IP in filename
maxhq Jan 27, 2015
7e88095
REV Renamed script to zabbix-mysql-dump
maxhq Jan 27, 2015
9614a42
Bash-related fixes.
Apr 7, 2015
0994f72
CHG Merge branch 'chevah-master' (pull request #4)
maxhq Jan 22, 2016
edc19d5
CHG Default output directory is now $PWD instead of script dir
maxhq Jan 22, 2016
cb68998
ENH Add quiet mode. IP reverse lookup optional.
dschneller Mar 12, 2015
d269565
DOC Refreshed and corrected some docs and formatting
maxhq Jan 22, 2016
1df2b0c
FIX Only invoke `dig` if available
maxhq Jan 22, 2016
ae54936
ENH Add database version to filename if available
maxhq Jan 22, 2016
026ada3
ENH Option -r to rotate backup files (by Daniel Schneller)
maxhq Jan 22, 2016
1feed59
ENH Option -c to use a MySQL config ("options") file
maxhq Jan 22, 2016
cbb6161
DOC Added hint not to modify default variable values
maxhq Jan 22, 2016
0a8bc9e
FIX Fixed typo "my" --> "mysql"
maxhq Jan 22, 2016
91f655c
DOC Reformatted help page and adjusted examples
maxhq Jan 22, 2016
a337a23
FIX Reading database name from config file did not work
maxhq Jan 22, 2016
6168774
DOC Changed version number to 0.8.0
maxhq Jan 22, 2016
fb816b9
Fixes issue when stderr output is included in backup file name, e.g. …
Mar 23, 2016
fef1c40
Merge pull request #5 from nikit0z/master
maxhq Mar 24, 2016
8226d44
NEW Added MIT license
maxhq Mar 26, 2016
4be030e
DOC Mention license in script
maxhq Mar 26, 2016
4ab9f54
Change versions 2.4.0 -> 3.0.0 in tables list
ruslan-ohitin Jul 1, 2016
64f245f
Add Zabbix 3.0.x tables to the list
ruslan-ohitin Jul 1, 2016
8acf579
Change version in README
ruslan-ohitin Jul 1, 2016
123bc77
CHG Updated table versions (3.0.3 and also 2.x versions)
maxhq Jul 11, 2016
a8e71ab
DOC Set latest version to 3.0.3
maxhq Jul 11, 2016
e0d796f
Merge branch 'patch-ruslan-ohitin'
maxhq Jul 11, 2016
dd09ae2
DOC How to release a new version
maxhq Jul 11, 2016
97b4075
DOC Added link to Zabbix.org page
maxhq Jul 11, 2016
9273643
Add -x flag for xz support
jonathanspw Jul 28, 2016
5d77734
NEW: Option -x to use XZ instead of GZ for compression
jonathanspw Jul 28, 2016
89d469f
Merge remote-tracking branch 'origin/master'
jonathanspw Jul 28, 2016
c0b8b26
FIX warning: here-document at line 206 delimited by end-of-file (want…
Sep 7, 2016
962e6a4
Merge pull request #8 from msjmeyer/master
maxhq Sep 8, 2016
4659367
REV Renamed readme file and moved history into readme
maxhq Sep 8, 2016
a7a4f95
FIX Prevent "Warning: Using a password on the command line interface …
maxhq Sep 8, 2016
273bdcd
Merge branch 'master' of https://github.com/neonardo1/zabbix-backup i…
maxhq Sep 8, 2016
0f5485c
ENH Added option -0 for "no compression" and revised code for xz comp…
maxhq Sep 8, 2016
f0db84f
Merge branch 'xz-support'
maxhq Sep 8, 2016
a485284
DOC Updated readme with changes in 0.8.2
maxhq Sep 8, 2016
cc01e7b
DOC Added "Jonathan Wright" as contributor
maxhq Sep 8, 2016
22f7eda
DOC Changed some wording in readme
maxhq Sep 8, 2016
273e73e
DOC Reference latest relase in README
maxhq Sep 10, 2016
658982e
DOC Added "announcment" to RELEASE task list
maxhq Sep 10, 2016
0096543
Enhanced known working version range to 3.0.7 (thanks, Lars Vinder)
maxhq Mar 1, 2017
a8faf47
Merge branch 'master' of github.com:maxhq/zabbix-backup
maxhq Mar 1, 2017
b16b2d5
Add postgres dump
sergeygalkin Mar 3, 2017
aec57ee
Add db port option
sergeygalkin Mar 5, 2017
f0564a0
support sockets and server config parsing
gergnz Mar 15, 2017
0d53668
fix dig if host isn't set, and force options to be used over config file
gergnz Mar 15, 2017
ae46152
fig logic
gergnz Mar 15, 2017
7bc26b9
make it a bit safer
gergnz Jul 2, 2017
fd4a304
cleanup and a couple of fixes
gergnz Jul 2, 2017
5e4c034
added support up to Zabbix 4.0.0
Oct 18, 2018
2887051
Show default path to zabbix_server.conf in help output
maxhq Mar 13, 2019
bab8708
Remove unneccessary variable
maxhq Mar 13, 2019
57c028d
Merge branch 'gergnz-master'
maxhq Mar 13, 2019
93806e6
Treat "maintenance_tag" as a config table
maxhq Mar 13, 2019
2b9506d
Adjust help texts and code formatting
maxhq Mar 14, 2019
576bc9d
Merge branch 'wschaft-master' into new
maxhq Mar 15, 2019
0918db7
Rename script to prepare merge of sergeygalkin's PR
maxhq Mar 14, 2019
a59b71a
Merge branch 'sergeygalkin-master' into new
maxhq Mar 15, 2019
97fa223
Replace tabs with spaces
maxhq Mar 14, 2019
f01e1d6
Change host option to "-H" and use "-h" and "--help" to show help
maxhq Mar 14, 2019
08ada33
Change some output text
maxhq Mar 14, 2019
0a30b61
Re-add accidentially deleted help for option "-z"
maxhq Mar 14, 2019
e6c0b3d
Rename flag DATA to SCHEMAONLY to make it more clear what it means
maxhq Mar 13, 2019
360e574
Reorder options for getopts command
maxhq Mar 14, 2019
c066c10
Also read database port from Zabbix config if available
maxhq Mar 14, 2019
44a2888
Support socket connections for PostgreSQL
maxhq Mar 14, 2019
fd2c1f7
Use "which" instead of hard coded path for binaries: suggested by yangqi
maxhq Mar 15, 2019
3ed7268
Update README and script with changes an contributors
maxhq Mar 15, 2019
748e766
New option -Z to skip reading the Zabbix server config file
maxhq Mar 15, 2019
d4f19ba
Rename some variables
maxhq Mar 15, 2019
7b207e7
Re-add accidentially deleted option "-t" (merge hell...)
maxhq Mar 15, 2019
3900056
Mimic special treatment of DBHost in zabbix_serverd.conf
maxhq Mar 15, 2019
b41330d
Only output config options that are set
maxhq Mar 15, 2019
5582142
Fix handling of MySQL option file: --defaults-extra-file must come first
maxhq Mar 15, 2019
de7d90a
Don't read Zabbix config or set defaults if MySQL options file was given
maxhq Mar 15, 2019
323937b
Don't set host from Zabbix config file if socket was specified manually
maxhq Mar 15, 2019
13de513
Show help about help options (not sure if this is useful)
maxhq Mar 15, 2019
6a0df23
Update texts to be posted (LinkedIn, XING) after a release
maxhq Mar 15, 2019
dfef0ca
missing $DBHOST to mysql client - error Cant connect to local MySQL s…
tiago-cruz-movile Mar 20, 2019
7a1f5c1
moved $DBHOST to psql case
tiago-cruz-movile Mar 21, 2019
a9ddde2
Merge branch 'tiago-cruz-movile-master'
maxhq Mar 21, 2019
2d38d33
Bump version number and add release info
maxhq Mar 21, 2019
bfb962e
Change title
maxhq Mar 21, 2019
8e8ce88
Update release instructions
maxhq Mar 21, 2019
1eff0a9
Add license scan report and status
fossabot Jul 12, 2019
1a35479
Fix shellcheck SC2236: Use -n instead of ! -z.
mjtrangoni Aug 9, 2019
9bd379c
Fix shellcheck SC2162: read without -r will mangle backslashes
mjtrangoni Aug 9, 2019
c52320c
Escape special characters while reading password
ironbishop Sep 17, 2019
0d79386
Don't source (PHP) Zabbix config to prevent possible escaping issues
maxhq Jan 16, 2020
c6e7d93
Fix accidentally disabled cleanup of postgresql password file
maxhq Jan 16, 2020
c2aaf2f
Merge branch 'fix-shellcheck-issues' of https://github.com/mjtrangoni…
maxhq Jan 16, 2020
a1ea57e
Merge branch 'mjtrangoni-fix-shellcheck-issues' into next
maxhq Jan 16, 2020
402503e
Merge pull request #17 from fossabot/master
maxhq Jan 16, 2020
c592a3a
Revert "Add license scan report and status"
maxhq Jan 16, 2020
ee6a2f8
Fix get-table-list.pl to work with Git repository
maxhq Jan 16, 2020
9d093de
get-table-list.pl: merge zabbix-dump's existing table config into output
maxhq Jan 16, 2020
c992748
get-table-list.pl: move some code into subroutines
maxhq Jan 16, 2020
3210328
Update table list to Zabbix 4.4.4
maxhq Jan 16, 2020
805b50f
Merge branch 'next'
maxhq Jan 16, 2020
27a105e
Set hostname to `uname -n` if DB is on localhost
maxhq Jan 16, 2020
2b325d5
Bump version number to 0.9.2 and update docs
maxhq Jan 16, 2020
b5464e5
Update release docs
maxhq Jan 16, 2020
b3c3355
Check for unknown tables; make PostgreSQL dump more stable
maxhq Jan 17, 2020
d5d5f97
Replace --extended-insert=FALSE with equivalent --skip-extended-insert
maxhq Jan 17, 2020
fc1896b
Rename misleading variable DATA_TABLES to SCHEMAONLY_TABLES
maxhq Jan 17, 2020
7b6616e
Do not backup each MySQL table individually anymore
maxhq Jan 17, 2020
815c211
Process 'DBSchema' option in Zabbix config and add -S to specify schema
maxhq Jan 17, 2020
2326371
Also output error message for unknown tables in quiet mode
maxhq Jan 17, 2020
6eed145
Get rid of "echo -e" in favor of "echo $''"
maxhq Jan 17, 2020
c2971ab
Skip IP reverse lookup for localhost, fix multiline dig answers
maxhq Jan 17, 2020
fa9332e
New option -v (--version) to show version information
maxhq Jan 17, 2020
4a093d3
Bump version to 0.9.3 and update changelog
maxhq Jan 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.project
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Jens Berthold

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 0 additions & 7 deletions README

This file was deleted.

99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Backup script for Zabbix configuration data (MySQL/PostgreSQL)

This is a MySQL/PostgreSQL database backup script for the [Zabbix](http://www.zabbix.com/) monitoring software from version 1.3.1 up to 4.4.

## Download

Download the latest (stable) release here:

https://github.com/maxhq/zabbix-backup/releases/latest

## More informations

Please see the [Project Wiki](https://github.com/maxhq/zabbix-backup/wiki).

## Version history

**0.9.3 (2020-01-17)**

- ENH: Check for unknown tables
- ENH: Speed up MySQL backup by not calling mysqldump for every single table anymore
- ENH: New option -S to specify PostgreSQL schema
- FIX: Stabilize and enhance PostgreSQL dump
- FIX: Skip IP reverse lookup for localhost, fix multiline dig answers

**0.9.2 (2020-01-16)**

- ENH: Support for Zabbix 4.4
- ENH: Fix (non-critical) shellcheck issues (Mario Trangoni)
- CHG: Fix and enhance helper script get-table-list.pl
- FIX: Escape special characters while reading password (ironbishop)
- FIX: Re-enable accidentally disabled cleanup of postgresql password file
- FIX: Insert hostname into backup file also if database resides on localhost

**0.9.1 (2019-03-21)**

- FIX: Correctly process hostname option -H (Tiago Cruz)

**0.9.0 (2019-03-14)**

- NEW: Support for PostgreSQL databases (Sergey Galkin)
- NEW: Option -P to specify database server port (Sergey Galkin)
- NEW: Support for socket connections to MySQL and PostgreSQL server (Greg Cockburn)
- NEW: Database connection parameters are read from Zabbix servern config by default (Greg Cockburn)
- ENH: Support for Zabbix 4.0 (Wesley Schaft)
- ENH: Options -h and --help to show help (hostname is now specified using -H)
- ENH: Options -Z to skip reading the Zabbix server config file
- CHG: Rename script to "zabbix-dump"
- FIX: Support for whitespaces in database parameters (Greg Cockburn)
- FIX: Support for backslashes in manually entered password (Greg Cockburn)

**0.8.2 (2016-09-08)**

- NEW: Option -x to use XZ instead of GZ for compression (Jonathan Wright)
- NEW: Option -0 for "no compression"
- FIX: Evil space was masking end of here-document (fixed in #8 by @msjmeyer)
- FIX: Prevent "Warning: Using a password on the command line interface can be insecure."

**0.8.1 (2016-07-11)**

- ENH: Added Zabbix 3.0.x tables to list (added & tested by Ruslan Ohitin)

**0.8.0 (2016-01-22)**

- FIX: Only invoke `dig` if available
- ENH: Option -c to use a MySQL config ("options") file (suggested by Daniel Schneller)
- ENH: Option -r to rotate backup files (Daniel Schneller)
- ENH: Add database version to filename if available
- ENH: Add quiet mode. IP reverse lookup optional (Daniel Schneller)
- ENH: Bash related fixes (Misu Moldovan)
- CHG: Default output directory is now $PWD instead of script dir

**0.7.1 (2015-01-27)**

- NEW: Parsing of commandline arguments implemented
- ENH: Try reverse lookup of IPs and include hostname/IP in filename
- REV: Stop if database password is wrong

**0.7.0 (2014-10-02)**

- ENH: Complete overhaul to make script work with lots of Zabbix versions

**0.6.0 (2014-09-15)**

- REV: Updated the table list for use with zabbix v2.2.3

**0.5.0 (2013-05-13)**

- NEW: Added table list comparison between database and script

**0.4.0 (2012-03-02)**

- REV: Incorporated mysqldump options (suggested by Jonathan Bayer)

**0.3.0 (2012-02-06)**

- ENH: Backup of Zabbix 1.9.x / 2.0.0, removed unnecessary use of
variables (DATEBIN etc) for commands that use to be in $PATH

**0.2.0 (2011-11-05)**
49 changes: 49 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## Releasing a new version

### Before commit

* Update README.md

### After commit

* Tag the release commit: `git tag v0.9.2 && git push --tags`
* Add release at https://github.com/maxhq/zabbix-backup/releases

**Summary of main changes**

```
This release fixes ...

### Direct download

[zabbix-mysql-dump](https://raw.githubusercontent.com/maxhq/zabbix-backup/v0.9.2/zabbix-dump) (v0.9.2)

### Changelog

Please see the [version history in the README](https://github.com/maxhq/zabbix-backup/blob/v0.9.2/README.md#version-history).

### Thanks!
- @username
```

* Update https://github.com/maxhq/zabbix-backup/wiki
* Update https://zabbix.org/wiki/Docs/howto/database_backup_script
* Announce release at https://www.linkedin.com/groups/161448

> **New version x.x.x of zabbix-dump**
>
> zabbix-dump is a Linux bash script for backing up the Zabbix configuration by saving MySQL or PostgreSQL database tables into a compressed file.
> Tables holding configuration data will be fully backed up. For mass data tables (events, history, trends, ...) only the table schema is stored without any data (to keep the backup small).
>
> Overiew: https://github.com/maxhq/zabbix-backup/blob/master/README.md
> Latest release: https://github.com/maxhq/zabbix-backup/releases/latest

* Announce release at https://www.xing.com/communities/forums/100845147

> **Neue Version x.x.x von zabbix-dump**
>
> zabbix-dump ist ein Linux-Bash-Skript zum Backup der Zabbix-Konfiguration durch Sicherung der MySQL- bzw. PostgreSQL-Datenbanktabellen in eine komprimierte Datei.
> Es sichert Konfigurationsdaten komplett, bei Tabellen mit Massendaten (Historie, Events, Trends etc.) jedoch nur das "leere" Datenbankschema (um das Backup zu minimieren).
>
> Übersicht: https://github.com/maxhq/zabbix-backup/blob/master/README.md
> Neueste Version: https://github.com/maxhq/zabbix-backup/releases/latest
167 changes: 167 additions & 0 deletions get-table-list.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#!/usr/bin/env perl
# NAME
# get-table-list.pl - List current and historic Zabbix database tables
#
# SYNOPSIS
# This is mainly a helper script for developing the backup script.
#
# It connects to svn://svn.zabbix.com (using Subversion client "svn") and
# fetches the schema definitions of all tagged Zabbix versions beginning
# from 1.3.1 (this takes a while).
#
# It then prints out a list of all tables together with the first and last
# Zabbix version where they were used.
#
# HISTORY
# v0.1 - 2014-09-19 First version
#
# AUTHOR
# Jens Berthold (maxhq), 2020
use strict;
use warnings;

use version;

my $REPO = 'https://git.zabbix.com/scm/zbx/zabbix.git';
my $REPO_WEB = 'https://git.zabbix.com/projects/ZBX/repos/zabbix/raw';

sub stop {
my ($msg) = @_;
print "ERROR: $msg\n";
exit;
}

# sort version numbers correctly
sub cmpver {
my ($a, $b) = @_;

# split version parts: 1.2.3rc1 --> 1 2 3rc1
my @a_parts = split /\./, $a;
my @b_parts = split /\./, $b;

for (my $i=0; $i<scalar(@a_parts); $i++) {
return 1 if $i >= scalar(@b_parts);
# split number parts: 3rc1 --> 3 rc 1
my ($a_num, $a_type, $a_idx) = $a_parts[$i] =~ m/^(\d+)(\D+)?(\d+)?$/;
my ($b_num, $b_type, $b_idx) = $b_parts[$i] =~ m/^(\d+)(\D+)?(\d+)?$/;
my $cmp;
# 3 before 4
$cmp = $a_num <=> $b_num; return $cmp unless $cmp == 0;
# 3rc1 before 3
return -1 if $a_type and not $b_type;
return 1 if not $a_type and $b_type;
# a1 before b1
$cmp = ($a_type//"") cmp ($b_type//""); return $cmp unless $cmp == 0;
# rc1 before rc2
$cmp = ($a_idx//0) <=> ($b_idx//0); return $cmp unless $cmp == 0;
}
# 1.2 before 1.2.1
return -1 if scalar(@a_parts) < scalar(@b_parts);
# equal
return 0;
}

# Get tag list from repo:
sub get_taglist {
print "Querying existing tags from $REPO...\n";

# Returned format:
# 7f6b20903537b9bbf72fe2b75ab7fac557856aad refs/tags/1.0
# 693709cc4a80777f7759856c853b38cbc920f068 refs/tags/1.1
my @tags_raw = `git ls-remote -t $REPO`;
# remove trailing newline
chomp @tags_raw;
# skip release candidates, betas and tags like "zabicom-xxx"
@tags_raw = grep { m{ refs/tags/ \d+ \. \d+ ( \. \d+ )? $}x } @tags_raw;

# Create HashRef:
# 1.0 => 7f6b20903537b9bbf72fe2b75ab7fac557856aad
# 1.1 => 693709cc4a80777f7759856c853b38cbc920f068
return {
map { m{^ (\w+) \s+ refs/tags/ (.*) $}x; $2 => $1 } @tags_raw
};
}

# Read old table informations from zabbix-dump
sub get_old_tabinfo {
my $tabinfo_old = {};

open my $fh, '<', './zabbix-dump' or stop("Couldn't find 'zabbix-dump': $!");

my $within_data_section = 0;
while (<$fh>) {
chomp;
if (/^__DATA__/) { $within_data_section = 1; next }
next unless $within_data_section;
my ($table, $from, undef, $to, $mode) = split /\s+/;

$tabinfo_old->{$table} = {
from => $from,
to => $to,
schema_only => ($mode//"") eq "SCHEMAONLY" ? 1 : 0,
};
}

return $tabinfo_old;
}



`which git` or stop("No Git client found");

my $tabinfo_old = get_old_tabinfo(); # old data from zabbix_dump

my $tags = get_taglist();
my $tabinfo = {}; # for each table, create a list of Zabbix versions that know it

print "Reading table schemas...\n";

# Loop over tags and read table schema
for my $tag (sort { cmpver($a,$b) } keys %$tags) {
next if cmpver($tag, "1.3.1") < 0; # before Zabbix 1.3.1, schema was stored as pure SQL

my ($schema, $subdir);

printf " - %-8s %s", $tag, "Looking for schema...";
# search in subdir /schema (<= 1.9.8) and /src for schema.(sql|tmpl)
for my $sub (qw(schema src)) {
# file list:
# 100644 blob 1f0a05eb826dfcdb26f9429ad30c720454374ca1 data.tmpl
# 100644 blob b98b5eecc62731508c09d9e76d7aed9d4eb201f2 schema.tmpl
my @files_raw = `curl -s $REPO_WEB/create/$sub?at=refs%2Ftags%2F$tag`;
next unless @files_raw; # directory not found?
chomp @files_raw; # remove trailing newline
my @files = map { /^ \d+ \s+ \w+ \s+ \w+ \s+ (.*) $/x; $1 } @files_raw;

($schema) = grep /^schema\.(sql|tmpl)/, @files;
$subdir = $sub;
last;
}
if (!$schema) {
print "\nNo schema found in tag $tag\n";
next;
}
print " Processing ($schema)... ";
my @table = `curl -s $REPO_WEB/create/$subdir/$schema?at=refs%2Ftags%2F$tag`;
for (@table) {
chomp;
next unless m/^TABLE/;
my (undef, $table) = split /\|/;
$tabinfo->{$table} //= [];
push @{$tabinfo->{$table}}, $tag;
}
print " Done\n";
}

#
# Print out results
#
print "\n\n";
print "TABLE FIRST USE LAST USE MODE\n";
print "----------------------------------------------------\n";
for my $tab (sort keys %$tabinfo) {
my $mode = $tabinfo_old->{$tab}
? ($tabinfo_old->{$tab}->{schema_only} ? ' SCHEMAONLY' : '')
: ' <-- NEW TABLE! Only store schema?';
printf "%-26s %-8s - %-8s%s\n", $tab, $tabinfo->{$tab}->[0], $tabinfo->{$tab}->[-1], $mode;
}
Loading