Add mail delivery ability

This commit is contained in:
Adrien Ferrand 2017-04-21 21:57:14 +00:00
parent f6abba49fc
commit d20b133a69
3 changed files with 48 additions and 6 deletions

View File

@ -11,7 +11,7 @@ RUN apk --no-cache add \
# Install backuppc build dependencies # Install backuppc build dependencies
gcc g++ autoconf automake make git patch perl perl-dev perl-cgi expat expat-dev curl wget \ gcc g++ autoconf automake make git patch perl perl-dev perl-cgi expat expat-dev curl wget \
# Install backuppc runtime dependencies # Install backuppc runtime dependencies
supervisor rsync samba-client iputils openssh openssl rrdtool postfix lighttpd lighttpd-mod_auth gzip apache2-utils \ supervisor rsync samba-client iputils openssh openssl rrdtool msmtp lighttpd lighttpd-mod_auth gzip apache2-utils \
# Compile and install needed perl modules # Compile and install needed perl modules
&& cpan App::cpanminus \ && cpan App::cpanminus \
&& cpanm -n Archive::Zip XML::RSS File::Listing \ && cpanm -n Archive::Zip XML::RSS File::Listing \
@ -31,6 +31,10 @@ supervisor rsync samba-client iputils openssh openssl rrdtool postfix lighttpd l
&& git clone https://github.com/Parchive/par2cmdline.git /root/par2cmdline --branch $PAR2_VERSION \ && git clone https://github.com/Parchive/par2cmdline.git /root/par2cmdline --branch $PAR2_VERSION \
&& cd /root/par2cmdline && ./automake.sh && ./configure && make && make check && make install \ && cd /root/par2cmdline && ./automake.sh && ./configure && make && make check && make install \
# Configure MSMTP for mail delivery (initially sendmail is a sym link to busybox)
&& rm -f /usr/sbin/sendmail \
&& ln -s /usr/bin/msmtp /usr/sbin/sendmail \
# Get BackupPC, it will be installed at runtime to allow dynamic upgrade of existing config/pool # Get BackupPC, it will be installed at runtime to allow dynamic upgrade of existing config/pool
&& curl -o /root/BackupPC-$BACKUPPC_VERSION.tar.gz -L https://github.com/backuppc/backuppc/releases/download/$BACKUPPC_VERSION/BackupPC-$BACKUPPC_VERSION.tar.gz \ && curl -o /root/BackupPC-$BACKUPPC_VERSION.tar.gz -L https://github.com/backuppc/backuppc/releases/download/$BACKUPPC_VERSION/BackupPC-$BACKUPPC_VERSION.tar.gz \
# Prepare backuppc home # Prepare backuppc home

View File

