Zabbix database backup utility for postgres and mysql
Project description
Zabbix backup python script
EXPERIMENTAL: DO NOT USE IN PRODUCTION
Install
pip install zabbixbackup
Usage
Create a backup connecting as user postgres to the db zabbix with schema zabbix
zabbixbackup psql --host 127.0.0.1 --user postgres --database zabbix --schema zabbix
Create a tar archive dump and save standard zabbix configuration files along with it.
zabbixbackup psql --host 127.0.0.1 --format tar --save-files
Create a "custom" archive and save it to a backup folder, rotate backups to retain only the last four.
zabbixbackup psql --host 127.0.0.1 --format custom --rotate 4
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)
Options documentation and examples
Main
- --read-zabbix-config
- --zabbix-config ZABBIX_CONFIG
- --read-mysql-config (MySQL specific)
- --mysql-config MYSQL_CONFIG (MySQL specific)
- --dry-run
Connection
- --host HOST (special for Postgres)
- --port PORT
- --sock SOCK (MySQL specific)
- --username USER
- --passwd PASSWD
- --database DBNAME
- --schema SCHEMA (Postgres specific)
- --reverse-lookup (NOT IMPLEMENTED)
Dump
Configuration files
Output
- --compression (Postgres specific)
- --format (Postgres specific)
- --archive
- --outdir
- --rotate
Verbosity
Database engine
<DBMS>
Database engine to use. Either postgresql or mysql (mariasql compatible).
Read zabbix configuration
--read-zabbix-config, -z
Default: False
Try to read database host and credentials from Zabbix config. The file is read and parsed trying to collect as much as possible. Every variable collected will be used if not already provided by user arguments.
Implicit if --zabbix-config is set.
Zabbix configuration file
--zabbix-config ZBX_CONFIG, -Z ZBX_CONFIG
Default: /etc/zabbix/zabbix_server.conf
Zabbix configuration file path.
Read MySQL configuration (MySQL specific)
--read-mysql-config, -c
Default: False
Read database host and credentials from MySQL config file.
Implicit if --mysql-config is set.
MySQL configuration file (MySQL specific)
--mysql-config MYSQL_CONFIG, -C MYSQL_CONFIG
Default: /etc/mysql/my.cnf
MySQL configuration file path.
Implicit if --read-mysql-config is set.
Dry run
--dry-run, -D
Default: False
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. This is meant only for inspection and debugging.
Hostname (special for Postgres)
--host, -H
Default: 127.0.0.1
Hostname/IP of DBMS server, to specify a blank value pass '-'.
For postgresql special rules might apply (see Postgres psql and pg_dump
online documentation for sockets).
Port
--port PORT, -P PORT
Default: 5432 for Postgres, 3306 for MySQL)
Database connection port.
Socket (Mysql specific)
--socket SOCK, -S SOCK
Default: None
Path to MySQL socket file. Alternative to specifying host.
Username
--user USER, -u USER
Default: zabbix
Username to use for the database connection.
Password
--passwd PASSWD, -p PASSWD
default: -
Database login password. Specify '-' for an interactive prompt.
For Postgres, a .pgpass will be created to connect to the database and then
deleted (might be saved with the backup).
Database name
--database DBNAME, -d DBNAME
Default: zabbix
The name of the database to connect to.
Database schema (Postgres specific)
--schema SCHEMA, -s SCHEMA
Default: public
The name of the schema to use.
Reverse lookup
--reverse-lookup, -n
Default: True
(NOT IMPLEMENTED) Perform a reverse lookup of the IP address for the host.
Unknown tables action
--unknown-action {dump,nodata,ignore,fail}, -U {dump,nodata,ignore,fail}
Default: ignore
Action for unknown tables.
Choose dump do dump the tables fully with definitions. nodata will include only
the definitions. ignore will skip the unknown tables. fail will abort the
backup in case of an unknown table.
Monitoring tables action
--monitoring-action {dump,nodata}, -U {dump,nodata}
Default: nodata
Action for monitoring table.
Choose dump do dump the tables fully with definitions. nodata will include only
the definitions.
Add columns
--add-columns, -N
Default: False
Add column names in INSERT clauses and quote them as needed.
Save configuration files
--save-files
Default: True
Save folders and other files in the backup (see --files).
File index to save with the backup
--files FILES
Default: '-'
Save folders and other files as listed in this index file.
Non existant will be ignored. Directory structure is replicated (copied via
cp).
File format: one line per folder or file.
if FILES is - then the standard files are selected, i.e:
/etc/zabbix/
/usr/lib/zabbix/
Postgres dump compression
--compression COMPRESSION
Default: 'None'
Passed as-is to pg_dump --compress, might be implied by format.
Postgres dump format
--format FORMAT
Default: 'custom'
Dump format, will mandate the file output format.
Available formats: plain, custom, directory, or tar (see postgres documentation).
Backup archive format
--archive ARCHIVE, -a ARCHIVE
Default: '-'
Backup archive format. '-' to leave the backup uncompressed as a folder.
Available formats are xz, gzip and bzip2. Use :<LEVEL> to set a compression
level. I.e. --archive xz:6.
Output directory
--outdir OUTDIR, -o OUTDIR
Default: '.'
The destination directory to save the backup to.
Backup rotation
--rotate ROTATE, -r ROTATE
Default: '0'
Rotate backups while keeping up 'R' old backups. Uses filenames to find old backups.
0 = keep everything.
Verbosity
--quiet, -q don't print anything except unrecoverable errors,
--verbose, -v print informations only,
--very-verbose, -V print even more informations,
--debug print everything.
Default: verbose
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] [-d DBNAME] [-s SCHEMA] [-n]
[-U {dump,nodata,ignore,fail}] [-M {dump,nodata}]
[-N] [--save-files] [--files FILES] [-x COMPRESSION]
[-f {plain,custom,directory,tar}] [-r ROTATE]
[-o OUTDIR] [-q | -v | -V | --debug]
options:
-h, --help
-z, --read-zabbix-config
-Z ZBX_CONFIG, --zabbix-config ZBX_CONFIG
-D, --dry-run
connection options:
-H HOST, --host HOST
-P PORT, --port PORT
-u USER, --username USER
-p PASSWD, --passwd PASSWD
-d DBNAME, --database DBNAME
-s SCHEMA, --schema SCHEMA
-n, --reverse-lookup
dump options:
-U {dump,nodata,ignore,fail}, --unknown-action {dump,nodata,ignore,fail}
-M {dump,nodata}, --monitoring-action {dump,nodata}
-N, --add-columns
configuration files:
--save-files
--files FILES
output options:
-a ARCHIVE, --archive ARCHIVE
-x COMPRESSION, --compression COMPRESSION
-f {tar,plain,custom,directory}
-r ROTATE, --rotate ROTATE
-o OUTDIR, --outdir OUTDIR
verbosity:
-q, --quiet
-v, --verbose
-V, --very-verbose
--debug
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] [-d DBNAME] [-n]
[-U {dump,nodata,ignore,fail}] [-M {dump,nodata}]
[-N] [--save-files] [--files FILES] [-r ROTATE]
[-o OUTDIR] [-q | -v | -V | --debug]
options:
-h, --help
-z, --read-zabbix-config
-Z ZBX_CONFIG, --zabbix-config ZBX_CONFIG
-c, --read-mysql-config
-C MYSQL_CONFIG, --mysql-config MYSQL_CONFIG
-D, --dry-run
connection options:
-H HOST, --host HOST
-P PORT, --port PORT
-S SOCK, --socket SOCK
-u USER, --username USER
-p PASSWD, --passwd PASSWD
-d DBNAME, --database DBNAME
-n, --reverse-lookup
dump options:
-U {dump,nodata,ignore,fail}, --unknown-action {dump,nodata,ignore,fail}
-M {dump,nodata}, --monitoring-action {dump,nodata}
-N, --add-columns
configuration files:
--save-files
--files FILES
output options:
-a ARCHIVE, --archive ARCHIVE
-r ROTATE, --rotate ROTATE
-o OUTDIR, --outdir OUTDIR
verbosity:
-q, --quiet
-v, --verbose
-V, --very-verbose
--debug
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zabbixbackup-0.0.1b2.tar.gz.
File metadata
- Download URL: zabbixbackup-0.0.1b2.tar.gz
- Upload date:
- Size: 31.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69b276f038c8562e2661811fb18712a4f652464e9c214df5539378436ed89f7a
|
|
| MD5 |
b0504a31c56c825232f00950cca3d054
|
|
| BLAKE2b-256 |
2aae6f1cad3c2f38fd5ea39e4b67fca1177e3474e614d2f4d66f85ff76100a29
|
File details
Details for the file zabbixbackup-0.0.1b2-py3-none-any.whl.
File metadata
- Download URL: zabbixbackup-0.0.1b2-py3-none-any.whl
- Upload date:
- Size: 31.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
affda00a09b824829804179543d28130f22c6512e7d91bda5a78ef66f955a3b6
|
|
| MD5 |
8b1b151f83d836e1913d1c6bdc9fd508
|
|
| BLAKE2b-256 |
281a57ee91bf1890f1652e78ac78f473b18dea1f1c585711346123d322b46e4e
|