Skip to Content
DocumentationGuidesAuto-backup your apps with cron

Auto backup your apps

Built-in cron scheduling for app backups is not included in Companion Hub yet. Today you trigger a backup with Backup now on the app’s page, Hub takes an automatic snapshot before an app update, and an agent or script can trigger one through the Hub MCP hub_backup_app tool.

Companion Hub creates per-app .tar.gz archives containing your app’s data, installed manifest files, and user-config overrides. You can automate retention limits in state/settings.json, trigger backups from cron through cihub app update-all or the Hub MCP server, and sync <ROOT_FOLDER_HOST>/backups/ to offsite storage. See Backup and restore for how per-app backups work.

Where a backup goes

Each backup archives a single app while its containers are stopped and writes the resulting tarball under your Hub data root (ROOT_FOLDER_HOST, shown by cihub doctor):

  • Archive path: <ROOT_FOLDER_HOST>/backups/<app-store>/<app-name>/<app>:<store>-<timestamp>.tar.gz
  • Archive contents:
    • app-data/ from <ROOT_FOLDER_HOST>/app-data/<app-store>/<app-name>/
    • app/ from <ROOT_FOLDER_HOST>/apps/<app-store>/<app-name>/ (generated docker-compose.yml and config.json)
    • user-config/ from <ROOT_FOLDER_HOST>/user-config/<app-store>/<app-name>/ (your custom docker-compose.yml and app.env overrides)

What you can automate today

1. Copy backups offsite with cron and rsync

Hub writes backups to <ROOT_FOLDER_HOST>/backups/ on the same disk as your live data. Syncing that directory to another disk or machine on a schedule protects against drive failure:

# Run `crontab -e` and sync backups every night at 03:30 30 3 * * * rsync -a "$HOME/.local/share/companion-hub/backups/" backup-host:/srv/hub-backups/

Backup filenames contain a colon because they start with the app’s URN (<app>:<store>-<timestamp>.tar.gz). Ensure the destination filesystem accepts colons in filenames; Linux ext4, XFS, Btrfs, ZFS, and macOS APFS allow colons, whereas exFAT, FAT32, and NTFS reject them unless you map characters during transfer.

2. Trigger backups from a script or cron

The cihub app CLI manages containers directly (list, status, logs, inspect, start, stop, restart, delete) and does not include a standalone cihub app backup subcommand. Instead, use one of two supported automation paths:

  • Pre-update backups via cihub app update-all: Running cihub app update-all on the Hub host asks the running Hub to update every app with a newer store version, taking a full backup of each app before updating it.
  • Scheduled backups via Hub MCP (hub_backup_app): Mint an API key with write capability (cihub api-key create --name cron-backup --capability write) and call the hub_backup_app tool on Hub’s MCP endpoint (http://localhost:5002/api/mcp) with the app’s URN (for example, nextcloud:ci-marketplace). You can also invoke hub_backup_app interactively from the tool catalog in Settings → MCP. See Hub MCP.

3. Cap backup retention

To limit how many archives Hub keeps on disk:

  • Dashboard: On the Settings tab, enable Advanced settings and set Maximum backups to keep (0 to 100). When Advanced Mode is enabled on an app, the app’s own settings can override this limit.
  • Configuration files: Set "maxBackups" in <ROOT_FOLDER_HOST>/state/settings.json or MAX_BACKUPS in your Hub env file (.env.dev on Linux and macOS, .env on Windows). See Environment variables.

Hub also runs a weekly sweep that deletes the oldest backups beyond the global limit. When the global limit is 0 (the default), the weekly sweep keeps only the newest five backups of each app and ignores per-app limits. If you need to keep archives longer, sync them to external storage.

Do not run tar directly over a running app’s app-data/ directory. Hub stops the app’s containers before archiving so database files remain consistent and preserves container-owned UIDs/GIDs through a privileged helper when needed. Archiving a live database directory directly can produce a corrupt backup that fails to restore.

Last updated on