Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bab5bf5ade
|
@@ -198,5 +198,3 @@ REJECT_UNLISTED_RECIPIENT=
|
|||||||
# NOTE(3wc): Other values are not supported, as compose.yml does not contain
|
# NOTE(3wc): Other values are not supported, as compose.yml does not contain
|
||||||
# configuration for them. Pull requests welcome!
|
# configuration for them. Pull requests welcome!
|
||||||
DB_FLAVOR=sqlite
|
DB_FLAVOR=sqlite
|
||||||
|
|
||||||
ENABLE_BACKUPS=true
|
|
||||||
@@ -4,10 +4,10 @@ Coöp Cloud + [Mailu][Mailu] = 🥳
|
|||||||
|
|
||||||
<!-- metadata -->
|
<!-- metadata -->
|
||||||
* **Category**: Apps
|
* **Category**: Apps
|
||||||
* **Status**: 2, beta
|
* **Status**: 1, alpha
|
||||||
* **Image**: [`mailu/*`](https://hub.docker.com/r/mailu/), 4, upstream
|
* **Image**: [`mailu/*`](https://hub.docker.com/r/mailu/), 4, upstream
|
||||||
* **Healthcheck**: No
|
* **Healthcheck**: No
|
||||||
* **Backups**: Yes
|
* **Backups**: No
|
||||||
* **Email**: N/A
|
* **Email**: N/A
|
||||||
* **Tests**: No
|
* **Tests**: No
|
||||||
* **SSO**: No
|
* **SSO**: No
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
export CERTDUMPER_POST_VERSION=v1
|
export CERTDUMPER_POST_VERSION=v1
|
||||||
export POSTFIX_OVERRIDE_VERSION=v17
|
export POSTFIX_OVERRIDE_VERSION=v17
|
||||||
export SENDER_LOGIN_VERSIONS=v2
|
export SENDER_LOGIN_VERSIONS=v2
|
||||||
export BACKUP_SQLITE_VERSION=v1
|
export PG_BACKUP_VERSION=v1
|
||||||
export RESTORE_SQLITE_VERSION=v1
|
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
import os
|
|
||||||
import sqlite3
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
source_path = Path("/data/main.db")
|
|
||||||
backup_dir = Path("/data/backup")
|
|
||||||
temporary_path = backup_dir / "main.db.tmp"
|
|
||||||
backup_path = backup_dir / "main.db"
|
|
||||||
|
|
||||||
os.umask(0o077)
|
|
||||||
backup_dir.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
||||||
temporary_path.unlink(missing_ok=True)
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Read-only mode prevents silently creating an empty source database.
|
|
||||||
source = sqlite3.connect(
|
|
||||||
f"{source_path.as_uri()}?mode=ro",
|
|
||||||
uri=True,
|
|
||||||
timeout=60,
|
|
||||||
)
|
|
||||||
destination = sqlite3.connect(temporary_path)
|
|
||||||
try:
|
|
||||||
source.backup(destination, pages=256, sleep=0.1)
|
|
||||||
result = destination.execute("PRAGMA integrity_check").fetchall()
|
|
||||||
if result != [("ok",)]:
|
|
||||||
raise RuntimeError(f"SQLite integrity check failed: {result}")
|
|
||||||
finally:
|
|
||||||
destination.close()
|
|
||||||
source.close()
|
|
||||||
# Only publish a fully written, verified snapshot.
|
|
||||||
os.replace(temporary_path, backup_path)
|
|
||||||
print(f"SQLite backup ready: {backup_path}", flush=True)
|
|
||||||
except Exception:
|
|
||||||
temporary_path.unlink(missing_ok=True)
|
|
||||||
raise
|
|
||||||
+22
-27
@@ -55,7 +55,7 @@ x-environment:
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
image: ghcr.io/mailu/nginx:2024.06.67
|
image: ghcr.io/mailu/nginx:2024.06.66
|
||||||
logging:
|
logging:
|
||||||
driver: json-file
|
driver: json-file
|
||||||
networks:
|
networks:
|
||||||
@@ -96,18 +96,25 @@ services:
|
|||||||
- "traefik.http.routers.${STACK_NAME}.rule=Host(`${DOMAIN}`)"
|
- "traefik.http.routers.${STACK_NAME}.rule=Host(`${DOMAIN}`)"
|
||||||
- "traefik.http.routers.${STACK_NAME}.tls.certresolver=${LETS_ENCRYPT_ENV}"
|
- "traefik.http.routers.${STACK_NAME}.tls.certresolver=${LETS_ENCRYPT_ENV}"
|
||||||
- "traefik.http.routers.${STACK_NAME}.entrypoints=web-secure"
|
- "traefik.http.routers.${STACK_NAME}.entrypoints=web-secure"
|
||||||
- "coop-cloud.${STACK_NAME}.version=4.0.1+2024.06.67"
|
- "backupbot.backup=true"
|
||||||
- "backupbot.backup=${ENABLE_BACKUPS:-true}"
|
- "coop-cloud.${STACK_NAME}.version=3.2.1+2024.06.66"
|
||||||
- "backupbot.backup.volumes.traefik_letsencrypt=false"
|
|
||||||
- "backupbot.backup.volumes.mailu.path=backup"
|
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: redis:8.10.3-alpine
|
image: redis:8.10.2-alpine
|
||||||
volumes:
|
volumes:
|
||||||
- "redis:/data"
|
- "redis:/data"
|
||||||
|
deploy:
|
||||||
|
labels:
|
||||||
|
backupbot.backup.pre-hook: "/pg_backup.sh backup"
|
||||||
|
backupbot.backup.volumes.postgres.path: "backup.sql"
|
||||||
|
backupbot.backup.post-hook: "/pg_backup.sh restore"
|
||||||
|
configs:
|
||||||
|
- source: pg_backup
|
||||||
|
target: /pg_backup.sh
|
||||||
|
mode: 0555
|
||||||
|
|
||||||
admin:
|
admin:
|
||||||
image: ghcr.io/mailu/admin:2024.06.67
|
image: ghcr.io/mailu/admin:2024.06.66
|
||||||
environment: *default-env
|
environment: *default-env
|
||||||
healthcheck:
|
healthcheck:
|
||||||
disable: true
|
disable: true
|
||||||
@@ -118,20 +125,12 @@ services:
|
|||||||
- "mailu:/data"
|
- "mailu:/data"
|
||||||
networks:
|
networks:
|
||||||
- default
|
- default
|
||||||
configs:
|
|
||||||
- source: backup_sqlite
|
|
||||||
target: /usr/local/bin/backup_sqlite.py
|
|
||||||
mode: 0444
|
|
||||||
- source: restore_sqlite
|
|
||||||
target: /usr/local/bin/restore_sqlite.py
|
|
||||||
mode: 0444
|
|
||||||
deploy:
|
deploy:
|
||||||
labels:
|
labels:
|
||||||
backupbot.backup.pre-hook: "python3 /usr/local/bin/backup_sqlite.py"
|
- "backupbot.backup=true"
|
||||||
backupbot.restore.post-hook: "python3 /usr/local/bin/restore_sqlite.py"
|
|
||||||
|
|
||||||
imap:
|
imap:
|
||||||
image: ghcr.io/mailu/dovecot:2024.06.67
|
image: ghcr.io/mailu/dovecot:2024.06.66
|
||||||
environment: *default-env
|
environment: *default-env
|
||||||
secrets:
|
secrets:
|
||||||
- secret_key
|
- secret_key
|
||||||
@@ -145,7 +144,7 @@ services:
|
|||||||
- default
|
- default
|
||||||
|
|
||||||
smtp:
|
smtp:
|
||||||
image: ghcr.io/mailu/postfix:2024.06.67
|
image: ghcr.io/mailu/postfix:2024.06.66
|
||||||
environment: *default-env
|
environment: *default-env
|
||||||
secrets:
|
secrets:
|
||||||
- secret_key
|
- secret_key
|
||||||
@@ -157,7 +156,7 @@ services:
|
|||||||
- app
|
- app
|
||||||
|
|
||||||
antispam:
|
antispam:
|
||||||
image: ghcr.io/mailu/rspamd:2024.06.67
|
image: ghcr.io/mailu/rspamd:2024.06.66
|
||||||
environment: *default-env
|
environment: *default-env
|
||||||
secrets:
|
secrets:
|
||||||
- secret_key
|
- secret_key
|
||||||
@@ -168,7 +167,7 @@ services:
|
|||||||
disable: true
|
disable: true
|
||||||
|
|
||||||
webmail:
|
webmail:
|
||||||
image: ghcr.io/mailu/webmail:2024.06.67
|
image: ghcr.io/mailu/webmail:2024.06.66
|
||||||
# entrypoint: "tail -f /dev/null"
|
# entrypoint: "tail -f /dev/null"
|
||||||
environment: *default-env
|
environment: *default-env
|
||||||
networks:
|
networks:
|
||||||
@@ -235,13 +234,9 @@ configs:
|
|||||||
certdumper_post:
|
certdumper_post:
|
||||||
name: ${STACK_NAME}_certdumper_post_${CERTDUMPER_POST_VERSION}
|
name: ${STACK_NAME}_certdumper_post_${CERTDUMPER_POST_VERSION}
|
||||||
file: certdumper_post.sh
|
file: certdumper_post.sh
|
||||||
backup_sqlite:
|
pg_backup:
|
||||||
name: ${STACK_NAME}_backup_sqlite_${BACKUP_SQLITE_VERSION}
|
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
|
||||||
file: backup_sqlite.py
|
file: pg_backup.sh
|
||||||
restore_sqlite:
|
|
||||||
name: ${STACK_NAME}_restore_sqlite_${RESTORE_SQLITE_VERSION}
|
|
||||||
file: restore_sqlite.py
|
|
||||||
|
|
||||||
|
|
||||||
secrets:
|
secrets:
|
||||||
secret_key:
|
secret_key:
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
BACKUP_FILE='/var/lib/postgresql/data/backup.sql'
|
||||||
|
|
||||||
|
# TODO: this recipe doesn't have a db_password secret.
|
||||||
|
function backup {
|
||||||
|
export PGPASSWORD=$(cat /run/secrets/db_password)
|
||||||
|
pg_dump -U ${POSTGRES_USER} ${POSTGRES_DB} > $BACKUP_FILE
|
||||||
|
}
|
||||||
|
|
||||||
|
function restore {
|
||||||
|
cd /var/lib/postgresql/data/
|
||||||
|
restore_config(){
|
||||||
|
# Restore allowed connections
|
||||||
|
cat pg_hba.conf.bak > pg_hba.conf
|
||||||
|
su postgres -c 'pg_ctl reload'
|
||||||
|
}
|
||||||
|
# Don't allow any other connections than local
|
||||||
|
cp pg_hba.conf pg_hba.conf.bak
|
||||||
|
echo "local all all trust" > pg_hba.conf
|
||||||
|
su postgres -c 'pg_ctl reload'
|
||||||
|
trap restore_config EXIT INT TERM
|
||||||
|
|
||||||
|
# Recreate Database
|
||||||
|
psql -U ${POSTGRES_USER} -d postgres -c "DROP DATABASE ${POSTGRES_DB} WITH (FORCE);"
|
||||||
|
createdb -U ${POSTGRES_USER} ${POSTGRES_DB}
|
||||||
|
psql -U ${POSTGRES_USER} -d ${POSTGRES_DB} -1 -f $BACKUP_FILE
|
||||||
|
|
||||||
|
trap - EXIT INT TERM
|
||||||
|
restore_config
|
||||||
|
}
|
||||||
|
|
||||||
|
$@
|
||||||
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""Restore Mailu's SQLite snapshot without replacing the live database inode."""
|
|
||||||
|
|
||||||
import sqlite3
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
backup_path = Path("/data/backup/main.db")
|
|
||||||
live_path = Path("/data/main.db")
|
|
||||||
|
|
||||||
# The source and destination must already exist. A missing snapshot or live
|
|
||||||
# database is a restore failure, not a reason to create an empty database.
|
|
||||||
with sqlite3.connect(
|
|
||||||
f"{backup_path.as_uri()}?mode=ro", uri=True, timeout=60
|
|
||||||
) as source:
|
|
||||||
if source.execute("PRAGMA integrity_check").fetchall() != [("ok",)]:
|
|
||||||
raise RuntimeError(f"Invalid SQLite snapshot: {backup_path}")
|
|
||||||
with sqlite3.connect(
|
|
||||||
f"{live_path.as_uri()}?mode=rw", uri=True, timeout=60
|
|
||||||
) as destination:
|
|
||||||
source.backup(destination, pages=256, sleep=0.1)
|
|
||||||
|
|
||||||
print(f"SQLite restore complete: {live_path}", flush=True)
|
|
||||||
Reference in New Issue
Block a user