Mastodon Backup Role¶
Creates on-host backups of the Mastodon database, media, and configuration with an optional archive fetch to the controller.
Features¶
Runs
pg_dumpin custom format with compression.Rsyncs the local media directory when
mastodon_storage_driver: local, excluding cache files by default.Captures
.env.production, systemd units, Traefik config, and nginx config.Generates a manifest for restore verification.
Usage¶
- hosts: mastodon
become: true
roles:
- role: local.ops_library.mastodon_backup
vars:
mastodon_backup_prefix: "manual"
mastodon_backup_fetch_local: true
Key Variables¶
Variable |
Default |
Description |
|---|---|---|
|
|
Remote backup root. |
|
|
Prefix for backup directory/archive names. |
|
|
Stop services during backup for consistency. |
|
|
Include local media directory. |
|
|
Rsync exclude patterns for local media backups. |
|
|
Fetch archive to the controller. |
|
|
Number of archives to retain. |
|
|
OS user for running |
Mastodon’s public/system/cache tree contains remote media cache data that can be refetched, and on busy
instances it can consume many filesystem entries. The default media backup excludes that cache subtree while
still preserving local account and media attachment files.
By default, pg_dump runs as the backup directory owner so it can write into the root-owned backup tree while
authenticating to PostgreSQL as mastodon_backup_postgres_user. If pg_hba.conf requires peer auth, set
mastodon_backup_postgres_become_user to postgres and ensure the backup directory is writable by that user.
See defaults/main.yml and roles/mastodon_shared/defaults/main.yml for the full reference.
Dependencies¶
local.ops_library.mastodon_shared
Testing¶
cd /path/to/ops-library
just test-role mastodon_backup
License¶
MIT