A Makefile-based backup system for our Docker databases and Gitea repositories: SQL dumps, git mirrors, retention cleanup and off-site rsync.
Environment variables in the Makefile:
| Variable | Meaning |
|---|---|
BACKUP_BASE |
Root of all backups (default /srv/backup) |
BACKUP_KEEP_DAYS |
Retention for DB dumps (default 7) |
DATABASE_BACKUP_BASE |
Where SQL dumps go |
REPOSITORY_BACKUP_BASE |
Where mirrored repos go |
GITEA_TOKEN |
API token for listing repositories |
RSYNC_* |
Off-site target: host, user, port, path |
export GITEA_TOKEN="your_token_here"
make backup # db dumps -> repos -> db_cleanup -> sync
make db_redmine db_wiki db_catalog # databases only
make repos # update the git mirrors
make db_cleanup # drop expired dumps
Each dump runs a script inside the service's container. Dumps are timestamped into /db_backup in the container, which must be mounted to the host's DATABASE_BACKUP_BASE.
| Service | Script | Needs in the container |
|---|---|---|
| Redmine (MariaDB) | database/mariadb_backup.sh |
MARIADB_USER, MARIADB_PASSWORD, MARIADB_DATABASE |
| Wiki (PostgreSQL) | database/pg_backup.sh |
POSTGRES_USER, POSTGRES_DB |
| Catalog (MySQL) | database/mysql_backup.sh |
MYSQL_ROOT_PASSWORD, MYSQL_DATABASE |
make repos lists every private and public repository from the Gitea API, then per repo: fetch --all --prune + pull when it exists locally, git clone when it does not.
make db_cleanup groups dumps by database prefix and deletes files older than BACKUP_KEEP_DAYS. A safety check keeps at least one backup per database, even when it is older than the retention window.
make sync rsyncs DATABASE_BACKUP_BASE and REPOSITORY_BACKUP_BASE to the remote server over SSH, with a custom port and a configurable remote rsync path.
.
├── Makefile # all backup tasks
├── DOCS.md
└── database/
├── mariadb_backup.sh
├── mysql_backup.sh
└── pg_backup.sh
With BACKUP_BASE=/srv/backup:
/srv/backup/
├── database/
│ ├── redmine-2026-03-07-12-00.sql
│ ├── wiki-2026-03-07-12-00.sql
│ └── catalog-2026-03-07-12-00.sql
└── repositories/
├── project-a/.git/
└── project-b/.git/
https://git.teletypegames.org/infra/backup-scripts