Projekt

Allgemein

Profil

MailCow » Historie » Version 7

Jeremias Keihsler, 11.06.2024 09:47

1 1 Jeremias Keihsler
h1. MailCow
2
3 7 Jeremias Keihsler
h2. set max mail-size
4
5
taken from https://docs.mailcow.email/manual-guides/Postfix/u_e-postfix-attachment_size/
6
7 2 Jeremias Keihsler
h2. Backup-Mailserver
8
9
interesting article covering that topic
10
https://autoize.com/backup-mx-configuration-for-mailcow/
11
12 3 Jeremias Keihsler
h3. Backup
13 1 Jeremias Keihsler
14
taken from https://mailcow.github.io/mailcow-dockerized-docs/b_n_r_backup/
15
16
create backup-target-location
17
18
<pre><code class="shell">
19
mkdir /mnt/mailcow_backups
20
</code></pre>
21
22
create daily-backup-script @/etc/cron.daily/mailcow_backup.sh@
23
<pre><code class="shell">
24
#!/bin/sh
25
26
# Backup mailcow data
27
# https://mailcow.github.io/mailcow-dockerized-docs/b_n_r_backup/
28
29
set -e
30
31
OUT="$(mktemp)"
32
export MAILCOW_BACKUP_LOCATION="/mnt/mailcow_backups"
33
SCRIPT="/opt/mailcow-dockerized/helper-scripts/backup_and_restore.sh"
34
PARAMETERS="backup all"
35
OPTIONS="--delete-days 30"
36
37
# run command
38
set +e
39
"${SCRIPT}" ${PARAMETERS} ${OPTIONS} 2>&1 > "$OUT"
40
RESULT=$?
41
42
if [ $RESULT -ne 0 ]
43
    then
44
            echo "${SCRIPT} ${PARAMETERS} ${OPTIONS} encounters an error:"
45
            echo "RESULT=$RESULT"
46
            echo "STDOUT / STDERR:"
47
            cat "$OUT"
48
fi
49 3 Jeremias Keihsler
</code></pre>
50
51 5 Jeremias Keihsler
h2. automatically delete mails older than in any given mailbox/folder
52
53
<pre><code class="shell">
54
vim /usr/local/bin/tidyup_mailbox.sh
55
</code></pre>
56
57
<pre><code class="shell">
58
#!/bin/bash
59
60
# JKE 2023-10-16
61
# path to mailcow-dockerized
62
cd /opt/mailcow-dockerized
63
64
sudo docker compose exec dovecot-mailcow doveadm expunge -u 'user@example.com' mailbox 'FromServerMail' before 2w
65
sudo docker compose exec dovecot-mailcow doveadm expunge -u 'user@example.com' mailbox 'FromServerMail/Crond' before 6w
66
sudo docker compose exec dovecot-mailcow doveadm expunge -u 'user@example.com' mailbox 'FromServerMail/Fail2Ban_2' before 5d
67
sudo docker compose exec dovecot-mailcow doveadm expunge -u 'user@example.com' mailbox 'FromServerMail/Logwatch' before 2w
68
sudo docker compose exec dovecot-mailcow doveadm expunge -u 'user@example.com' mailbox 'FromServerMail/ztrash' before 1w
69
</code></pre>
70
71
add this to cron
72
73
<pre><code class="shell">
74
vim /etc/cron.d/tidyup_mailbox
75
</code></pre>
76
77
<pre><code class="shell">
78
# JKE 2023-10-16
79
#
80
#    min  hr   dom  month dow    user    command
81
#    -    -    -    -     -
82
#    |    |    |    |     |
83
#    |    |    |    |     +-day of week (0-7) sunday=0 or 7
84
#    |    |    |    +---------month (1-12)
85
#    |    |    +----------------day of month (1-31)
86
#    |    +-----------------------hour (0-23)
87
#    +------------------------------min (0-59)
88
#
89
     57   23   *    *     *    root    /usr/local/bin/tidyup_mailbox.sh
90
</code></pre>
91 3 Jeremias Keihsler
92
h2. Debug
93
94
h3. logs
95
96
in-memory logs are sometimes not enough ...
97 4 Jeremias Keihsler
find @mailcow.conf@, start in it's directory
98 3 Jeremias Keihsler
99
<pre><code class="shell">
100
docker compose logs
101 1 Jeremias Keihsler
</code></pre>
102 6 Jeremias Keihsler
103
h3. statistics with pflogsumm
104
105
taken from https://docs.mailcow.email/manual-guides/Postfix/u_e-postfix-pflogsumm/
106
107
<pre><code class="shell">
108
docker logs --since 24h $(docker ps -qf name=postfix-mailcow) | pflogsumm
109
</code></pre>
110
111
<pre><code class="shell">
112
# JKE 2024-06-11
113
#
114
#    min  hr   dom  month dow    user    command
115
#    -    -    -    -     -
116
#    |    |    |    |     |
117
#    |    |    |    |     +-day of week (0-7) sunday=0 or 7
118
#    |    |    |    +---------month (1-12)
119
#    |    |    +----------------day of month (1-31)
120
#    |    +-----------------------hour (0-23)
121
#    +------------------------------min (0-59)
122
#
123
     59   23   *    *     *    root    docker logs --since 24h $(docker ps -qf name=postfix-mailcow) | /usr/sbin/pflogsumm -d today | mail -s "Postfix Report of $(date)" postmaster@example.com
124
</code></pre>