Skip to main content

Zabbix database backup utility for postgres and mysql

Project description

Zabbix backup python script

EXPERIMENTAL: use at your own risk!

Python script to perform zabbix dumps.

See full project documentation at https://www.zabbixbackup.com.

Inspired by the project https://github.com/npotorino/zabbix-backup.

Install

pip install zabbixbackup

Examples

Create a backup connecting as user postgres to the db zabbix with schema zabbix

python -m zabbixbackup psql --host 127.0.0.1 --user postgres --passwd mypassword --database zabbix --schema zabbix

Create a tar archive dump and save standard zabbix configuration files along with it.

python -m zabbixbackup psql --host 127.0.0.1 --passwd mypassword --format tar --save-files

Create a "custom" archive and save it to a backup folder, rotate backups to retain only the last four.

python -m zabbixbackup psql --host 127.0.0.1 --passwd mypassword --format custom --rotate 4

Setup an authentication (.pgpass) file and use it to login in subsequent call.

python -m zabbixbackup pgsql --host 127.0.0.1 \
          --passwd - --keep-login-file --dry-run
[input password]
mv .pgpass /root

python -m zabbixbackup pgsql --host 127.0.0.1 --login-file /root/.pgpass

Setup an authentication (mylogin.cnf) file and use it to login in subsequent call.

python -m zabbixbackup mysql --host 127.0.0.1 \
          --passwd - --keep-login-file --dry-run
[input password]
mv mylogin.cnf /root

python -m zabbixbackup mysql --host 127.0.0.1 --login-file /root/mylogin.cnf

First level CLI

usage: zabbixbackup [-h] {psql,pgsql,mysql} ...

options:
  -h, --help          show this help message and exit

DBMS:
  {psql,pgsql,mysql}
    psql (pgsql)      (see zabbixbackup psql --help)
    mysql             (see zabbixbackup mysql --help)

Postgres SQL: second level CLI

zabbixbackup psql --help

usage: zabbixbackup psql [-h] [-z] [-Z ZBX_CONFIG] [-D] [-H HOST] [-P PORT]
                         [-u USER] [-p PASSWD] [--keep-login-file]
                         [--login-file LOGINFILE] [-d DBNAME] [-s SCHEMA] [-n]
                         [-U {dump,nodata,ignore,fail}] [-M {dump,nodata}]
                         [-N] [-x PGCOMPRESSION]
                         [-f {directory,tar,custom,plain}] [--save-files]
                         [--files FILES] [-a ARCHIVE] [-o OUTDIR] [-r ROTATE]
                         [-q | -v | -V | --debug]

zabbix dump for psql inspired and directly translated from...

options:
  -h, --help            show this help message and exit
  -z, --read-zabbix-config
                        try to read database host and credentials from Zabbix
                        config. Implicit if `--zabbix-config` is set.
                        (default: False)
  -Z ZBX_CONFIG, --zabbix-config ZBX_CONFIG
                        Zabbix config file path. Implicit if `--read-zabbix-
                        config` is set. (default:
                        /etc/zabbix/zabbix_server.conf)
  -D, --dry-run         Do not create the actual backup, only show dump
                        commands. Be aware that the database will be queried
                        for tables selection and temporary folders and files
                        will be created. (default: False)

connection options:
  -H HOST, --host HOST  hostname/IP of DBMS server, to specify a blank value
                        pass '-'. If host starts with a slash it's interpreted
                        as a socket directory. Special rules might apply (see
                        postgre online documentation for sockets). (default:
                        127.0.0.1)
  -P PORT, --port PORT  DBMS port. (default: 5432)
  -u USER, --username USER
                        database login user. (default: zabbix)
  -p PASSWD, --passwd PASSWD
                        database login password (specify '-' for an
                        interactive prompt). (default: None)
  --keep-login-file     if a credential file is created (.pgpass) do not
                        delete it on exit. (default: False)
  --login-file LOGINFILE
                        use '.pgpass' file for the authentication. (default:
                        None)
  -d DBNAME, --database DBNAME
                        database name. (default: zabbix)
  -s SCHEMA, --schema SCHEMA
                        database schema. (default: public)
  -n, --reverse-lookup  (NOT IMPLEMENTED) perform a reverse lookup of the IP
                        address for the host. (default: True)