@ -8,6 +8,7 @@
* [UI SSL encryption](#ui-ssl-encryption) * [UI SSL encryption](#ui-ssl-encryption)
* [Self-signed certificate](#self-signed-certificate) * [Self-signed certificate](#self-signed-certificate)
* [Advanced SSL use](#advanced-ssl-use) * [Advanced SSL use](#advanced-ssl-use)
* [SMTP configuration for notification delivery](#smtp-configuration-for-notification-delivery)
* [Upgrading](#upgrading) * [Upgrading](#upgrading)
* [Dockerising an existing BackupPC v3.x](#dockerising-an-existing-backuppc-v3x) * [Dockerising an existing BackupPC v3.x](#dockerising-an-existing-backuppc-v3x)
* [Shell access](#shell-access) * [Shell access](#shell-access)
@ -58,7 +59,7 @@ It is advised to mount these volumes on the host to persist your backups. Assumi
```bash ```bash
docker run \ docker run \
--name backuppc \ --name backuppc \
--public 80:8080 \ --publish 80:8080 \
--volume /var/docker-data/backuppc/etc:/etc/backuppc \ --volume /var/docker-data/backuppc/etc:/etc/backuppc \
--volume /var/docker-data/backuppc/home:/home/backuppc \ --volume /var/docker-data/backuppc/home:/home/backuppc \
--volume /var/docker-data/backuppc/data:/data/backuppc \ --volume /var/docker-data/backuppc/data:/data/backuppc \
@ -80,7 +81,7 @@ For example:
chown -R myUser:myGroup /var/docker-data/backuppc chown -R myUser:myGroup /var/docker-data/backuppc
docker run \ docker run \
--name backuppc \ --name backuppc \
--public 80:8080 \ --publish 80:8080 \
--volume /var/docker-data/backuppc/etc:/etc/backuppc \ --volume /var/docker-data/backuppc/etc:/etc/backuppc \
--volume /var/docker-data/backuppc/home:/home/backuppc \ --volume /var/docker-data/backuppc/home:/home/backuppc \
--volume /var/docker-data/backuppc/data:/data/backuppc \ --volume /var/docker-data/backuppc/data:/data/backuppc \
@ -100,7 +101,7 @@ Set the environment variable `USE_SSL (default: false)` to `true`, and the embed
```bash ```bash
docker run \ docker run \
--name backuppc \ --name backuppc \
--public 443:8080 --publish 443:8080 \
--env 'USE_SSL=true' --env 'USE_SSL=true'
``` ```
@ -112,6 +113,35 @@ Instead of providing a very advanced SSL configuration in this Docker, and reinv
You will be able to make routing based on DNS, use certificates signed by Let's Encrypt and so on. See [nginx-proxy](https://github.com/jwilder/nginx-proxy) + [letsencrypt-nginx-proxy-companion](https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion) or [traefik](https://hub.docker.com/_/traefik/) for more information. You will be able to make routing based on DNS, use certificates signed by Let's Encrypt and so on. See [nginx-proxy](https://github.com/jwilder/nginx-proxy) + [letsencrypt-nginx-proxy-companion](https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion) or [traefik](https://hub.docker.com/_/traefik/) for more information.
# SMTP configuration for notification delivery
BackupPC can send notifications by mail to inform users about backups state. This docker include the MSMTP utility, which basically rely all mails to a pre-existing SMTP server.
Two configuration approaches are available.
## Relay notifications to a local SMTP
If you are using BackupPC to backup your IT architecture, it is likely that you have alreay a SMTP server configured on your host or local network. Or you can instantiate a dockerised full-featured SMTP server (like [namshi/smtp](https://github.com/namshi/docker-smtp)) on the same network than the backuppc container.
In both cases, the SMTP server should be accessible to the backuppc container through YOUR_SMTP_FQDN on port 25. Set the environment variable `SMTP_HOST` (default: mail.example.org) to YOUR_SMTP_FQDN before creating the BackupPC container, and all mails emitted by BackupPC will be relayed on this SMTP server.
You should also set the _optional_ environment variable `SMTP_MAIL_DOMAIN (default empty)` to the domain you manage, in order to resolve automatically the right part of the email sender to this domain if it is not specified by BackupPC. Indeed by default, sender mail of BackupPC notifications is only 'backuppc', without right part: these emails are likely to be refused by most SMTP servers.
```bash
docker run \
--name backuppc \
--publish 80:8080 \
--env SMTP_HOST=smtp.my-domain.org \
--env SMTP_MAIL_DOMAIN=my-domain.org \
adferrand/backuppc:4.1.1
```
## Advanced SMTP configuration
In more complex scenarios, like sending notifications through a TLS-secured SMTP server with authentication (eg. Google SMTP), you can use any advanced configuration supported by MSMTP. To do so, mount or copy a user-wide SMTP configuration file `.msmtp` in the volume `/home/backuppc`. This configuration will be used for any email sended by BackupPC.
See [MSMTP documentation](http://msmtp.sourceforge.net/doc/msmtp.html), in particular its [configuration examples](http://msmtp.sourceforge.net/doc/msmtp.html#Examples), to see how to build the configuration which suits your needs.
# Upgrading # Upgrading
To update the BackupPC version of this container: To update the BackupPC version of this container:
@ -138,7 +168,7 @@ Then launch a container instance, mounting your existing BackupPC installation a
```bash ```bash
docker run \ docker run \
--name backuppc \ --name backuppc \
--public 80:8080 \ --publish 80:8080 \
--volume /etc/backuppc:/etc/backuppc \ --volume /etc/backuppc:/etc/backuppc \
--volume /home/backuppc:/home/backuppc \ --volume /home/backuppc:/home/backuppc \
--volume /var/lib/backuppc:/data/backuppc \ --volume /var/lib/backuppc:/data/backuppc \
@ -155,4 +185,4 @@ For debugging and maintenance purpose, you may need to start a shell in your run
docker exec -it backuppc /bin/sh docker exec -it backuppc /bin/sh
``` ```
You will have the standard tools of an Alpine distribution. You will obtain a shell with the standard tools of an Alpine distribution.

View File

@ -54,6 +54,14 @@ if [ -f /firstrun ]; then
fi fi
touch /var/log/lighttpd/error.log && chown -R backuppc:backuppc /var/log/lighttpd touch /var/log/lighttpd/error.log && chown -R backuppc:backuppc /var/log/lighttpd
# Configure standard mail delivery parameters (may be overriden by backuppc user-wide config)
echo "account default" > /etc/msmtprc
echo "host ${SMTP_HOST:-mail.example.org}" >> /etc/msmtprc
echo "auto_from on" >> /etc/msmtprc
if [ "${SMTP_MAIL_DOMAIN:-}" != "" ]; then
echo "maildomain ${SMTP_MAIL_DOMAIN}" >> /etc/msmtprc
fi
# Clean # Clean
rm -rf /root/BackupPC-$BACKUPPC_VERSION.tar.gz /root/BackupPC-$BACKUPPC_VERSION /firstrun rm -rf /root/BackupPC-$BACKUPPC_VERSION.tar.gz /root/BackupPC-$BACKUPPC_VERSION /firstrun
fi fi