9 Commits
4 changed files with 79 additions and 23 deletions

No files matched your search

+1 -1
View File
@@ -3,4 +3,4 @@
HERE=$(dirname "$0") HERE=$(dirname "$0")
# local start # local start
sudo sh -c "nohup $HERE/main.sh -d </dev/null &" sudo sh -c "nohup $HERE/main.sh --dx </dev/null &"
+1 -1
View File
@@ -28,6 +28,6 @@ after_backup() {
copy_to_nas "$BACKUP_TARGET" "$NAS_TARGET" copy_to_nas "$BACKUP_TARGET" "$NAS_TARGET"
let rc=rc+$? let rc=rc+$?
#check_services #check_services
let rc=rc+$? #let rc=rc+$?
return $rc return $rc
} }
+63 -20
View File
@@ -26,11 +26,14 @@ LIST_EXT=list
SYNO_USB=/usr/syno/bin/synousbdisk SYNO_USB=/usr/syno/bin/synousbdisk
SYSTEMCTL_USER="/usr/bin/systemctl --user --machine=container@" SYSTEMCTL_USER="/usr/bin/systemctl --user --machine=container@"
SYSTEMCTL="/usr/bin/systemctl" SYSTEMCTL="/usr/bin/systemctl"
PODMAN=" sudo -u container podman" PODMAN=" sudo -u container -i podman"
CONTAINER_EXEC_USER=" $PODMAN exec" CONTAINER_EXEC_USER=" $PODMAN exec"
CONTAINER_SVC_UPDATE_USER=" $PODMAN auto-update" CONTAINER_SVC_UPDATE_USER=" $PODMAN auto-update"
CONTAINER_EXEC="podman exec" CONTAINER_EXEC="podman exec"
tagP1=".backup#"
tagP2=".tag"
LOG_RECIPIENT=hb242@pm.me LOG_RECIPIENT=hb242@pm.me
INFO=INFO INFO=INFO
WARN=WARN WARN=WARN
@@ -161,6 +164,8 @@ start_containers() {
if [ -d /var/containers ]; then if [ -d /var/containers ]; then
do_start_stop_containers start do_start_stop_containers start
let rc=rc+$? let rc=rc+$?
# warten bis alle wieder da sind
sleep 2m
fi fi
return $rc return $rc
} }
@@ -197,15 +202,34 @@ do_start_stop_containers() {
return $rc 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() { update_services() {
log $DEBUG "$DBG update_services()" log $DEBUG "$DBG update_services()"
mail_log $INFO "$INF update services" mail_log $INFO "$INF update services"
local upd=$($CONTAINER_SVC_UPDATE_USER 2>&1 | tee $LOG_FILE | egrep 'registry\s+true' | sed 's/^.* \([^[:space:]]*\/[^[:space:]]*\).*$/\1/g') 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[@]} check_pipe_rc ${PIPESTATUS[@]}
local rc=$? local rc=$?
for i in $upd; do for i in $upd; do
mail_log $INFO "$INF $i" mail_log $INFO "$INF updated: $i"
done 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 return $rc
} }
@@ -435,8 +459,8 @@ backup_dir() {
local root=$1 local root=$1
local archive=$2 local archive=$2
local dir=$3 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\"" 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 --exclude "@eaDir" -C "$root" "$dir" 2>>$LOG_FILE | gpg --batch -c --passphrase $PASSPHRASE -o "$archive" 2>>$LOG_FILE 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[@]} check_pipe_rc ${PIPESTATUS[@]}
return $? return $?
} }
@@ -495,11 +519,11 @@ set_log_info() {
mail_log $INFO ">>> " mail_log $INFO ">>> "
} }
backup_daily() { cron_backup_daily() {
# "master"-Server startet Backup auf NAS # "master"-Server startet Backup auf NAS
if [ -d $BACKUP_MASTER_CHECK ]; then if [ -d $BACKUP_MASTER_CHECK ]; then
log $DEBUG "$DBG starting daily backup on $NAS_HOSTNAME" 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) # alte Logs löschen (nur auf einem Server ausführen)
prune_logs prune_logs
@@ -512,6 +536,10 @@ backup_daily() {
nohup $THIS_SCRIPT -w >>$LOG_FILE 2>&1 </dev/null & nohup $THIS_SCRIPT -w >>$LOG_FILE 2>&1 </dev/null &
fi fi
backup_daily
}
backup_daily() {
mail_log $INFO ">>>>>>>>>> daily auto backup $VER for $HOST_NAME <<<<<<<<<<" mail_log $INFO ">>>>>>>>>> daily auto backup $VER for $HOST_NAME <<<<<<<<<<"
do_auto_backup backup_daily do_auto_backup backup_daily
@@ -642,7 +670,7 @@ list_archives() {
local target=$1 local target=$1
local targ=${NAS_ROOT//\//\\\/} # slashes escapen local targ=${NAS_ROOT//\//\\\/} # slashes escapen
log $DEBUG "$DBG > find \"$NAS_ROOT\" -type f -name \"*.$EXT\" | sed -E \"s/^$targ//\"" 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[@]} check_pipe_rc ${PIPESTATUS[@]}
return $? return $?
} }
@@ -734,8 +762,8 @@ mount_usb_device() {
fi fi
} }
# Check if auto mounted device is exfat and return mount point # Check if auto mounted device is exfat or vfat and return mount point
# (fn for consitence with linux fn) # (fn for consistence with linux fn)
# #
# $1 - device name # $1 - device name
# returns mount point # returns mount point
@@ -745,7 +773,7 @@ mount_usb_device_syno() {
local device=$1 local device=$1
log $DEBUG "$DBG > $SYNO_USB -info $device | grep -i \"file system\" | sed -E \"s/.*:\s*(.*)\s*/\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) 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." mail_log $ERROR "$ERR device $device not exfat formatted."
return 1 return 1
fi fi
@@ -756,6 +784,7 @@ mount_usb_device_syno() {
mail_log $ERROR "$ERR mount point \"$mount_point\" does not exist." mail_log $ERROR "$ERR mount point \"$mount_point\" does not exist."
return 1 return 1
fi fi
mount_point=$(check_syno_mount_point $mount_point)
echo $mount_point echo $mount_point
return 0 return 0
} }
@@ -820,6 +849,28 @@ umount_usb_device_linux() {
return $? 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 # USB-HDD suchen und Backup-Typ ermitteln
# #
# Der Typ wird über eine Datei auf der USB-HDD festgelegt: # Der Typ wird über eine Datei auf der USB-HDD festgelegt:
@@ -830,19 +881,11 @@ umount_usb_device_linux() {
check_backup_device() { check_backup_device() {
log $DEBUG "$DBG check_backup_drive( $@ )" log $DEBUG "$DBG check_backup_drive( $@ )"
local mount_point=$1 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/\"" 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) local tag=$(ls $mount_point/${tagP1}*${tagP2} 2>>$LOG_FILE | sed -E "s/.*$tagP1(.*)$tagP2/\1/" 2>>$LOG_FILE)
if [ $? -ne 0 ]; then 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 return 1
fi fi
echo $tag echo $tag
+14 -1
View File
@@ -3,6 +3,13 @@
# entrypoint for all actions # 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.16 10.05.2025 - fix mail.sh, log results of auto-update
# 2.1.15 09.05.2025 - podman 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.14 09.05.2025 - Fix mail.sh, homeserver.target, cleared all docker references
@@ -15,7 +22,7 @@
# 2.1.7 29.04.2025 - 1. Schritt zur Umstellung auf podman # 2.1.7 29.04.2025 - 1. Schritt zur Umstellung auf podman
# 2.1.6 29.04.2025 - weekly backup Sa->SO # 2.1.6 29.04.2025 - weekly backup Sa->SO
VER="2.1.16" VER="2.2.4"
HERE=$(dirname "$0") HERE=$(dirname "$0")
THIS_SCRIPT=$0 THIS_SCRIPT=$0
@@ -69,6 +76,12 @@ while :; do
show_help # Display a usage synopsis. show_help # Display a usage synopsis.
exit 0 exit 0
;; ;;
--dx)
MAIL_LOG_FILE="${log_file_name}.auto.log"
check_root
cron_backup_daily
break
;;
-d|--daily) -d|--daily)
MAIL_LOG_FILE="${log_file_name}.auto.log" MAIL_LOG_FILE="${log_file_name}.auto.log"
check_root check_root