dump action options:
  -U {dump,nodata,ignore,fail}, --unknown-action {dump,nodata,ignore,fail}
                        action for unknown tables. (default: ignore)
  -M {dump,nodata}, --monitoring-action {dump,nodata}
                        action for monitoring table (default: nodata)
  -N, --add-columns     add column names in INSERT clauses and quote them as
                        needed. (default: False)

dump level compression options:
  -x PGCOMPRESSION, --pgcompression PGCOMPRESSION
                        passed as-is to pg_dump --compress, might be implied
                        by format. (default: None)
  -f {directory,tar,custom,plain}, --pgformat {directory,tar,custom,plain}
                        dump format, will mandate the file output format.
                        (default: custom)

configuration files:
  --save-files          save folders and other files (see --files). (default:
                        False)
  --files FILES         save folders and other files as listed in this file.
                        One line per folder or file, non existant will be
                        ignored. Directory structure is replicated (copied via
                        'cp'). (default: -)

output options:
  -a ARCHIVE, --archive ARCHIVE
                        archive level compression. 'tar' to create a tar
                        archive, '-' to leave the backup uncompressed as a
                        folder. Other available formats are xz, gzip and
                        bzip2. Use ':<LEVEL>' to set a compression level. I.e.
                        --archive xz:6 (default: -)
  -o OUTDIR, --outdir OUTDIR
                        save database dump to 'outdir'. (default: .)
  -r ROTATE, --rotate ROTATE
                        rotate backups while keeping up 'R' old backups.Uses
                        filename to match '0=keep everything'. (default: 0)

verbosity:
  -q, --quiet           don't print anything except unrecoverable errors.
                        (default: False)
  -v, --verbose         print informations. (default: True)
  -V, --very-verbose    print even more informations. (default: False)
  --debug               print everything. (default: False)

MySQL: second level CLI

zabbixbackup mysql --help

usage: zabbixbackup mysql [-h] [-z] [-Z ZBX_CONFIG] [-c] [-C MYSQL_CONFIG]
                          [-D] [-H HOST] [-P PORT] [-S SOCK] [-u USER]
                          [-p PASSWD] [--keep-login-file]
                          [--login-file LOGINFILE] [-d DBNAME] [-n]
                          [-U {dump,nodata,ignore,fail}] [-M {dump,nodata}]
                          [-N] [--mysqlcompression MYSQLCOMPRESSION]
                          [--save-files] [--files FILES] [-a ARCHIVE]
                          [-o OUTDIR] [-r ROTATE] [-q | -v | -V | --debug]

zabbix dump for mysql inspired and directly translated from...

options:
  -h, --help            show this help message and exit
  -z, --read-zabbix-config
                        try to read database host and credentials from Zabbix
                        config. Implicit if `--zabbix-config` is set.
                        (default: False)
  -Z ZBX_CONFIG, --zabbix-config ZBX_CONFIG
                        Zabbix config file path. Implicit if `--read-zabbix-
                        config` is set. (default:
                        /etc/zabbix/zabbix_server.conf)
  -c, --read-mysql-config
                        Read database host and credentials from MySQL config
                        file. Implicit if `--mysql-config` is set. (default:
                        False)
  -C MYSQL_CONFIG, --mysql-config MYSQL_CONFIG
                        MySQL config file path. Implicit if `--read-mysql-
                        config` is set. (default: /etc/mysql/my.cnf)
  -D, --dry-run         Do not create the actual backup, only show dump
                        commands. Be aware that the database will be queried
                        for tables selection and temporary folders and files
                        will be created. (default: False)

