3 Commits
4 changed files with 204 additions and 34 deletions

No files matched your search

+92 -1
View File
@@ -1,3 +1,94 @@
#!/usr/bin/eval bash #!/usr/bin/eval bash
# nothing to do PROTON_TARGET="/Users/hb/mnt/nas/backups/div"
PROTON_TARGET_FILE="proton_mail_pass.$EXT"
PROTON_ROOT="/Users/hb/Downloads"
PROTON_BACKUP_DIR="Proton_Backup"
PROTON_BACKUP="$PROTON_ROOT/$PROTON_BACKUP_DIR"
PROTON_MAIL_EXPORT="$PROTON_ROOT/proton-mail-export-cli"
PROTON_PASS_EXPORT="$PROTON_ROOT/Proton Pass_export"
check_proton() {
if [ ! -d "$PROTON_MAIL_EXPORT" ]; then
mail_log $ERROR "$ERR there is no Proton Mail export."
return 1
fi
# tr ist nötig, weil bei macOS führene blanks entfernt werden müssen
if [ "$(ls "$PROTON_PASS_EXPORT"*|wc -l|tr -d ' ')" != "1" ]; then
mail_log $ERROR "$ERR there is no Proton Pass export."
return 1
fi
if [ ! -d "$PROTON_TARGET" ]; then
mail_log $ERROR "$ERR could not find targe dir $PROTON_TARGET!"
return 1
fi
if [ -f "$PROTON_TARGET/$PROTON_TARGET_FILE" ]; then
log $DEBUG "$DBG > rm -f \"$PROTON_TARGET/$PROTON_TARGET_FILE\""
rm -f "$PROTON_TARGET/$PROTON_TARGET_FILE" >>$LOG_FILE 2>&1
fi
}
delete_proton_backup_dir() {
log $DEBUG "$DBG delete_proton_backup_dir()"
if [ -d "$PROTON_BACKUP" ]; then
log $DEBUG "$DBG > rm -rf \"$PROTON_BACKUP\""
rm -rf "$PROTON_BACKUP" >>$LOG_FILE 2>&1 && return 0
fi
return 1
}
create_proton_backup_dir() {
log $DEBUG "$DBG create_proton_backup_dir()"
delete_proton_backup_dir
log $DEBUG "$DBG > mkdir -p \"$PROTON_BACKUP\""
mkdir -p "$PROTON_BACKUP" >>$LOG_FILE 2>&1 && return 0
return 1
}
move_proton_exports() {
log $DEBUG "$DBG move_proton_exports()"
log $DEBUG "$DBG > mv \"$PROTON_MAIL_EXPORT\" \"$PROTON_BACKUP\""
mv "$PROTON_MAIL_EXPORT" "$PROTON_BACKUP" >>$LOG_FILE 2>&1
if [ $? -ne 0 ]; then return 1; fi
log $DEBUG "$DBG > mv \"$PROTON_PASS_EXPORT\"* \"$PROTON_BACKUP\""
mv "$PROTON_PASS_EXPORT"* "$PROTON_BACKUP" >>$LOG_FILE 2>&1
if [ $? -ne 0 ]; then return 1; fi
}
do_proton_backup() {
log $DEBUG "$DBG do_proton_backup()"
mail_log $INFO "$INF checking environment"
check_proton
is_error $? && return 1
mail_log $INFO "$INF create $PROTON_BACKUP"
create_proton_backup_dir
is_error $? && return 1
mail_log $INFO "$INF move Proton exports to source directory"
move_proton_exports
is_error $? && return 1
mail_log $INFO "$INF backing up Proton exports to $PROTON_TARGET/$PROTON_TARGET_FILE"
backup_directory "$PROTON_ROOT" "$PROTON_TARGET/$PROTON_TARGET_FILE" "$PROTON_BACKUP_DIR"
is_error $? && return 1
}
proton_backup() {
mail_log $INFO ">>>>>>>>>> Proton backup $VER at $HOST_NAME <<<<<<<<<<"
do_proton_backup
mail_log $INFO "$INF deleting $PROTON_BACKUP"
delete_proton_backup_dir
is_error $?
mail_log $DEBUG "$DBG rm -f \"$PROTON_PASS_EXPORT\"*"
mail_log $DEBUG "$(rm -f "$PROTON_PASS_EXPORT"* 2>&1)"
mail_log $INFO ">>>>>>>>>> end of Proton backup"
send_mail_log "Proton Backup"
}
+13 -4
View File
@@ -46,13 +46,22 @@ if [ -z "$TO" ] || [ -z "$SUBJECT" ]; then
exit exit
fi fi
PODMANCMD="$SUDO $PODMAN"
if [ ! -z "$REMOTE" ]; then
PODMANCMD="ssh $MAILSERVER_IP $PODMANCMD"
fi
# der Mail-Container sollte laufen, falls nicht, dann ist wahrscheinlich der Backup
# noch nicht durch => 30 Minuten warten
$PODMANCMD ps | grep $MAILCONTAINER >/dev/null
if [ $? -ne 0 ]; then
sleep 30m
fi
# Mail body aus Datei oder STDIN holen # Mail body aus Datei oder STDIN holen
CONTENT=$(cat ${1:--}) CONTENT=$(cat ${1:--})
MAILCMD="$SUDO $PODMAN exec -i $MAILCONTAINER /usr/sbin/sendmail -i -t" MAILCMD="$PODMANCMD exec -i $MAILCONTAINER /usr/sbin/sendmail -i -t"
if [ ! -z "$REMOTE" ]; then
MAILCMD="ssh $MAILSERVER_IP $MAILCMD"
fi
# construct mail header + content and pipe to sendmail # construct mail header + content and pipe to sendmail
cat <<EOMB | $MAILCMD cat <<EOMB | $MAILCMD
FROM: hb42@gmx.de FROM: hb42@gmx.de
+84 -28
View File
@@ -31,6 +31,9 @@ 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
@@ -149,6 +152,17 @@ check_root() {
exit 100 exit 100
fi fi
} }
# Ausführung auf macOS begrenzen
#
check_mac() {
if [[ "$(uname)" != "Darwin" ]]; then
log $ERROR "$ERR script works only on MAC."
echo "****"
echo "***** script works only on MAC! *****"
echo "****"
exit 110
fi
}
start_containers() { start_containers() {
local let rc=0 local let rc=0
@@ -161,6 +175,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
} }
@@ -205,22 +221,22 @@ do_start_stop_containers() {
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 old_img=$($PODMAN ps --format "table {{.ImageID}} {{.Names}} {{.Image}}" --sort names) 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 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/') local plan=$($CONTAINER_SVC_UPDATE_USER --dry-run --format "{{.Image}} {{.Updated}}" 2>&1 | grep pending | sed 's/^\(.*\) pending/\1/')
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=$?
# warten bis alle wieder da sind (wg. ps)
sleep 20
local new_img=$($PODMAN ps --format "table {{.ImageID}} {{.Names}} {{.Image}}" --sort names)
echo "$new_img" >>$LOG_FILE 2>&1
for i in $plan; do for i in $plan; do
mail_log $INFO "$INF pending: $i" mail_log $INFO "$INF pending: $i"
done 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 for i in $upd; do
mail_log $INFO "$INF updated: $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 # diff output bring zu wenig
#log $DEBUG "$DBG diff before after" #log $DEBUG "$DBG diff before after"
#local diff_img=$(diff <(echo "$old_img") <(echo "$new_img")) #local diff_img=$(diff <(echo "$old_img") <(echo "$new_img"))
@@ -429,7 +445,29 @@ backup_all_dirs() {
for dir in $(iterate_dirs_in "$root" "$@"); do for dir in $(iterate_dirs_in "$root" "$@"); do
tar_file="$target/$prefix-$dir.$EXT" tar_file="$target/$prefix-$dir.$EXT"
backup_dir "$root" "$tar_file" "$dir" backup_directory "$root" "$tar_file" "$dir"
if [ $? -ne 0 ]; then return 1; fi
done
return 0
}
# Einzelnes Verzeichnis sichern und Backup prüfen
#
# $1 - Pfad zum Verzeichnis, das gesichert werden soll
# $2 - Zielpfad und -name für das Archiv
# $2 - zu sicherndes Verzeichnis
#
# returns 0 for success, 1 otherwise
#
backup_directory() {
log $DEBUG "$DBG backup_directory( $@ )"
local root=$1
local tar_file=$2
local dir=$3
tar_dir "$root" "$tar_file" "$dir"
if [ $? -ne 0 ]; then return 1; fi if [ $? -ne 0 ]; then return 1; fi
create_list "$tar_file" "$dir" create_list "$tar_file" "$dir"
@@ -437,25 +475,28 @@ backup_all_dirs() {
test_integrity "$tar_file" test_integrity "$tar_file"
if [ $? -ne 0 ]; then return 1; fi if [ $? -ne 0 ]; then return 1; fi
done
return 0
} }
# Einzelnes Verzeichnis sichern. # Einzelnes Verzeichnis sichern.
# #
# $1 - Pfad um Verzeichnis, das gesichert werden soll # $1 - Pfad zum Verzeichnis, das gesichert werden soll
# $2 - Zielpfad und -name für das Archiv # $2 - Zielpfad und -name für das Archiv
# $2 - zu sicherndes Verzeichnis # $2 - zu sicherndes Verzeichnis
# #
# returns 0 for success, 1 otherwise # returns 0 for success, 1 otherwise
# #
backup_dir() { tar_dir() {
log $DEBUG "$DBG backup_dir( $@ )" log $DEBUG "$DBG tar_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 --sort=name --exclude \"@eaDir\" -C \"$root\" \"$dir\" | gpg --batch -c --passphrase xxxx -o \"$archive\"" local sort=--sort=name
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 if [[ "$(uname)" == "Darwin" ]]; then
sort=""
fi
log $DEBUG "$DBG > tar -c -z --numeric-owner --one-file-system $sort --exclude \"@eaDir\" -C \"$root\" \"$dir\" | gpg --batch -c --passphrase xxxx -o \"$archive\""
tar -c -z --numeric-owner --one-file-system $sort --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 $?
} }
@@ -757,8 +798,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
@@ -768,7 +809,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
@@ -779,6 +820,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
} }
@@ -843,6 +885,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:
@@ -853,19 +917,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
+15 -1
View File
@@ -3,6 +3,13 @@
# entrypoint for all actions # entrypoint for all actions
# #
# 2.3.1. 16.08.2025 - 30 min delay for mail.sh
# 2.3.0 12.08.2025 - new function for backup & encryption of Proton exports
# 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.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.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
@@ -17,7 +24,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.2.0" VER="2.3.1"
HERE=$(dirname "$0") HERE=$(dirname "$0")
THIS_SCRIPT=$0 THIS_SCRIPT=$0
@@ -33,6 +40,7 @@ show_help() {
echo " show contents of archive (path from $NAS_ROOT)" echo " show contents of archive (path from $NAS_ROOT)"
echo ' -r, --restore <archive> <file(s)> ' echo ' -r, --restore <archive> <file(s)> '
echo " restore files from archive to $RESTORE_PATH" echo " restore files from archive to $RESTORE_PATH"
echo " -p, --proton backup and encrypt Proton exports (MacBook only)"
echo " -h, -?. --help show this help" echo " -h, -?. --help show this help"
echo " " echo " "
echo " -d, -w, -e must be run as superuser." echo " -d, -w, -e must be run as superuser."
@@ -128,6 +136,12 @@ while :; do
do_restore $@ do_restore $@
break break
;; ;;
-p|--proton)
MAIL_LOG_FILE="${log_file_name}.proton.log"
check_mac
proton_backup
break
;;
--) # End of all options. --) # End of all options.
shift shift
break break