Compare commits

...

7 Commits

Author SHA1 Message Date
a888dbaa05 Merge branch 'main' of https://gitty.interesting-corner.nl/sem/backup-scripts
add services folder with backup scripts for ymir
2026-08-09 14:48:24 +00:00
23bd1e4c20 Add services backup scripts 2026-08-09 14:47:19 +00:00
Games Server
b6dfcb949a Make script executable 2026-07-24 14:28:55 +02:00
SemvdHoeven
020fb93e2d Execute zabbix script relative to current script 2026-07-24 12:24:54 +02:00
SemvdHoeven
6394f70fe5 Dont use folder for zabbix script 2026-07-24 11:03:48 +02:00
SemvdHoeven
4948114cfc Add script to send info to zabbix 2026-07-24 10:19:00 +02:00
Sem
8edcab8d11 Add start of script to update zabbix 2026-07-22 23:53:22 +02:00
8 changed files with 206 additions and 3 deletions

27
send-zabbix-backup-info.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
if [ $# -eq 0 ]
then
echo "No argument supplied. Use this script with:"
echo "send-zabbix-backup-info.sh <servicename> <duration_ms> <files_created> <bytes_sent> <end_date>"
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'"

21
services/backup-docspell.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
echo "running backup docspell script at $(date)"
backup-scripts/start-backup.sh
echo "backing up docspell!"
echo "------------------"
cd /srv/docspell/docker/docker-compose/
echo "cd to $(pwd)"
echo "executing postgres pg_dump command"
docker exec -it postgres_db pg_dump -d dbname -U dbuser -Fc -f /opt/backup/docspell.sqlc
# then backup to backups vm
echo "sending sql backup to VM"
rsync --stats --progress -arv --ignore-times /backups/docspell-backup/* sem@10.10.100.52:/home/sem/docspell-backup/
echo "sending docspell dir to VM"
rsync --stats --progress -arv --ignore-times /srv/docspell/* sem@10.10.100.52:/home/sem/docspell-backup/
# run script using absolute path because docker backup command cd's to /srv/docspell
/backups/backup-scripts/stop-backup.sh

24
services/backup-immich.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
echo "running backup immich script at $(date)"
backup-scripts/start-backup.sh
echo "backing up immich!"
echo "------------------"
echo "backing up photos!"
# use the --update flag to update the remote only if a newer version is on the local filesystem"
rsync --stats --progress -arv --update /mass/photos/* sem@10.10.100.52:/home/sem/immich/immich_photos_backup/
echo "------------------"
echo "backing up config"
echo "executing backup command"
docker exec -t immich_postgres pg_dumpall --clean --if-exists --username=postgres | gzip > "/backups/immich_backup_dump.sgl.gz"
echo "sending config backup to VM"
rsync --stats --progress -arv /backups/immich_backup_dump.sgl.gz sem@10.10.100.52:/home/sem/immich/immich_backup_dump.sgl.gz
echo "------------------"
echo "backing up immich-app folder"
rsync --stats --progress -arv /home/sem/immich-app sem@10.10.100.52:/home/sem/immich/immich-app
backup-scripts/stop-backup.sh

18
services/backup-music.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/bash
echo "running backup music script at $(date)"
backup-scripts/start-backup.sh
echo "backing up music!"
# backup music to backups vm
rsync --stats --progress -arv --ignore-existing /home/sem/Music/* sem@10.10.100.52:/home/sem/music-backup/songs
echo "backing up db!"
rsync --stats --progress -arv /var/lib/navidrome/* --exclude /var/lib/navidrome/cache sem@10.10.100.52:/home/sem/music-backup/navidrome
echo "backing up config!"
rsync --stats --progress -arv /etc/navidrome/* sem@10.10.100.52:/home/sem/music-backup/navidrome
backup-scripts/stop-backup.sh

11
services/backup-trilium.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
echo "running backup trilium script at $(date)"
backup-scripts/start-backup.sh
echo "backing up trilium!"
echo "------------------"
rsync --stats --progress -arv --ignore-times /home/sem/trilium-data sem@10.10.100.52:/home/sem/
backup-scripts/stop-backup.sh

25
services/backup-webserver.sh Executable file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
echo "running backup webserver script at $(date)"
backup-scripts/start-backup.sh
echo "[since 27-03-2026] Not backing up webserver because it's tracked in gitea"
# echo "backing up webserver!"
# echo "------------------"
# rsync -arv /home/sem/webserver sem@10.10.100.52:/home/sem/webserver-backups/
echo "------------------"
echo "Backing up mysql database!"
echo "Creating database dump"
mysqldump -u root -p'Mmiiigod1j!mysql' --all-databases > /backups/all_databases.sql
echo "Sending database backup"
rsync --stats --progress -arv --ignore-times /backups/all_databases.sql sem@10.10.100.52:/home/sem/webserver-backups/
echo "------------------"
echo "Backing up library!"
rsync --stats --progress -arv /srv/library sem@10.10.100.52:/home/sem/webserver-backups/
backup-scripts/stop-backup.sh

View File

@@ -5,7 +5,8 @@
if [ $# -eq 0 ]
then
echo "No argument supplied. Use this script with:"
echo "tar-and-backup-service.sh <servicename> <foldername>"
echo "tar-and-backup-service.sh <servicename> <foldername> [-z]"
echo "Use the -z flag to also send information about the backup to zabbix"
exit 0
fi
@@ -13,10 +14,34 @@ 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
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
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

52
update-zabbix-backup-status.sh Executable file
View File

@@ -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