Operations Backup and Restore - osama1998H/Moca GitHub Wiki
Per-tenant PostgreSQL backup/restore, gzip compression, optional encrypted backup files, and scheduled backups.
Moca provides per-site backup and restore using pg_dump/psql. Backups can be gzip-compressed and, when requested, encrypted before they are written to disk.
moca backup create # Backup current site
moca backup create --site mysite # Backup specific site
moca backup create --encrypt # Create an encrypted backup (.enc)
moca backup list # List available backups
moca backup restore <file> # Restore from backup
moca backup verify <file> # Verify backup integrity
moca backup schedule --cron "0 2 * * *"Backups are stored in sites/{site}/backups/ with timestamped filenames:
sites/mysite/backups/
├── 20250408_120000_mysite.sql.gz
├── 20250407_120000_mysite.sql.gz.enc
└── ...
- All tables in the site's PostgreSQL schema
- Document data, MetaType definitions, permissions, settings
- Optional gzip compression
- Optional backup-file encryption
Use moca backup create --encrypt to wrap the backup file in an encrypted .enc envelope. The CLI expects a 64-character hex key and resolves it in this order:
--encryption-key-
backup.encryption_keyinmoca.yaml MOCA_ENCRYPTION_KEY
Examples:
moca backup create --site mysite --encrypt
moca backup create --site mysite --encrypt --encryption-key 0123...cdef
moca backup restore sites/mysite/backups/20250407_120000_mysite.sql.gz.encImplementation details that matter operationally:
- encrypted backups add a trailing
.encextension - restore auto-detects encrypted backups from the
.encsuffix - the decrypted payload is then decompressed normally if the inner file ends in
.gz - a wrong key fails restore before
psqlis invoked
When MOCA_ENCRYPTION_KEY is set for the server process, Password fields are encrypted at rest and transparently decrypted on document reads. This is separate from backup-file encryption: field encryption protects database values, while moca backup create --encrypt protects exported backup artifacts.
moca backup verify validates file existence, checksums, and gzip / SQL structure for plain .sql and .sql.gz backups. Encrypted .enc files are restored directly and their integrity is enforced during decryption, but the current verifier does not decrypt .enc backups as part of verify.
Configure automatic backups via moca backup schedule or cron.