From 8edcab8d11d565248a141f7369c4f8f88d7ba198 Mon Sep 17 00:00:00 2001 From: Sem Date: Wed, 22 Jul 2026 23:53:22 +0200 Subject: [PATCH 1/5] Add start of script to update zabbix --- update-zabbix-backup-status.sh | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 update-zabbix-backup-status.sh diff --git a/update-zabbix-backup-status.sh b/update-zabbix-backup-status.sh new file mode 100755 index 0000000..8d94ab3 --- /dev/null +++ b/update-zabbix-backup-status.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# script to send info about a backup to zabbix. +# Usage: +# update-zabbix-backup-status.sh [-sf] HOSTNAME SERVICE_NAME [DURATION] [SIZE] +# parameters: +# -s Backup succeeded (required if not failed) +# -f Backup failed (required if not succeeded) +# HOSTNAME hostname of the host that performed the backup +# SERVICE_NAME name of the service that was backed up +# DURATION duration of the backup +# SIZE Size in bytes of the transfered files + +function print_help +{ + echo "script to send info about a backup to zabbix." + echo "Usage:" + echo " update-zabbix-backup-status.sh [-sf] HOSTNAME SERVICE_NAME [DURATION] [SIZE]" + echo "parameters:" + echo " -s Backup succeeded (required if not failed)" + echo " -f Backup failed (required if not succeeded)" + echo " -h Show this message" + echo " HOSTNAME hostname of the host that performed the backup" + echo " SERVICE_NAME name of the service that was backed up" + echo " DURATION duration of the backup. Only needed if succeeded" + echo " SIZE Size in bytes of the transfered files. Only needed if succeeded" +} + +if [ -z $1 ] +then + echo "Please provide arguments. Use -h to show help" + exit 0 +fi + +if [ "$1" = "-h" ] +then + print_help +fi + +if ! command -v zabbix_sender >/dev/null 2>&1 +then + echo "zabbix_sender could not be found. Is it and the zabbix_agent2 installed?" + exit 1 +fi + +# TODO implement sending items to zabbix +# Use zabbix_sender directly? (for some reason not installed on games vm) https://www.zabbix.com/documentation/current/en/manual/concepts/sender + +# Or create python script and use python library? https://www.zabbix.com/documentation/current/en/devel/python +# if using python script I can run the rsync backup command using subprocess, and catch the output of that +# then I can check the bytes sent to calculate the size + \ No newline at end of file From 4948114cfcc6bfa7ae16f7b32c4a14c32614feb2 Mon Sep 17 00:00:00 2001 From: SemvdHoeven Date: Fri, 24 Jul 2026 10:19:00 +0200 Subject: [PATCH 2/5] Add script to send info to zabbix --- send-zabbix-backup-info.sh | 27 +++++++++++++++++++++++++++ tar-and-backup-service.sh | 30 +++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 send-zabbix-backup-info.sh diff --git a/send-zabbix-backup-info.sh b/send-zabbix-backup-info.sh new file mode 100644 index 0000000..e3e9ea0 --- /dev/null +++ b/send-zabbix-backup-info.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +if [ $# -eq 0 ] +then + echo "No argument supplied. Use this script with:" + echo "send-zabbix-backup-info.sh " + exit 0 +fi + +SERVICE_NAME=$1 +DURATION_MS=$2 +FILES_CREATED=$3 +BYTES_SENT=$4 +END_DATE=$5 + +if ! command -v zabbix_sender >/dev/null 2>&1 +then + echo "zabbix_sender could not be found. Is the package zabbix-sender installed?" + exit 1 +fi +echo " == Sending backup information to zabbix" +# send completed +zabbix_sender -s "$(hostname)" -k "backup.status[$SERVICE_NAME] -o 1" +zabbix_sender -s "$(hostname)" -k "backup.duration[$SERVICE_NAME] -o $DURATION_MS" +zabbix_sender -s "$(hostname)" -k "backup.files[$SERVICE_NAME] -o $FILES_CREATED" +zabbix_sender -s "$(hostname)" -k "backup.bytes[$SERVICE_NAME] -o $BYTES_SENT" +zabbix_sender -s "$(hostname)" -k "backup.date[$SERVICE_NAME] -o '$END_DATE'" \ No newline at end of file diff --git a/tar-and-backup-service.sh b/tar-and-backup-service.sh index 88d923a..b79ae19 100755 --- a/tar-and-backup-service.sh +++ b/tar-and-backup-service.sh @@ -5,7 +5,8 @@ if [ $# -eq 0 ] then echo "No argument supplied. Use this script with:" - echo "tar-and-backup-service.sh " + echo "tar-and-backup-service.sh [-z]" + echo "Use the -z flag to also send information about the backup to zabbix" exit 0 fi @@ -13,10 +14,33 @@ SERVICE_NAME=$1 BACKUP_FOLDER=$2 TAR_FILE=$SERVICE_NAME.tar.gz +START_MS=$(date +%s%3N) + echo " == Backing up $SERVICE_NAME to $TAR_FILE" echo " == Creating tar.gz file" tar czvf $TAR_FILE $BACKUP_FOLDER echo " == transfering tar file" -rsync -avz --stats --progress $TAR_FILE sem@10.10.100.52:/home/sem/$SERVICE_NAME/ + +TMPFILE=$(mktemp) +rsync -avz --stats --progress $TAR_FILE sem@10.10.100.52:/home/sem/$SERVICE_NAME/ | tee "$TMPFILE" +RSYNC_OUTPUT="$(cat $TMPFILE)" +rm "$TMPFILE" + echo " == Removing local tar file" -rm $TAR_FILE \ No newline at end of file +rm $TAR_FILE + +BYTES_SENT=$(echo "$RSYNC_OUTPUT" | grep "Total transferred file size" | cut -d: -f2 | cut -d' ' -f2 | tr -d ' ' | tr -d ',') +FILES_CREATED=$(echo "$RSYNC_OUTPUT" | grep "Number of regular files transferred" | cut -d: -f2 | tr -d ' ') + +END_MS=$(date +%s%3N) +DURATION_MS=$((END_MS - START_MS)) +END_DATE=$(date "+%d-%m-%Y %H:%M:%S") + +echo " == Backup completed in $DURATION_MS ms" +echo " == Total bytes sent: $BYTES_SENT" +echo " == Total files created: $FILES_CREATED" + +if [ "$3" == "-z" ] +then + ./zabbix/send-zabbix-backup-info.sh $SERVICE_NAME $DURATION_MS $FILES_CREATED $BYTES_SENT "$END_DATE" +fi \ No newline at end of file From 6394f70fe5f45b26c681a5ad5b8d927763893a1b Mon Sep 17 00:00:00 2001 From: SemvdHoeven Date: Fri, 24 Jul 2026 11:03:48 +0200 Subject: [PATCH 3/5] Dont use folder for zabbix script --- tar-and-backup-service.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tar-and-backup-service.sh b/tar-and-backup-service.sh index b79ae19..ac52251 100755 --- a/tar-and-backup-service.sh +++ b/tar-and-backup-service.sh @@ -42,5 +42,5 @@ echo " == Total files created: $FILES_CREATED" if [ "$3" == "-z" ] then - ./zabbix/send-zabbix-backup-info.sh $SERVICE_NAME $DURATION_MS $FILES_CREATED $BYTES_SENT "$END_DATE" + ./send-zabbix-backup-info.sh $SERVICE_NAME $DURATION_MS $FILES_CREATED $BYTES_SENT "$END_DATE" fi \ No newline at end of file From 020fb93e2decd4975d55791172501df63203c723 Mon Sep 17 00:00:00 2001 From: SemvdHoeven Date: Fri, 24 Jul 2026 12:24:54 +0200 Subject: [PATCH 4/5] Execute zabbix script relative to current script --- tar-and-backup-service.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tar-and-backup-service.sh b/tar-and-backup-service.sh index ac52251..12c8393 100755 --- a/tar-and-backup-service.sh +++ b/tar-and-backup-service.sh @@ -42,5 +42,6 @@ echo " == Total files created: $FILES_CREATED" if [ "$3" == "-z" ] then - ./send-zabbix-backup-info.sh $SERVICE_NAME $DURATION_MS $FILES_CREATED $BYTES_SENT "$END_DATE" + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + "$SCRIPT_DIR/send-zabbix-backup-info.sh" $SERVICE_NAME $DURATION_MS $FILES_CREATED $BYTES_SENT "$END_DATE" fi \ No newline at end of file From b6dfcb949a58981d88ba8a074aa0e38ac2f07a15 Mon Sep 17 00:00:00 2001 From: Games Server Date: Fri, 24 Jul 2026 14:28:55 +0200 Subject: [PATCH 5/5] Make script executable --- send-zabbix-backup-info.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 send-zabbix-backup-info.sh diff --git a/send-zabbix-backup-info.sh b/send-zabbix-backup-info.sh old mode 100644 new mode 100755