> ## Documentation Index
> Fetch the complete documentation index at: https://cache-pot.thatdevguy.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Cache-Pot persistence commands: SAVE, BGSAVE, BGREWRITEAOF

> Use SAVE, BGSAVE, and BGREWRITEAOF to manually trigger point-in-time snapshot writes and compact the append-only file in Cache-Pot.

Cache-Pot's persistence commands let you manually trigger a snapshot save or compact the AOF at any time — useful before a planned restart, after a bulk import, or as part of a maintenance script. Cache-Pot supports two persistence mechanisms: point-in-time snapshots (enabled with `--snapshot-path`) and an append-only file (enabled with `--aof-path`). Both can be active simultaneously.

***

### SAVE

Writes a full snapshot of the current keyspace to disk synchronously. The server serializes every key, hash, list, set, sorted set, and vector collection to the configured snapshot file before returning `OK`.

**Syntax:** `SAVE`

```redis theme={null}
SAVE   # OK
```

**Returns:** `OK` when the snapshot has been written successfully. Returns an error if no snapshot path is configured.

<Note>
  `SAVE` writes to the path set by `--snapshot-path` (default filename: `cache-pot.snapshot`). The server does not fork — it holds an in-process read lock across each keyspace shard while writing. Latency-sensitive workloads should schedule `SAVE` during low-traffic windows.
</Note>

<Warning>
  If Cache-Pot is started without `--snapshot-path`, `SAVE` returns `ERR persistence is disabled (no snapshot path configured)`.
</Warning>

***

### BGSAVE

Triggers a snapshot write using the same synchronous path as `SAVE`. The `BG` prefix is retained for Redis client compatibility — Cache-Pot does not fork a background process.

**Syntax:** `BGSAVE`

```redis theme={null}
BGSAVE   # OK
```

**Returns:** `OK` on success; the same error as `SAVE` if no snapshot path is configured.

<Note>
  Unlike Redis, Cache-Pot does not fork a child process for `BGSAVE`. The write is synchronous. The command name is kept so that backup scripts and monitoring tools designed for Redis work without changes.
</Note>

***

### BGREWRITEAOF

Compacts the append-only file by rewriting it to contain only the minimum set of commands needed to reconstruct the current keyspace state. This eliminates superseded writes and reduces the AOF file size.

**Syntax:** `BGREWRITEAOF`

```redis theme={null}
BGREWRITEAOF   # OK
```

**Returns:** `OK` when the rewrite completes. Returns an error if AOF is not enabled.

<Note>
  `BGREWRITEAOF` only has an effect when Cache-Pot is started with `--aof-path`. Without it, the command returns `ERR AOF is disabled (no --aof-path configured)`.
</Note>

<Tip>
  Run `BGREWRITEAOF` after large batch imports or bulk deletes. A heavily fragmented AOF can be orders of magnitude larger than necessary; rewriting it speeds up future replays and reduces disk I/O during startup.
</Tip>
