# BGSAVE

> Start writing a snapshot of the data set to disk in the background.

URL: https://docs.hotkv.com/commands/bgsave/

```
BGSAVE [SCHEDULE]
```

- Group: Server
- Complexity: O(1) to start; the save itself is O(N) in the number of keys
- HotKV Cloud: all plans
- On-Premise: no license needed

`BGSAVE` starts writing a point-in-time snapshot of every database to the
snapshot file (`dbfilename` in `dir`) and replies right away. Clients keep
being served while the snapshot is written. Check progress with
`rdb_bgsave_in_progress` and the result with `rdb_last_bgsave_status` in
[INFO](https://docs.hotkv.com/commands/info/index.md) `persistence`, or wait for
[LASTSAVE](https://docs.hotkv.com/commands/lastsave/index.md) to change.

The server also starts background saves on its own according to the `save`
setting.

## Options

| Option | Effect |
| --- | --- |
| `SCHEDULE` | Accepted for compatibility. In Redis it delays the save while an AOF rewrite runs; in HotKV a rewrite does not stop a background save, so it starts at once either way. |

## Return value

| Case | Reply (RESP2 and RESP3) |
| --- | --- |
| Save started | Simple string `Background saving started` |
| A background save is already running | Error `ERR Background save already in progress` |
| Any other argument | Error `ERR syntax error` |

## Examples

```
127.0.0.1:6379> BGSAVE
Background saving started
127.0.0.1:6379> BGSAVE
(error) ERR Background save already in progress
```

In HotKV Cloud, the CLI tab of the panel does not run `BGSAVE`. Send it from
your own client connection.

## Compatibility

Same replies as Redis 7 and Valkey 8, except that `SCHEDULE` never delays the
save.

## See also

[SAVE](https://docs.hotkv.com/commands/save/index.md), [LASTSAVE](https://docs.hotkv.com/commands/lastsave/index.md),
[BGREWRITEAOF](https://docs.hotkv.com/commands/bgrewriteaof/index.md), [persistence](https://docs.hotkv.com/persistence/index.md)