# Backup and restore

| Goal | Command |
| --- | --- |
| Snapshot now | `openprogram backup create` |
| See what exists | `openprogram backup list` |
| See what a restore overwrites | `openprogram backup restore <name> --dry-run` |
| Restore | `openprogram backup restore <name>` (`-y` skips the confirmation) |
| Delete all but the newest N | `openprogram backup prune --keep 5` (default 5; below 1 is rejected. Nothing is ever pruned automatically) |

Archives: `~/.openprogram/backups/<profile>-<timestamp>.tar.gz`. Each command acts on the active profile only; under `--profile alpha`, `~/.openprogram-alpha/backups/`, and a restore cannot cross profiles.

## Scope

An allowlist, so a new cache directory cannot start bloating archives.

| Included | Holds |
| --- | --- |
| `memory/`, `projects/` | Memory, and projects with their chat history, run steps and memory |
| `session_aliases.json`, `run_index.jsonl`, `revisions.jsonl` | Chat names, which chat each run belongs to, Workflow versions |
| `config.json`, `cli-config.json` | Configuration |
| `agents/`, `agents.json` | Agent definitions |
| `programs_meta.json`, `functions_meta.json`, `program-sources.json` | Program and function metadata |
| `channels/`, `bindings.json` | Channel accounts and session bindings |
| `skills/`, `skills.json`, `plugins/`, `marketplaces.json` | Skills and plugins |
| `mcp_servers.json`, `models/`, `commands/` | MCP servers, model overrides, custom commands |
| `owner.json`, `worktrees.json`, `usage.db` | Ownership, worktrees, usage history |
| `programs/`, `workflow_archives/`, `recordings/` | Installed and your own programs with what applications keep (meetings among it), archived Workflows, recorded demonstrations |
| `scheduler/`, `always_on/`, `memory-spaces/` | Scheduled jobs, always-on agents, memory kept per agent |
| `project-file-history/`, `imports/` | Earlier document versions, which outside sessions were imported |
| `output-styles/`, `plugin-trust.json`, `plugins-enabled.json`, `AGENTS.md` | Output styles, plugin trust and enablement, instructions for every project |

**Left out, regenerated or not state**

- `cache/`, `tool_results/`, `browser-states/`, `chrome-profile/`, `trash/`, `shadow-git/`, `logs/`
- `*.log`, `*.lock`, `*.pid`, `*.port`, `*.sock`, recovery copies of state files, the Web token
- Credential-writer temporaries such as `.env.tmp` and `*.json.tmp`
- `profiles/`, the folder the old per-account sign-ins used; nothing reads it now
- `node_modules/` anywhere; symlinks, skipped rather than followed

## Credentials

| Data | Default | `--include-credentials` |
| --- | --- | --- |
| `auth/`, `mcp_tokens/`, `plugin-options/`, `web_push/`, profile AuthStore and `.env` files, Channel `channels/*/credentials.json` | Left out | Archived, plaintext |
| `config.json[api_keys]`; MCP env, header, bearer-token and OAuth client-secret fields | Removed, rest of file kept | Archived, plaintext |
| Web runtime token, pending Channel pairing codes, the Tailscale node key in `tailnet/` | Left out | Left out |

Store an opted-in archive like the credentials themselves. To move machines, logging in again is usually safer. `backup-manifest.json` lists only the categories actually included, redacted or excluded, plus never-backup rules under `credential_policy`, with no secret values.

## Restore

1. **Running-process check.** A live worker or Web server refuses the restore. Run `openprogram stop` first.
2. **Confirmation.** Lists what will be overwritten and waits for `y`.
3. **Safety snapshot.** Current state goes to `<profile>-pre-restore-<timestamp>.tar.gz`. If the archive has credentials, so does the snapshot, and the command says so.
4. **Replace** only the entries in the archive. Caches and logs stay. A secret field a mixed file omits or redacts keeps this machine's value.

**Archive and restore safety**

- POSIX applies mode `0600`. Windows source checkouts keep the state directory's inherited NTFS ACL.
- An archive is written to a unique temporary file, flushed and published atomically; POSIX also flushes the directory.
- The whole archive is validated before any of it is visible: containment, member type, JSON shape of every registered secret file. Symlink, hardlink and traversal members are refused, and a rejected archive changes nothing.
- Files publish through the owner-only atomic writer and each publish is journalled. A restore stopped by a crash or full disk is reversed at the start of the next restore.
- POSIX uses descriptor-relative traversal. Windows has no `dir_fd`, so it validates containment and rejects symlinks, junctions and other reparse points before each path operation.

[Configuration and data directory](https://fzkuji.github.io/OpenProgram/docs/server/configuration.html)