connection options:
  -H HOST, --host HOST  hostname/IP of DBMS server, to specify a blank value
                        pass '-'. (default: 127.0.0.1)
  -P PORT, --port PORT  DBMS port. (default: 3306)
  -S SOCK, --socket SOCK
                        path to DBMS socket file. Alternative to specifying
                        host. (default: None)
  -u USER, --username USER
                        database login user. (default: zabbix)
  -p PASSWD, --passwd PASSWD
                        database login password (specify '-' for an
                        interactive prompt). (default: None)
  --keep-login-file     if a credential file is created (mylogin.cnf) do not
                        delete it on exit. (default: False)
  --login-file LOGINFILE
                        use 'mylogin.cnf' file for the authentication.
                        (default: None)
  -d DBNAME, --database DBNAME
                        database name. (default: zabbix)
  -n, --reverse-lookup  (NOT IMPLEMENTED) perform a reverse lookup of the IP
                        address for the host. (default: True)

dump action options:
  -U {dump,nodata,ignore,fail}, --unknown-action {dump,nodata,ignore,fail}
                        action for unknown tables. (default: ignore)
  -M {dump,nodata}, --monitoring-action {dump,nodata}
                        action for monitoring table (default: nodata)
  -N, --add-columns     add column names in INSERT clauses and quote them as
                        needed. (default: False)

dump level compression options:
  --mysqlcompression MYSQLCOMPRESSION
                        dump level compression. Available formats are xz, gzip
                        and bzip2. Use ':<LEVEL>' to set a compression level.
                        I.e. --archive xz:6. See documentation for the
                        details. (default: gzip:6)

configuration files:
  --save-files          save folders and other files (see --files). (default:
                        False)
  --files FILES         save folders and other files as listed in this file.
                        One line per folder or file, non existant will be
                        ignored. Directory structure is replicated (copied via
                        'cp'). (default: -)

output options:
  -a ARCHIVE, --archive ARCHIVE
                        archive level compression. 'tar' to create a tar
                        archive, '-' to leave the backup uncompressed as a
                        folder. Other available formats are xz, gzip and
                        bzip2. Use ':<LEVEL>' to set a compression level. I.e.
                        --archive xz:6 (default: -)
  -o OUTDIR, --outdir OUTDIR
                        save database dump to 'outdir'. (default: .)
  -r ROTATE, --rotate ROTATE
                        rotate backups while keeping up 'R' old backups.Uses
                        filename to match '0=keep everything'. (default: 0)

verbosity:
  -q, --quiet           don't print anything except unrecoverable errors.
                        (default: False)
  -v, --verbose         print informations. (default: True)
  -V, --very-verbose    print even more informations. (default: False)
  --debug               print everything. (default: False)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zabbixbackup-0.0.1b7.tar.gz (35.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zabbixbackup-0.0.1b7-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file zabbixbackup-0.0.1b7.tar.gz.

File metadata

  • Download URL: zabbixbackup-0.0.1b7.tar.gz
  • Upload date:
  • Size: 35.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.1

File hashes

Hashes for zabbixbackup-0.0.1b7.tar.gz
Algorithm Hash digest
SHA256 558fe957770d621eba542e361f836c6bf7d017910013ea46ad06b31b2bc2c03a
MD5 c91aae4658f6fa6bb19e51cf6045b8f8
BLAKE2b-256 9e856184995afd7689990b3da7655cc7d0c9b184b10eb43568ccfb303c31673d

See more details on using hashes here.

File details

Details for the file zabbixbackup-0.0.1b7-py3-none-any.whl.

File metadata

  • Download URL: zabbixbackup-0.0.1b7-py3-none-any.whl
  • Upload date:
  • Size: 34.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.1

File hashes

Hashes for zabbixbackup-0.0.1b7-py3-none-any.whl
Algorithm Hash digest
SHA256 9c378ccea2d6586cbbd7f3eb6705754dd1ce902faca69e27c9194b37182bbfd1
MD5 2cdf7f18be67d50a928710b6e44d9394
BLAKE2b-256 5242b0f26e6bca8b24138686b09da25f2aed4ba65b1f5dff011e56015cecd3c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page