Projekt

Allgemein

Profil

MailCow » Historie » Version 5

Jeremias Keihsler, 16.10.2023 08:27

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