diff --git a/calvados.sh b/calvados.sh index fdfc8a1..7504e1f 100755 --- a/calvados.sh +++ b/calvados.sh @@ -1,3 +1,94 @@ #!/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" +} \ No newline at end of file diff --git a/mail.sh b/mail.sh index f32a05f..82d5834 100755 --- a/mail.sh +++ b/mail.sh @@ -46,13 +46,22 @@ if [ -z "$TO" ] || [ -z "$SUBJECT" ]; then exit 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 CONTENT=$(cat ${1:--}) -MAILCMD="$SUDO $PODMAN exec -i $MAILCONTAINER /usr/sbin/sendmail -i -t" -if [ ! -z "$REMOTE" ]; then - MAILCMD="ssh $MAILSERVER_IP $MAILCMD" -fi +MAILCMD="$PODMANCMD exec -i $MAILCONTAINER /usr/sbin/sendmail -i -t" # construct mail header + content and pipe to sendmail cat < 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 + local sort=--sort=name + 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[@]} return $? } diff --git a/main.sh b/main.sh index 96b75ca..3507fda 100755 --- a/main.sh +++ b/main.sh @@ -3,6 +3,8 @@ # 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 @@ -22,7 +24,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.2.4" +VER="2.3.1" HERE=$(dirname "$0") THIS_SCRIPT=$0 @@ -38,6 +40,7 @@ show_help() { echo " show contents of archive (path from $NAS_ROOT)" echo ' -r, --restore ' 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 " " echo " -d, -w, -e must be run as superuser." @@ -133,6 +136,12 @@ while :; do do_restore $@ break ;; + -p|--proton) + MAIL_LOG_FILE="${log_file_name}.proton.log" + check_mac + proton_backup + break + ;; --) # End of all options. shift break