Benutzer-Werkzeuge

Webseiten-Werkzeuge


tachtler:dovecot_backup_-_skript

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
tachtler:dovecot_backup_-_skript [2021/10/02 09:15] – [Zstandard (zstd)] klaustachtler:dovecot_backup_-_skript [2023/07/05 19:07] (aktuell) – [Dovecot Backup - Skript] klaus
Zeile 12: Zeile 12:
  
 ^ Beschreibung  ^ Externer Link                                                                   ^ ^ Beschreibung  ^ Externer Link                                                                   ^
-| Linux-Magazin | [[http://www.linux-magazin.de/ausgaben/2018/06/backups-von-e-mails/|Wie Admins ihre Mailserver vor Datenverlust schützen]] / {{ :tachtler:protected:054-058_email_backup_v2.pdf |Artikel aus Ausgabe 06/2018}} |+| Linux-Magazin | [[http://www.linux-magazin.de/ausgaben/2018/06/backups-von-e-mails/|Wie Admins ihre Mailserver vor Datenverlust schützen]]\\ [[https://www.linux-magazin.de/ausgaben/2018/06/backups-von-e-mails/4/|Wie Admins ihre Mailserver vor Datenverlust schützen (Seite 4) - Erwähnung]]\\ {{ :tachtler:protected:054-058_email_backup_v2.pdf |Artikel aus Ausgabe 06/2018 - geschützt}} |
 | Homepage      | [[http://dovecot.org|http://dovecot.org]]                                       | | Homepage      | [[http://dovecot.org|http://dovecot.org]]                                       |
 | Dokumentation | [[http://dovecot.org/documentation.html|http://dovecot.org/documentation.html]] | | Dokumentation | [[http://dovecot.org/documentation.html|http://dovecot.org/documentation.html]] |
Zeile 28: Zeile 28:
  
 **__CentOS 7__** **__CentOS 7__**
 +
 +Zur Installation von [[https://de.wikipedia.org/wiki/Zstandard|Zstandard (zstd)]] über ein **''rpm''**-Paket, soll hier das Repository eines Drittanbieters genutzt werden, da [[https://de.wikipedia.org/wiki/Zstandard|Zstandard (zstd)]] **__nicht__** im [[http://centos.org|CentOS]]-Repository enthalten ist.
 +
 +Nachfolgend soll das Repository des Drittanbieters [[https://fedoraproject.org/wiki/EPEL|EPEL]] genutzt werden. Eine Anleitung, wie das Repository des Drittanbieters [[https://fedoraproject.org/wiki/EPEL|EPEL]] eingebunden werden könnte, kann unter nachfolgendem internen Link nachgelesen werden:
 +  * [[tachtler:epel_centos_7|EPEL CentOS 7]]
  
 Zur Installation der Komprimierungsmethode [[https://de.wikipedia.org/wiki/Zstandard|Zstandard (zstd)]] wird nachfolgendes Paket benötigt: Zur Installation der Komprimierungsmethode [[https://de.wikipedia.org/wiki/Zstandard|Zstandard (zstd)]] wird nachfolgendes Paket benötigt:
Zeile 224: Zeile 229:
  
 <code bash> <code bash>
-#!/bin/bash+#!/usr/bin/env bash
  
 ############################################################################## ##############################################################################
Zeile 233: Zeile 238:
 #               will be send by e-mail.                                      # #               will be send by e-mail.                                      #
 #                                                                            # #                                                                            #
-# Last update : 02.10.2021                                                   # +# Last update : 03.07.2023                                                   # 
-# Version     : 1.18                                                         #+# Version     : 1.20                                                         #
 #                                                                            # #                                                                            #
 # Author      : Klaus Tachtler, <klaus@tachtler.net>                         # # Author      : Klaus Tachtler, <klaus@tachtler.net>                         #
Zeile 243: Zeile 248:
 #  | This program is free software; you can redistribute it and/or modify |  # #  | This program is free software; you can redistribute it and/or modify |  #
 #  | it under the terms of the GNU General Public License as published by |  # #  | it under the terms of the GNU General Public License as published by |  #
-#  | the Free Software Foundation; either version of the License, or    |  #+#  | the Free Software Foundation; either version of the License, or    |  #
 #  | (at your option) any later version.                                  |  # #  | (at your option) any later version.                                  |  #
 #  +----------------------------------------------------------------------+  # #  +----------------------------------------------------------------------+  #
 #                                                                            # #                                                                            #
-# Copyright (c) 2021 by Klaus Tachtler.                                      #+# Copyright (c) 2023 by Klaus Tachtler.                                      #
 #                                                                            # #                                                                            #
 ############################################################################## ##############################################################################
Zeile 301: Zeile 306:
 # Version     : 1.08                                                         # # Version     : 1.08                                                         #
 # Description : GitHub Issue #9                                              # # Description : GitHub Issue #9                                              #
-#               Add ability to only backup specific mailboxes, by using the  #+#               Add ability to only backup specific mailboxes, by using the  # 
 #               variable FILE_USERLIST with the file path and file name as   # #               variable FILE_USERLIST with the file path and file name as   #
 #               content. The file must contain one e-mail address per line.  # #               content. The file must contain one e-mail address per line.  #
Zeile 370: Zeile 375:
 #               The error handling was also been improved.                   # #               The error handling was also been improved.                   #
 #               Thanks to Marco De Lellis.                                   # #               Thanks to Marco De Lellis.                                   #
 +# -------------------------------------------------------------------------- #
 +# Version     : 1.19                                                         #
 +# Description : GitHub: Issue #24                                            #
 +#               Correct the license mismatch between GitHub and the script.  #
 +#               Thanks to David Haerdeman (Alphix).                          #
 +# -------------------------------------------------------------------------- #
 +# Version     : 1.20                                                         #
 +# Description : GitHub: Pull request #26                                     #
 +#               Improved FreeBSD compatibility.                              #
 +#               Thanks to wombelix (Dominik Wombacher)                       #
 # -------------------------------------------------------------------------- # # -------------------------------------------------------------------------- #
 # Version     : x.xx                                                         # # Version     : x.xx                                                         #
Zeile 421: Zeile 436:
  
 # Variables. # Variables.
-DSYNC_COMMAND=`command -v dsync` 
 TAR_COMMAND=`command -v tar` TAR_COMMAND=`command -v tar`
 GZIP_COMMAND=`command -v gzip` GZIP_COMMAND=`command -v gzip`
Zeile 449: Zeile 463:
 VAR_COUNT_USER=0 VAR_COUNT_USER=0
 VAR_COUNT_FAIL=0 VAR_COUNT_FAIL=0
 +
 +# FreeBSD specific commands
 +if [ "$OSTYPE" = "FreeBSD" ]; then
 +        DSYNC_COMMAND=`command -v doveadm`
 +        STAT_COMMAND_PARAM_FORMAT='-f'
 +        STAT_COMMAND_ARG_FORMAT_USER='%Su'
 +        STAT_COMMAND_ARG_FORMAT_GROUP='%Sg'
 +        MKTEMP_COMMAND_PARAM_ARG="-d ${TMP_FOLDER}/${SCRIPT_NAME}-XXXXXXXXXXXX"
 +else
 + DSYNC_COMMAND=`command -v dsync`
 +        STAT_COMMAND_PARAM_FORMAT='-c'
 +        STAT_COMMAND_ARG_FORMAT_USER='%U'
 +        STAT_COMMAND_ARG_FORMAT_GROUP='%G'
 +        MKTEMP_COMMAND_PARAM_ARG="-d -p ${TMP_FOLDER} -t ${SCRIPT_NAME}-XXXXXXXXXXXX"
 +fi
  
 # Functions. # Functions.
 function log() { function log() {
- echo $1 +        echo $1 
- echo `$DATE_COMMAND '+%Y/%m/%d %H:%M:%S'` " INFO:" $1 >>${FILE_LAST_LOG}+        echo `$DATE_COMMAND '+%Y/%m/%d %H:%M:%S'` " INFO:" $1 >>${FILE_LAST_LOG}
 } }
  
 function retval() { function retval() {
 if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
- case "$?" in +        case "$?" in 
- *) +        *) 
- log "ERROR: Unknown error $?" +                log "ERROR: Unknown error $?" 
- ;; +        ;; 
- esac+        esac
 fi fi
 } }
Zeile 468: Zeile 497:
 function movelog() { function movelog() {
  $CAT_COMMAND $FILE_LAST_LOG >> $FILE_LOG  $CAT_COMMAND $FILE_LAST_LOG >> $FILE_LOG
- $RM_COMMAND -f $FILE_LAST_LOG+ $RM_COMMAND -f $FILE_LAST_LOG
  $RM_COMMAND -f $FILE_LOCK  $RM_COMMAND -f $FILE_LOCK
 } }
  
 function sendmail() { function sendmail() {
- case "$1" in +        case "$1" in 
- 'STATUS'+        'STATUS'
- MAIL_SUBJECT='Status execution '$SCRIPT_NAME' script.' +                MAIL_SUBJECT='Status execution '$SCRIPT_NAME' script.' 
- ;; +        ;; 
- *) +        *) 
- MAIL_SUBJECT='ERROR while execution '$SCRIPT_NAME' script !!!' +                MAIL_SUBJECT='ERROR while execution '$SCRIPT_NAME' script !!!' 
- ;; +        ;; 
- esac+        esac
  
- $CAT_COMMAND <<-MAIL >$FILE_MAIL +$CAT_COMMAND <<MAIL >$FILE_MAIL 
- Subject: $MAIL_SUBJECT +Subject: $MAIL_SUBJECT 
- Date: $VAR_EMAILDATE +Date: $VAR_EMAILDATE 
- From: $VAR_SENDER +From: $VAR_SENDER 
- To: $MAIL_RECIPIENT+To: $MAIL_RECIPIENT
  
- MAIL+MAIL
  
- $CAT_COMMAND $FILE_LAST_LOG >> $FILE_MAIL+$CAT_COMMAND $FILE_LAST_LOG >> $FILE_MAIL
  
- $PROG_SENDMAIL -f $VAR_SENDER -t $MAIL_RECIPIENT < $FILE_MAIL+$PROG_SENDMAIL -f $VAR_SENDER -t $MAIL_RECIPIENT < $FILE_MAIL
  
- $RM_COMMAND -f $FILE_MAIL+$RM_COMMAND -f $FILE_MAIL
  
 } }
Zeile 502: Zeile 531:
  CODE_ERROR="$1"  CODE_ERROR="$1"
  
- sendmail ERROR+        sendmail ERROR
  movelog  movelog
  exit $CODE_ERROR  exit $CODE_ERROR
Zeile 512: Zeile 541:
  LINE_COUNT=68  LINE_COUNT=68
  
- # Help variables. +        # Help variables. 
- WORD_COUNT=`echo $TEXT_INPUT | wc -c` +        WORD_COUNT=`echo $TEXT_INPUT | wc -c` 
- CHAR_AFTER=`expr $LINE_COUNT - $WORD_COUNT - 5` +        CHAR_AFTER=`expr $LINE_COUNT - $WORD_COUNT - 5` 
- LINE_SPACE=`expr $LINE_COUNT - 3`+        LINE_SPACE=`expr $LINE_COUNT - 3`
  
  # Format placeholder.  # Format placeholder.
Zeile 536: Zeile 565:
  LINE_COUNT=68  LINE_COUNT=68
  
- # Help variables. +        # Help variables. 
- WORD_COUNT=`echo $TEXT_INPUT | wc -c` +        WORD_COUNT=`echo $TEXT_INPUT | wc -c` 
- CHAR_AFTER=`expr $LINE_COUNT - $WORD_COUNT - 9`+        CHAR_AFTER=`expr $LINE_COUNT - $WORD_COUNT - 9`
  
  # Format placeholder.  # Format placeholder.
Zeile 556: Zeile 585:
 function checkcommand () { function checkcommand () {
  # Parameters.  # Parameters.
- TEXT_VARIABLE="$1+        CHECK_COMMAND="$1"
- CHECK_COMMAND="$2"+
  
- if [ ! -s "$2" ]; then + if [ ! -s "$1" ]; then 
- logline "Check if command '$TEXT_VARIABLE'|'$CHECK_COMMAND' was found " false+ logline "Check if command '$CHECK_COMMAND' was found " false
  error 10  error 10
  else  else
- logline "Check if command '$TEXT_VARIABLE'|'$CHECK_COMMAND' was found " true+ logline "Check if command '$CHECK_COMMAND' was found " true
  fi  fi
 } }
Zeile 573: Zeile 601:
 log "" log ""
 log "SCRIPT_NAME.................: $SCRIPT_NAME" log "SCRIPT_NAME.................: $SCRIPT_NAME"
 +log ""
 +log "OS_TYPE.....................: $OSTYPE"
 log "" log ""
 log "COMPRESSION.................: $COMPRESSION" log "COMPRESSION.................: $COMPRESSION"
Zeile 588: Zeile 618:
 # Check if compress extension is allowed. # Check if compress extension is allowed.
 if [[ $COMPRESSION != 'zst' && $COMPRESSION != 'gz' ]]; then if [[ $COMPRESSION != 'zst' && $COMPRESSION != 'gz' ]]; then
- logline "Check compression extension" false +        logline "Check compression extension" false 
- log "" +        log "" 
- log "ERROR: Compression extension $COMPRESSION unsupported: choose between zst and gz" +        log "ERROR: Compression extension $COMPRESSION unsupported: choose between gz and zst
- log "" +        log "" 
- error 19+        error 19
 fi fi
  
 # Check if command (file) NOT exist OR IS empty. # Check if command (file) NOT exist OR IS empty.
-checkcommand 'dsync' $DSYNC_COMMAND  +checkcommand $DSYNC_COMMAND 
-checkcommand 'tar' $TAR_COMMAND +checkcommand $TAR_COMMAND 
-checkcommand 'touch' $TOUCH_COMMAND +checkcommand $TOUCH_COMMAND 
-checkcommand 'rm' $RM_COMMAND +checkcommand $RM_COMMAND 
-checkcommand 'cat' $CAT_COMMAND +checkcommand $CAT_COMMAND 
-checkcommand 'date' $DATE_COMMAND +checkcommand $DATE_COMMAND 
-checkcommand 'mkdir' $MKDIR_COMMAND +checkcommand $MKDIR_COMMAND 
-checkcommand 'chown' $CHOWN_COMMAND +checkcommand $CHOWN_COMMAND 
-checkcommand 'chmod' $CHMOD_COMMAND +checkcommand $CHMOD_COMMAND 
-checkcommand 'grep' $GREP_COMMAND +checkcommand $GREP_COMMAND 
-checkcommand 'mktemp' $MKTEMP_COMMAND +checkcommand $MKTEMP_COMMAND 
-checkcommand 'mv' $MV_COMMAND +checkcommand $MV_COMMAND 
-checkcommand 'stat' $STAT_COMMAND +checkcommand $STAT_COMMAND 
-checkcommand 'sendmail' $PROG_SENDMAIL+checkcommand $PROG_SENDMAIL
  
 if [ $COMPRESSION = 'gz' ]; then if [ $COMPRESSION = 'gz' ]; then
- checkcommand 'gzip' $GZIP_COMMAND+        checkcommand $GZIP_COMMAND
 fi fi
  
 if [ $COMPRESSION = 'zst' ]; then if [ $COMPRESSION = 'zst' ]; then
- checkcommand 'zstd' $ZSTD_COMMAND+        checkcommand $ZSTD_COMMAND
 fi fi
  
 # Check if LOCK file NOT exist. # Check if LOCK file NOT exist.
 if [ ! -e "$FILE_LOCK" ]; then if [ ! -e "$FILE_LOCK" ]; then
- logline "Check if the script is NOT already runnig " true+        logline "Check if the script is NOT already runnig " true
  
- $TOUCH_COMMAND $FILE_LOCK+        $TOUCH_COMMAND $FILE_LOCK
 else else
- logline "Check if the script is NOT already runnig " false +        logline "Check if the script is NOT already runnig " false 
- log "" +        log "" 
- log "ERROR: The script was already running, or LOCK file already exists!" +        log "ERROR: The script was already running, or LOCK file already exists!" 
- log ""+        log ""
  error 20  error 20
 fi fi
Zeile 634: Zeile 664:
 # Check if TMP_FOLDER directory path NOT exists, else create it. # Check if TMP_FOLDER directory path NOT exists, else create it.
 if [ ! -d "$TMP_FOLDER" ]; then if [ ! -d "$TMP_FOLDER" ]; then
- logline "Check if TMP_FOLDER exists " false+        logline "Check if TMP_FOLDER exists " false
  $MKDIR_COMMAND -p $TMP_FOLDER  $MKDIR_COMMAND -p $TMP_FOLDER
-if [ "$?" != "0" ]; then + if [ "$?" != "0" ]; then 
- logline "Create temporary '$TMP_FOLDER' folder " false + logline "Create temporary '$TMP_FOLDER' folder " false 
- error 21 + error 21 
-else + else 
- logline "Create temporary '$TMP_FOLDER' folder " true + logline "Create temporary '$TMP_FOLDER' folder " true 
-fi+ fi
 else else
- logline "Check if TMP_FOLDER exists " true+        logline "Check if TMP_FOLDER exists " true
 fi fi
  
 # Check if TMP_FOLDER is owned by $MAILDIR_USER. # Check if TMP_FOLDER is owned by $MAILDIR_USER.
-if [ "$MAILDIR_USER" != `$STAT_COMMAND -c '%U' $TMP_FOLDER` ]; then +if [ "$MAILDIR_USER" != `$STAT_COMMAND $STAT_COMMAND_PARAM_FORMAT "$STAT_COMMAND_ARG_FORMAT_USER" $TMP_FOLDER` ]; then 
- logline "Check if TMP_FOLDER owner is $MAILDIR_USER " false+        logline "Check if TMP_FOLDER owner is $MAILDIR_USER " false
  $CHOWN_COMMAND -R $MAILDIR_USER:$MAILDIR_GROUP $TMP_FOLDER  $CHOWN_COMMAND -R $MAILDIR_USER:$MAILDIR_GROUP $TMP_FOLDER
-if [ "$?" != "0" ]; then + if [ "$?" != "0" ]; then 
- logline "Set ownership of TMP_FOLDER to $MAILDIR_USER:$MAILDIR_GROUP " false +         logline "Set ownership of TMP_FOLDER to $MAILDIR_USER:$MAILDIR_GROUP " false 
- error 22+ error 22 
 + else 
 +        logline "Set ownership of TMP_FOLDER to $MAILDIR_USER:$MAILDIR_GROUP " true 
 + fi
 else else
- logline "Set ownership of TMP_FOLDER to $MAILDIR_USER:$MAILDIR_GROUP " true +        logline "Check if TMP_FOLDER owner is $MAILDIR_USER " true
-fi +
-else +
- logline "Check if TMP_FOLDER owner is $MAILDIR_USER " true+
 fi fi
  
 # Check if TMP_FOLDER group is $MAILDIR_GROUP. # Check if TMP_FOLDER group is $MAILDIR_GROUP.
-if [ "$MAILDIR_GROUP" != `$STAT_COMMAND -c '%G' $TMP_FOLDER` ]; then +if [ "$MAILDIR_GROUP" != `$STAT_COMMAND $STAT_COMMAND_PARAM_FORMAT "$STAT_COMMAND_ARG_FORMAT_GROUP" $TMP_FOLDER` ]; then 
- logline "Check if TMP_FOLDER group is $MAILDIR_GROUP " false+        logline "Check if TMP_FOLDER group is $MAILDIR_GROUP " false
  $CHOWN_COMMAND -R $MAILDIR_USER:$MAILDIR_GROUP $TMP_FOLDER  $CHOWN_COMMAND -R $MAILDIR_USER:$MAILDIR_GROUP $TMP_FOLDER
-if [ "$?" != "0" ]; then + if [ "$?" != "0" ]; then 
- logline "Set ownership of TMP_FOLDER to $MAILDIR_USER:$MAILDIR_GROUP " false +         logline "Set ownership of TMP_FOLDER to $MAILDIR_USER:$MAILDIR_GROUP " false 
- error 23+ error 23 
 + else 
 +        logline "Set ownership of TMP_FOLDER to $MAILDIR_USER:$MAILDIR_GROUP " true 
 + fi
 else else
- logline "Set ownership of TMP_FOLDER to $MAILDIR_USER:$MAILDIR_GROUP " true +        logline "Check if TMP_FOLDER group is $MAILDIR_GROUP " true
-fi +
-else +
- logline "Check if TMP_FOLDER group is $MAILDIR_GROUP " true+
 fi fi
  
 # Check if DIR_BACKUP directory NOT exists, else create it. # Check if DIR_BACKUP directory NOT exists, else create it.
 if [ ! -d "$DIR_BACKUP" ]; then if [ ! -d "$DIR_BACKUP" ]; then
- logline "Check if DIR_BACKUP exists " false+        logline "Check if DIR_BACKUP exists " false
  $MKDIR_COMMAND -p $DIR_BACKUP  $MKDIR_COMMAND -p $DIR_BACKUP
-if [ "$?" != "0" ]; then + if [ "$?" != "0" ]; then 
- logline "Create backup '$DIR_BACKUP' folder " false + logline "Create backup '$DIR_BACKUP' folder " false 
- error 24 + error 24 
-else + else 
- logline "Create backup '$DIR_BACKUP' folder " true + logline "Create backup '$DIR_BACKUP' folder " true 
-fi+ fi
 else else
- logline "Check if DIR_BACKUP exists " true+        logline "Check if DIR_BACKUP exists " true
 fi fi
  
 # Check if DIR_BACKUP is owned by $MAILDIR_USER. # Check if DIR_BACKUP is owned by $MAILDIR_USER.
-if [ "$MAILDIR_USER" != `$STAT_COMMAND -c '%U' $DIR_BACKUP` ]; then +if [ "$MAILDIR_USER" != `$STAT_COMMAND $STAT_COMMAND_PARAM_FORMAT "$STAT_COMMAND_ARG_FORMAT_USER" $DIR_BACKUP` ]; then 
- logline "Check if DIR_BACKUP owner is $MAILDIR_USER " false+        logline "Check if DIR_BACKUP owner is $MAILDIR_USER " false
  $CHOWN_COMMAND -R $MAILDIR_USER:$MAILDIR_GROUP $DIR_BACKUP  $CHOWN_COMMAND -R $MAILDIR_USER:$MAILDIR_GROUP $DIR_BACKUP
-if [ "$?" != "0" ]; then + if [ "$?" != "0" ]; then 
- logline "Set ownership of DIR_BACKUP to $MAILDIR_USER:$MAILDIR_GROUP " false +         logline "Set ownership of DIR_BACKUP to $MAILDIR_USER:$MAILDIR_GROUP " false 
- error 25+ error 25 
 + else 
 +        logline "Set ownership of DIR_BACKUP to $MAILDIR_USER:$MAILDIR_GROUP " true 
 + fi
 else else
- logline "Set ownership of DIR_BACKUP to $MAILDIR_USER:$MAILDIR_GROUP " true +        logline "Check if DIR_BACKUP owner is $MAILDIR_USER " true
-fi +
-else +
- logline "Check if DIR_BACKUP owner is $MAILDIR_USER " true+
 fi fi
  
 # Check if DIR_BACKUP group is $MAILDIR_GROUP. # Check if DIR_BACKUP group is $MAILDIR_GROUP.
-if [ "$MAILDIR_GROUP" != `$STAT_COMMAND -c '%G' $DIR_BACKUP` ]; then +if [ "$MAILDIR_GROUP" != `$STAT_COMMAND $STAT_COMMAND_PARAM_FORMAT "$STAT_COMMAND_ARG_FORMAT_GROUP" $DIR_BACKUP` ]; then 
- logline "Check if DIR_BACKUP group is $MAILDIR_GROUP " false+        logline "Check if DIR_BACKUP group is $MAILDIR_GROUP " false
  $CHOWN_COMMAND -R $MAILDIR_USER:$MAILDIR_GROUP $DIR_BACKUP  $CHOWN_COMMAND -R $MAILDIR_USER:$MAILDIR_GROUP $DIR_BACKUP
-if [ "$?" != "0" ]; then + if [ "$?" != "0" ]; then 
- logline "Set ownership of DIR_BACKUP to $MAILDIR_USER:$MAILDIR_GROUP " false +         logline "Set ownership of DIR_BACKUP to $MAILDIR_USER:$MAILDIR_GROUP " false 
- error 26+ error 26 
 + else 
 +        logline "Set ownership of DIR_BACKUP to $MAILDIR_USER:$MAILDIR_GROUP " true 
 + fi
 else else
- logline "Set ownership of DIR_BACKUP to $MAILDIR_USER:$MAILDIR_GROUP " true +        logline "Check if DIR_BACKUP group is $MAILDIR_GROUP " true
-fi +
-else +
- logline "Check if DIR_BACKUP group is $MAILDIR_GROUP " true+
 fi fi
  
Zeile 719: Zeile 749:
 log "" log ""
 if [ ! -n "$FILE_USERLIST"  ]; then if [ ! -n "$FILE_USERLIST"  ]; then
- log "Check if the variable FILE_USERLIST is set ................[  NO  ]" +        log "Check if the variable FILE_USERLIST is set ................[  NO  ]" 
- log "Mailboxes to backup will be determined by doveadm user \"*\"."+        log "Mailboxes to backup will be determined by doveadm user \"*\"."
  
-for users in `doveadm user "*"`; do + for users in `doveadm user "*"`; do 
- VAR_LISTED_USER+=($users); + VAR_LISTED_USER+=($users); 
-done+ done
 else else
- logline "Check if the variable FILE_USERLIST is set " true +        logline "Check if the variable FILE_USERLIST is set " true 
- log "Mailboxes to backup will be read from file." +        log "Mailboxes to backup will be read from file." 
- log "" +        log "" 
- log "- File: [$FILE_USERLIST]"+        log "- File: [$FILE_USERLIST]"
  
-# Check if file exists. + # Check if file exists. 
-if [ -f "$FILE_USERLIST" ]; then + if [ -f "$FILE_USERLIST" ]; then 
- logline "- Check if FILE_USERLIST exists " true +         logline "- Check if FILE_USERLIST exists " true 
-else + else 
- logline "- Check if FILE_USERLIST exists " false +         logline "- Check if FILE_USERLIST exists " false 
- log "" +         log "" 
- error 30 + error 30 
-fi+ fi
  
-# Check if file is readable. + # Check if file is readable. 
-if [ -r "$FILE_USERLIST" ]; then + if [ -r "$FILE_USERLIST" ]; then 
- logline "- Check if FILE_USERLIST is readable " true +         logline "- Check if FILE_USERLIST is readable " true 
-else + else 
- logline "- Check if FILE_USERLIST is readable " false +         logline "- Check if FILE_USERLIST is readable " false 
- log "" +         log "" 
- error 31 + error 31 
-fi+ fi 
 + 
 + # Read file into variable. 
 + while IFS= read -r line 
 + do  
 + # Check for valid e-mail address. 
 + if [ $FILE_USERLIST_VALIDATE_EMAIL = 'Y' ]; then 
 + # Check if basic email address syntax is valid. 
 + if echo "${line}" | $GREP_COMMAND '^[a-zA-Z0-9.-]*@[a-zA-Z0-9.-]*\.[a-zA-Z0-9]*$' >/dev/null; then 
 + VAR_LISTED_USER+=($line); 
 + else 
 +        log "" 
 +         log "ERROR: The user: $line is NOT valid e-mail address!"
  
-# Read file into variable. +                 ((VAR_COUNT_FAIL++)) 
-while IFSread -r line +                 VAR_FAILED_USER+=($line)
-do + fi 
- # Check for valid e-mail address. + else
- if [ $FILE_USERLIST_VALIDATE_EMAIL = 'Y' ]then +
- # Check if basic email address syntax is valid. +
- if echo "${line}" | $GREP_COMMAND '^[a-zA-Z0-9.-]*@[a-zA-Z0-9.-]*\.[a-zA-Z0-9]*$' >/dev/null; then+
  VAR_LISTED_USER+=($line);  VAR_LISTED_USER+=($line);
- else 
- log "" 
- log "ERROR: The user: $line is NOT valid e-mail address!" 
- 
- ((VAR_COUNT_FAIL++)) 
- VAR_FAILED_USER+=($line); 
  fi  fi
- else 
- VAR_LISTED_USER+=($line); 
- fi 
  done <"$FILE_USERLIST"  done <"$FILE_USERLIST"
  
Zeile 781: Zeile 811:
  
 # Make temporary directory DIR_TEMP inside TMP_FOLDER. # Make temporary directory DIR_TEMP inside TMP_FOLDER.
-DIR_TEMP=$($MKTEMP_COMMAND -d -p $TMP_FOLDER -t $SCRIPT_NAME-XXXXXXXXXXXX)+DIR_TEMP=$($MKTEMP_COMMAND $MKTEMP_COMMAND_PARAM_ARG)
 if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
  logline "Create temporary '$DIR_TEMP' folder " false  logline "Create temporary '$DIR_TEMP' folder " false
Zeile 793: Zeile 823:
 $CHOWN_COMMAND -R $MAILDIR_USER:$MAILDIR_GROUP $DIR_TEMP $CHOWN_COMMAND -R $MAILDIR_USER:$MAILDIR_GROUP $DIR_TEMP
 if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
- logline "Set ownership of DIR_TEMP to $MAILDIR_USER:$MAILDIR_GROUP " false+        logline "Set ownership of DIR_TEMP to $MAILDIR_USER:$MAILDIR_GROUP " false
  error 41  error 41
 else else
- logline "Set ownership of DIR_TEMP to $MAILDIR_USER:$MAILDIR_GROUP " true+        logline "Set ownership of DIR_TEMP to $MAILDIR_USER:$MAILDIR_GROUP " true
  log ""  log ""
 fi fi
Zeile 811: Zeile 841:
  
  log "Extract mailbox data for user: $users ..."  log "Extract mailbox data for user: $users ..."
- $DSYNC_COMMAND -o plugin/quota= -f -u $users backup $MAILDIR_TYPE:$LOCATION+ 
 +        if [ "$OSTYPE" = "FreeBSD" ]; then 
 +         $DSYNC_COMMAND -o plugin/quota= backup -u $users $MAILDIR_TYPE:$LOCATION 
 + else 
 + $DSYNC_COMMAND -o plugin/quota= -f -u $users backup $MAILDIR_TYPE:$LOCATION 
 + fi
  
  # Check the status of dsync and continue the script depending on the result.  # Check the status of dsync and continue the script depending on the result.
Zeile 828: Zeile 863:
  VAR_FAILED_USER+=($users);  VAR_FAILED_USER+=($users);
  else  else
- log "Synchronization done for user: $users ..."+        log "Synchronization done for user: $users ..."
  
  cd $DIR_TEMP  cd $DIR_TEMP
  
  log "Packaging to archive for user: $users ..."  log "Packaging to archive for user: $users ..."
- $TAR_COMMAND -acvf $users-$FILE_BACKUP $USERPART --atime-preserve --preserve-permissions+ if [ "$OSTYPE" = "FreeBSD" ]; then 
 + $TAR_COMMAND -cvzf $users-$FILE_BACKUP $USERPART 
 + else 
 + $TAR_COMMAND -cvzf $users-$FILE_BACKUP $USERPART --atime-preserve --preserve-permissions 
 + fi
  
  log "Delete mailbox files for user: $users ..."  log "Delete mailbox files for user: $users ..."
- $RM_COMMAND "$DIR_TEMP/$DOMAINPART" -rf+ $RM_COMMAND -rf "$DIR_TEMP/$DOMAINPART"
  if [ "$?" != "0" ]; then  if [ "$?" != "0" ]; then
- logline "Delete mailbox files at: $DIR_TEMP " false+        logline "Delete mailbox files at: $DIR_TEMP " false
  else  else
- logline "Delete mailbox files at: $DIR_TEMP " true+        logline "Delete mailbox files at: $DIR_TEMP " true
  fi  fi
  
Zeile 846: Zeile 885:
  $MV_COMMAND "$DIR_TEMP/$users-$FILE_BACKUP" "$DIR_BACKUP"  $MV_COMMAND "$DIR_TEMP/$users-$FILE_BACKUP" "$DIR_BACKUP"
  if [ "$?" != "0" ]; then  if [ "$?" != "0" ]; then
- logline "Move archive file for user to: $DIR_BACKUP " false+        logline "Move archive file for user to: $DIR_BACKUP " false
  else  else
- logline "Move archive file for user to: $DIR_BACKUP " true+        logline "Move archive file for user to: $DIR_BACKUP " true
  fi  fi
  
Zeile 856: Zeile 895:
  (ls -t $users-$FILE_DELETE|head -n $BACKUPFILES_DELETE;ls $users-$FILE_DELETE)|sort|uniq -u|xargs -r rm  (ls -t $users-$FILE_DELETE|head -n $BACKUPFILES_DELETE;ls $users-$FILE_DELETE)|sort|uniq -u|xargs -r rm
  if [ "$?" != "0" ]; then  if [ "$?" != "0" ]; then
- logline "Delete old archive files from: $DIR_BACKUP " false+        logline "Delete old archive files from: $DIR_BACKUP " false
  else  else
- logline "Delete old archive files from: $DIR_BACKUP " true+        logline "Delete old archive files from: $DIR_BACKUP " true
  fi  fi
  fi  fi
  
  log "Ended backup process for user: $users ..."  log "Ended backup process for user: $users ..."
- log ""+        log ""
 done done
  
 # Delete the temporary folder DIR_TEMP. # Delete the temporary folder DIR_TEMP.
-$RM_COMMAND $DIR_TEMP -rf+$RM_COMMAND -rf $DIR_TEMP
 if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
  logline "Delete temporary '$DIR_TEMP' folder " false  logline "Delete temporary '$DIR_TEMP' folder " false
Zeile 879: Zeile 918:
 $CHOWN_COMMAND -R $MAILDIR_USER:$MAILDIR_GROUP $DIR_BACKUP $CHOWN_COMMAND -R $MAILDIR_USER:$MAILDIR_GROUP $DIR_BACKUP
 if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
- logline "Set ownership of DIR_BACKUP to $MAILDIR_USER:$MAILDIR_GROUP " false+        logline "Set ownership of DIR_BACKUP to $MAILDIR_USER:$MAILDIR_GROUP " false
  error 43  error 43
 else else
- logline "Set ownership of DIR_BACKUP to $MAILDIR_USER:$MAILDIR_GROUP " true+        logline "Set ownership of DIR_BACKUP to $MAILDIR_USER:$MAILDIR_GROUP " true
 fi fi
  
Zeile 888: Zeile 927:
 $CHMOD_COMMAND 700 $DIR_BACKUP $CHMOD_COMMAND 700 $DIR_BACKUP
 if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
- logline "Set permission of DIR_BACKUP to drwx------ " false+        logline "Set permission of DIR_BACKUP to drwx------ " false
  error 44  error 44
 else else
- logline "Set permission of DIR_BACKUP to drwx------ " true+        logline "Set permission of DIR_BACKUP to drwx------ " true
 fi fi
  
Zeile 897: Zeile 936:
 $CHMOD_COMMAND -R 600 $DIR_BACKUP/* $CHMOD_COMMAND -R 600 $DIR_BACKUP/*
 if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
- logline "Set file permissions in DIR_BACKUP to -rw------- " false+        logline "Set file permissions in DIR_BACKUP to -rw------- " false
  error 45  error 45
 else else
- logline "Set file permissions in DIR_BACKUP to -rw------- " true+        logline "Set file permissions in DIR_BACKUP to -rw------- " true
  log ""  log ""
 fi fi
Zeile 906: Zeile 945:
 # Delete LOCK file. # Delete LOCK file.
 if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
- retval $? +        retval $? 
- log "" +        log "" 
- $RM_COMMAND -f $FILE_LOCK+        $RM_COMMAND -f $FILE_LOCK
  error 99  error 99
 else else
  headerblock "End backup $SCRIPT_NAME "  headerblock "End backup $SCRIPT_NAME "
- log ""+        log ""
 fi fi
  
Zeile 931: Zeile 970:
 log "" log ""
 END_TIMESTAMP=`$DATE_COMMAND '+%s'` END_TIMESTAMP=`$DATE_COMMAND '+%s'`
-log "Runtime: `$DATE_COMMAND -u -d "0 $END_TIMESTAMP seconds - $RUN_TIMESTAMP seconds" +'%H:%M:%S'` time elapsed."+if [ "$OSTYPE" = "FreeBSD" ]; then 
 +        DELTA=$((END_TIMESTAMP-RUN_TIMESTAMP)) 
 +        log "$(printf 'Runtime: %02d:%02d:%02d time elapsed.\n' $((DELTA/3600)) $((DELTA%3600/60)) $((DELTA%60)))" 
 +else 
 + log "Runtime: `$DATE_COMMAND -u -d "0 $END_TIMESTAMP seconds - $RUN_TIMESTAMP seconds" +'%H:%M:%S'` time elapsed." 
 +fi
 log "" log ""
 headerblock "Finished creating the backups [`$DATE_COMMAND '+%a, %d %b %Y %H:%M:%S (%z)'`]" headerblock "Finished creating the backups [`$DATE_COMMAND '+%a, %d %b %Y %H:%M:%S (%z)'`]"
Zeile 938: Zeile 982:
 # If errors occurred on user backups, exit with return code 1 instead of 0. # If errors occurred on user backups, exit with return code 1 instead of 0.
 if [ "$VAR_COUNT_FAIL" -gt "0" ]; then if [ "$VAR_COUNT_FAIL" -gt "0" ]; then
- sendmail ERROR+        sendmail ERROR
  # Move the log to the permanent log file.  # Move the log to the permanent log file.
  movelog  movelog
Zeile 945: Zeile 989:
  # Status e-mail.  # Status e-mail.
  if [ $MAIL_STATUS = 'Y' ]; then  if [ $MAIL_STATUS = 'Y' ]; then
- sendmail STATUS+        sendmail STATUS
  fi  fi
  # Move the log to the permanent log file.  # Move the log to the permanent log file.
Zeile 986: Zeile 1030:
 # /root/Install/scripts/dovecot_backup.sh # /root/Install/scripts/dovecot_backup.sh
  
-+-----------------------------------------------------------------+++-------------------------------------------------------------------+
 | Start backup of the mailboxes [Sat, 02 Oct 2021 08:18:37 (+0200)] | | Start backup of the mailboxes [Sat, 02 Oct 2021 08:18:37 (+0200)] |
-+-----------------------------------------------------------------+++-------------------------------------------------------------------+
  
 SCRIPT_NAME.................: dovecot_backup SCRIPT_NAME.................: dovecot_backup
 +
 +OS_TYPE.....................: linux-gnu
  
 COMPRESSION.................: gz COMPRESSION.................: gz
Zeile 1074: Zeile 1120:
  
 SCRIPT_NAME.................: dovecot_backup SCRIPT_NAME.................: dovecot_backup
 +
 +OS_TYPE.....................: linux-gnu
  
 COMPRESSION.................: gz COMPRESSION.................: gz
tachtler/dovecot_backup_-_skript.1633158912.txt.gz · Zuletzt geändert: 2021/10/02 09:15 von klaus