Skip to content
Open
Changes from all commits
Commits
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
19 changes: 17 additions & 2 deletions zabbix-dump
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ DEFAULT_DBPASS=""
COMPRESSION="gz"
QUIET="no"
REVERSELOOKUP="yes"
COLUMN_NAMES="no"
GENERATIONSTOKEEP=0
ZBX_CONFIG="/etc/zabbix/zabbix_server.conf"
READ_ZBX_CONFIG="yes"
Expand Down Expand Up @@ -149,6 +150,9 @@ OPTIONS
-n
Skip reverse lookup of IP address for host.

-N
Add column names in INSERT INTO .. VALUES .. and quote them as needed

-f
Force backup for unknown tables / forward compatibility:
Don't complain about unknown tables and make a full backup of them
Expand Down Expand Up @@ -194,7 +198,7 @@ fi
# PARSE COMMAND LINE ARGUMENTS
#
DB_GIVEN=0
while getopts ":c:S:d:H:o:p:P:r:s:t:u:z:0nqxZfiv" opt; do
while getopts ":c:S:d:H:o:p:P:r:s:t:u:z:0nNqxZfiv" opt; do
case $opt in
t) DBTYPE="$OPTARG" ;;
H) ODBHOST="$OPTARG" ;;
Expand All @@ -212,6 +216,7 @@ while getopts ":c:S:d:H:o:p:P:r:s:t:u:z:0nqxZfiv" opt; do
x) COMPRESSION="xz" ;;
0) COMPRESSION="" ;;
n) REVERSELOOKUP="no" ;;
N) COLUMN_NAMES="yes" ;;
f) HANDLE_UNKNOWN="backup" ;;
i) HANDLE_UNKNOWN="ignore" ;;
q) QUIET="yes" ;;
Expand Down Expand Up @@ -520,6 +525,11 @@ case $DBTYPE in

# dump data
DUMP_OPTS=(--opt --single-transaction --skip-lock-tables --no-create-info --skip-extended-insert)

if [ "${COLUMN_NAMES}" == "yes" ]; then
DUMP_OPTS+=( --complete-insert --quote-names )
fi

while read -r table; do
if elementIn "$table" "${SCHEMAONLY_TABLES[@]}"; then
DUMP_OPTS+=(--ignore-table=$DBNAME.$table)
Expand All @@ -537,7 +547,12 @@ case $DBTYPE in
if [ $? -ne 0 ]; then echo $'\nERROR: Could not backup table data.\n' >&2; cat $ERRORLOG >&2; exit 1; fi
;;
psql)
DUMP_OPTS=()
DUMP_OPTS=( --format=plain )

if [ "${COLUMN_NAMES}" == "yes" ]; then
DUMP_OPTS+=( --inserts --column-inserts --quote-all-identifiers )
fi

while read -r table; do
if [ $HANDLE_UNKNOWN == "ignore" ]; then
if elementIn "$table" "${UNKNOWN_TABLES[@]}"; then
Expand Down