Files
seafile-backup/README.md
T
trex Bot dce11df819 Rewrite as an online restic backup
The 2023 prototype could not work against the current stack and, where it
did run, reported success while doing nothing: it dumped from a stale IP
(192.168.4.11) that is not even the Seafile database, joined a network the
DB is not on, used a mistyped seahub.sh path, and discarded every exit code.

Replace it with a single orchestrator that:

* never stops Seafile - the DB dump uses --single-transaction and the block
  store is content-addressed and immutable, so restic can read it live;
* reads the DB credentials from the Seafile conf/.env instead of duplicating
  them in the stack .env;
* dumps with --quick --routines --events --triggers --add-drop-table (the old
  --skip-opt produced a dump with no DROP TABLE, i.e. unrestorable over an
  existing database) and passes the password via MYSQL_PWD;
* puts the dump inside the restic snapshot, so a restore needs one source;
* drops rclone entirely - it cannot write to the RustFS buckets (403 on every
  bucket) and `sync` is the wrong semantics for a backup;
* checks every step, exits non-zero on failure, pings the Kuma push monitor
  with /start, /fail or the result, and sends a failure notification;
* takes an exclusive lock, verifies the dump trailer and the snapshot, and
  only then prunes old dump directories;
* keeps a second restic repository on a different physical disk;
* runs as a non-root image with a read-only rootfs and no capabilities.

Also: replace the dead Drone pipeline with a Gitea Actions build, drop the
unused python-dotenv/requests dependencies, and fix the README.
2026-11-24 14:39:11 -06:00

81 lines
3.6 KiB
Markdown

# seafile-backup
Online backup of a Seafile CE stack (Seafile 12+) to [restic](https://restic.net/).
Seafile keeps running for the whole backup:
* the database dump uses `--single-transaction`, so it is a consistent InnoDB
snapshot taken while seahub is serving;
* the block store (`seafile-data/storage`) is content-addressed and immutable
once written, so restic can read it while Seafile writes new blocks.
A cold mode (`COLD_BACKUP=true`) stops seahub/seafile around the run for
pre-upgrade snapshots. It is off by default and needs `/var/run/docker.sock`.
## What a run does
1. Takes an exclusive lock (a second run exits immediately).
2. Pings the Uptime Kuma push monitor with `/start`.
3. Dumps `ccnet_db`, `seafile_db` and `seahub_db` into one consistent
`--databases` dump under `/config/db/<timestamp>/`, reading the credentials
from the Seafile `conf/.env`.
4. Runs `restic backup` over the Seafile tree **and** that dump directory in a
single snapshot, tagged `seafile`, host `cygnus`.
5. Repeats the backup into `LOCAL_RESTIC_REPOSITORY` when it is set.
6. Applies the retention policy, prunes weekly and runs a `--read-data-subset`
check weekly.
7. Deletes dump directories older than `DB_DUMP_KEEP`.
8. Pings Kuma with the result and sends an Apprise notification.
Any failure exits non-zero, pings `/fail` and sends a failure notification.
## Environment
| Variable | Default | Meaning |
|---|---|---|
| `SEAFILE_ROOT` | `/shared/seafile` | Seafile data root inside the container |
| `SEAFILE_CONF_ENV` | `/shared/seafile/conf/.env` | source of the DB credentials |
| `DB_HOST` / `DB_USER` / `DB_PASSWORD` | from `conf/.env` | override the DB target |
| `DB_SSL` | `false` | pass TLS to `mariadb-dump` (the bundled server has none) |
| `DATABASES` | `ccnet_db,seafile_db,seahub_db` | databases to dump |
| `DB_DUMP_DIR` | `/config/db` | where dumps are written |
| `DB_DUMP_KEEP` | `3` | dump directories to keep |
| `LOG_PATH` | `/config/seafile-backup.log` | log file (rotated at 10 MB) |
| `RESTIC_REPOSITORY` | *required* | primary restic repository |
| `RESTIC_PASSWORD` | *required* | primary repository password |
| `LOCAL_RESTIC_REPOSITORY` | unset | optional second (local) repository |
| `LOCAL_RESTIC_PASSWORD` | `RESTIC_PASSWORD` | password for the local repository |
| `RESTIC_CACHE_DIR` | `/config/restic-cache` | restic cache root |
| `RESTIC_HOST` / `RESTIC_TAG` | `cygnus` / `seafile` | snapshot labels |
| `KEEP_DAILY` / `KEEP_WEEKLY` / `KEEP_MONTHLY` / `KEEP_YEARLY` | `7` / `4` / `12` / `3` | retention |
| `PRUNE_WEEKDAY` | `0` (Monday) | weekday to run `restic prune` |
| `CHECK_WEEKDAY` | `6` (Sunday) | weekday to run `restic check` |
| `CHECK_READ_DATA_SUBSET` | `5%` | how much data `restic check` re-reads |
| `PRUNE_MAX_UNUSED` | `5%` | `restic prune --max-unused` |
| `KUMA_PUSH_URL` | unset | Uptime Kuma push URL |
| `APPRISE_URL` / `APPRISE_URLS` | unset | Apprise endpoint and targets |
| `COLD_BACKUP` | `false` | stop Seafile around the run |
| `SEAFILE_CONTAINER` | `seafile` | container to stop in cold mode |
| `FAIL_ON_PARTIAL` | `false` | treat restic exit 3 as a failure |
| `CRON` | `0 3 * * *` | supercronic schedule |
`AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY` are read by restic itself for the
`s3:` backend.
## Restore
```sh
restic restore latest --target /restore
# then, against an empty MariaDB 10.11:
mariadb -h <host> -u root -p < /restore/config/db/<stamp>/seafile-databases.sql
```
The dump is written with `--add-drop-table`, so it can also be replayed over an
existing database.
## Build
```sh
docker build -t git.jonb.io/jblu/seafile-backup:latest .
```