10 Commits
6 changed files with 102 additions and 24 deletions

No files matched your search

+1 -1
View File
@@ -3,4 +3,4 @@
HERE=$(dirname "$0")
# local start
sudo sh -c "nohup $HERE/main.sh -d </dev/null &"
sudo sh -c "nohup $HERE/main.sh --dx </dev/null &"
+2 -2
View File
@@ -27,7 +27,7 @@ after_backup() {
let rc=rc+$?
copy_to_nas "$BACKUP_TARGET" "$NAS_TARGET"
let rc=rc+$?
check_services
let rc=rc+$?
#check_services
#let rc=rc+$?
return $rc
}
+5 -2
View File
@@ -13,7 +13,10 @@
#
PODMAN=/usr/bin/podman
SUDO="sudo -u container sh -c"
#
# -i ist entscheident, damit die restliche Kommandozeile sauber ausgewertet wird
# das ersetzt den expliziten Aufruf mit "sh -c "..." "
SUDO="sudo -u container -i"
MAILCONTAINER=smtp-relay
MAILSERVER_IP=10.4.2.30
REMOTE=""
@@ -48,7 +51,7 @@ CONTENT=$(cat ${1:--})
MAILCMD="$SUDO $PODMAN exec -i $MAILCONTAINER /usr/sbin/sendmail -i -t"
if [ ! -z "$REMOTE" ]; then
MAILCMD="ssh $MAILSERVER_IP \"$MAILCMD\""
MAILCMD="ssh $MAILSERVER_IP $MAILCMD"
fi
# construct mail header + content and pipe to sendmail
cat <<EOMB | $MAILCMD
+76 -18
View File
@@ -26,9 +26,14 @@ LIST_EXT=list
SYNO_USB=/usr/syno/bin/synousbdisk
SYSTEMCTL_USER="/usr/bin/systemctl --user --machine=container@"
SYSTEMCTL="/usr/bin/systemctl"
CONTAINER_EXEC_USER=" sudo -u container podman exec"
PODMAN=" sudo -u container -i podman"
CONTAINER_EXEC_USER=" $PODMAN exec"
CONTAINER_SVC_UPDATE_USER=" $PODMAN auto-update"
CONTAINER_EXEC="podman exec"
tagP1=".backup#"
tagP2=".tag"
LOG_RECIPIENT=hb242@pm.me
INFO=INFO
WARN=WARN
@@ -159,6 +164,8 @@ start_containers() {
if [ -d /var/containers ]; then
do_start_stop_containers start
let rc=rc+$?
# warten bis alle wieder da sind
sleep 2m
fi
return $rc
}
@@ -195,8 +202,40 @@ do_start_stop_containers() {
return $rc
}
# podman auto-update nach dem Backup starten
#
# Die fn schreibt sehr viel ins Log, damit der Update ggf. nachvollzogen werden kann,
# wenn etwas daneben geht.
#
update_services() {
log $DEBUG "$DBG update_services()"
mail_log $INFO "$INF update services"
local old_img=$($PODMAN ps --filter "label=io.containers.autoupdate=registry" --format "table {{.ImageID}} {{.Names}} {{.Image}}" --sort names)
echo "$old_img" >>$LOG_FILE 2>&1
local plan=$($CONTAINER_SVC_UPDATE_USER --dry-run --format "{{.Image}} {{.Updated}}" 2>&1 | grep pending | sed 's/^\(.*\) pending/\1/')
for i in $plan; do
mail_log $INFO "$INF pending: $i"
done
local upd=$($CONTAINER_SVC_UPDATE_USER --format "table {{.Image}} {{.Updated}}" 2>&1 | tee -a $LOG_FILE | grep true | sed 's/^\(.*\) true/\1/')
check_pipe_rc ${PIPESTATUS[@]}
local rc=$?
for i in $upd; do
mail_log $INFO "$INF updated: $i"
done
# warten bis alle wieder da sind (wg. ps)
sleep 2m >>$LOG_FILE 2>&1
local new_img=$($PODMAN ps --filter "label=io.containers.autoupdate=registry" --format "table {{.ImageID}} {{.Names}} {{.Image}}" --sort names)
echo "$new_img" >>$LOG_FILE 2>&1
# diff output bring zu wenig
#log $DEBUG "$DBG diff before after"
#local diff_img=$(diff <(echo "$old_img") <(echo "$new_img"))
#echo "$diff_img" >> $LOG_FILE
return $rc
}
check_services() {
log $DEBUG "$DBG check_services()"
mail_log $INFO "$INF check services"
$HERE/check.sh >>$LOG_FILE 2>&1
return $?
}
@@ -420,8 +459,8 @@ backup_dir() {
local root=$1
local archive=$2
local dir=$3
log $DEBUG "$DBG > tar -c -z --numeric-owner --one-file-system --exclude \"@eaDir\" -C \"$root\" \"$dir\" | gpg --batch -c --passphrase xxxx -o \"$archive\""
tar -c -z --numeric-owner --one-file-system --exclude "@eaDir" -C "$root" "$dir" 2>>$LOG_FILE | gpg --batch -c --passphrase $PASSPHRASE -o "$archive" 2>>$LOG_FILE
log $DEBUG "$DBG > tar -c -z --numeric-owner --one-file-system --sort=name --exclude \"@eaDir\" -C \"$root\" \"$dir\" | gpg --batch -c --passphrase xxxx -o \"$archive\""
tar -c -z --numeric-owner --one-file-system --sort=name --exclude "@eaDir" -C "$root" "$dir" 2>>$LOG_FILE | gpg --batch -c --passphrase $PASSPHRASE -o "$archive" 2>>$LOG_FILE
check_pipe_rc ${PIPESTATUS[@]}
return $?
}
@@ -480,11 +519,11 @@ set_log_info() {
mail_log $INFO ">>> "
}
backup_daily() {
cron_backup_daily() {
# "master"-Server startet Backup auf NAS
if [ -d $BACKUP_MASTER_CHECK ]; then
log $DEBUG "$DBG starting daily backup on $NAS_HOSTNAME"
run_script_remote $NAS_IP "$NAS_SCRIPT -d"
run_script_remote $NAS_IP "$NAS_SCRIPT --dx"
# alte Logs löschen (nur auf einem Server ausführen)
prune_logs
@@ -497,6 +536,10 @@ backup_daily() {
nohup $THIS_SCRIPT -w >>$LOG_FILE 2>&1 </dev/null &
fi
backup_daily
}
backup_daily() {
mail_log $INFO ">>>>>>>>>> daily auto backup $VER for $HOST_NAME <<<<<<<<<<"
do_auto_backup backup_daily
@@ -627,7 +670,7 @@ list_archives() {
local target=$1
local targ=${NAS_ROOT//\//\\\/} # slashes escapen
log $DEBUG "$DBG > find \"$NAS_ROOT\" -type f -name \"*.$EXT\" | sed -E \"s/^$targ//\""
find "$NAS_ROOT" -type f -name "*.$EXT" 2>>$LOG_FILE | sed -E "s/^$targ//" 2>>$LOG_FILE
find "$NAS_ROOT" -type f -name "*.$EXT" 2>>$LOG_FILE | sed -E "s/^$targ//" 2>>$LOG_FILE | sort
check_pipe_rc ${PIPESTATUS[@]}
return $?
}
@@ -719,8 +762,8 @@ mount_usb_device() {
fi
}
# Check if auto mounted device is exfat and return mount point
# (fn for consitence with linux fn)
# Check if auto mounted device is exfat or vfat and return mount point
# (fn for consistence with linux fn)
#
# $1 - device name
# returns mount point
@@ -730,7 +773,7 @@ mount_usb_device_syno() {
local device=$1
log $DEBUG "$DBG > $SYNO_USB -info $device | grep -i \"file system\" | sed -E \"s/.*:\s*(.*)\s*/\1/\""
local fs=$($SYNO_USB -info $device 2>>$LOG_FILE | grep -i "file system" 2>>$LOG_FILE | sed -E "s/.*:\s*(.*)\s*/\1/" 2>>$LOG_FILE)
if [ "$fs" != "exfat" ]; then
if [ "$fs" != "exfat" && "$fs" != "vfat" ]; then
mail_log $ERROR "$ERR device $device not exfat formatted."
return 1
fi
@@ -741,6 +784,7 @@ mount_usb_device_syno() {
mail_log $ERROR "$ERR mount point \"$mount_point\" does not exist."
return 1
fi
mount_point=$(check_syno_mount_point $mount_point)
echo $mount_point
return 0
}
@@ -805,6 +849,28 @@ umount_usb_device_linux() {
return $?
}
# Mit GUID-Partitontable meldet Synology die falsche Partition (/volumeUSB1/usbshare1-1)
# zusätzlich auf ggf. vorhandener 2. Partition (*1-2) suchen
#
# $1 - mount point
#
check_syno_mount_point() {
log $DEBUG "$DBG check_syno_mount_point( $@ )"
local mount_point=$1
log $DEBUG "$DBG > ls $mount_point/${tagP1}*${tagP2} | wc -l"
if [ "$(ls $mount_point/${tagP1}*${tagP2} 2>>$LOG_FILE | wc -l 2>>$LOG_FILE)" != "1" ]; then
log $DEBUG "No tag at mount point \"$mount_point\". Checking next partiton."
mount_point=$(echo $mount_point | sed -E "s/(.*1)-1/\1-2/")
if [ "$(ls $mount_point/${tagP1}*${tagP2} 2>>$LOG_FILE | wc -l 2>>$LOG_FILE)" != "1" ]; then
mail_log $ERROR "$ERR no tag found on device at $mount_point."
return 1
fi
fi
echo $mount_point
}
# USB-HDD suchen und Backup-Typ ermitteln
#
# Der Typ wird über eine Datei auf der USB-HDD festgelegt:
@@ -815,19 +881,11 @@ umount_usb_device_linux() {
check_backup_device() {
log $DEBUG "$DBG check_backup_drive( $@ )"
local mount_point=$1
local tagP1=".backup#"
local tagP2=".tag"
log $DEBUG "$DBG > ls $mount_point/${tagP1}*${tagP2} | wc -l"
if [ "$(ls $mount_point/${tagP1}*${tagP2} 2>>$LOG_FILE | wc -l 2>>$LOG_FILE)" != "1" ]; then
mail_log $ERROR "$ERR no tag found on device at $mount_point."
return 1
fi
log $DEBUG "$DBG > ls $mount_point/${tagP1}*${tagP2} | sed -E \"s/.*$tagP1(.*)$tagP2/\1/\""
local tag=$(ls $mount_point/${tagP1}*${tagP2} 2>>$LOG_FILE | sed -E "s/.*$tagP1(.*)$tagP2/\1/" 2>>$LOG_FILE)
if [ $? -ne 0 ]; then
mail_log $ERROR "$ERR no tag found on device at $mount_point."
mail_log $ERROR "$ERR no valid tag found on device at $mount_point."
return 1
fi
echo $tag
+16 -1
View File
@@ -3,6 +3,15 @@
# entrypoint for all actions
#
# 2.2.4 30.07.2025 - inc delay (again) for container startup-check (2m)
# 2.2.3 24.06.2025 - Export-Disk kann exfat- oder vfat-formatiert sein,
# Export-Disk mit mehreren Partitonen erkennen
# 2.2.2 19.06.2025 - inc delay for container startup check, fix error in log output
# 2.2.1 16.06.2025 - delay container startup check
# 2.2.0 16.05.2025 - fixes for auto-update, podman migration done
# 2.1.17 11.05.2025 - bugfixes, sort tar archive, split daily/cron daily
# 2.1.16 10.05.2025 - fix mail.sh, log results of auto-update
# 2.1.15 09.05.2025 - podman auto-update
# 2.1.14 09.05.2025 - Fix mail.sh, homeserver.target, cleared all docker references
# 2.1.13 08.05.2025 - check if services are running after backup
# 2.1.12 08.05.2025 - mail.sh an neuen Container angepasst
@@ -13,7 +22,7 @@
# 2.1.7 29.04.2025 - 1. Schritt zur Umstellung auf podman
# 2.1.6 29.04.2025 - weekly backup Sa->SO
VER="2.1.13"
VER="2.2.4"
HERE=$(dirname "$0")
THIS_SCRIPT=$0
@@ -67,6 +76,12 @@ while :; do
show_help # Display a usage synopsis.
exit 0
;;
--dx)
MAIL_LOG_FILE="${log_file_name}.auto.log"
check_root
cron_backup_daily
break
;;
-d|--daily)
MAIL_LOG_FILE="${log_file_name}.auto.log"
check_root
+2
View File
@@ -45,6 +45,8 @@ after_backup() {
let rc=rc+$?
copy_to_nas "$BACKUP_TARGET" "$NAS_TARGET"
let rc=rc+$?
update_services
let rc=rc+$?
check_services
let rc=rc+$?
return $rc