> For the complete documentation index, see [llms.txt](https://docs.fivemstats.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fivemstats.net/tgiann-fivem-stats-script/database-backups.md).

# Database Backups

Scheduled backups of your game database, how to download and restore them.

The media service backs up your game database (the one in `mysql_connection_string`) to `tgiann-media/backups/backup-<date>.sql.gz` inside the script folder. Each backup is one consistent snapshot taken while the server runs, players stay online. It restores exactly, float coordinates included.

{% hint style="info" %}
If your `server.cfg` limits who can read `mysql_connection_string` with `add_convar_permission`, add `add_convar_permission tgiann-fivem-stats-script read mysql_connection_string`. Without it backups are off.
{% endhint %}

## Turn them on

Backups are off until you turn them on on the [Backups](https://docs.fivemstats.net/panel/backups.md) page:

| Setting                   | Default    | Range                            |
| ------------------------- | ---------- | -------------------------------- |
| **Back up automatically** | Off        |                                  |
| **Every**                 | 4 hours    | 1 to 168 hours                   |
| **Keep**                  | 28 backups | 1 to 500, older ones are deleted |

The first automatic backup is checked 5 minutes after the server starts. **Back up now** on the same page takes one at once.

## Download

Click the download button next to a backup on the [Backups](https://docs.fivemstats.net/panel/backups.md) page. The file comes from the media port of your server, so that port must be open, see [Ports and Firewall](https://docs.fivemstats.net/tgiann-fivem-stats-script/ports-and-firewall.md). A download link works for 10 minutes and only once.

## Restore

Stop the server first and restore into an empty database (or one you are ready to overwrite).

Linux:

```bash
gunzip -c backup-2026-10-24_04-00-00.sql.gz | mysql -u root -p your_database
```

Windows: extract the `.sql` file with 7-Zip, then run it in HeidiSQL (**File** > **Run SQL file**) or:

```bat
mysql -u root -p your_database < backup-2026-10-24_04-00-00.sql
```

## What is not in a backup

The `tgiann-media` folder (statistics, logs, screenshots, videos). Copy that folder to keep them, see [Media Service](https://docs.fivemstats.net/tgiann-fivem-stats-script/media-service.md#where-files-are-stored).

Backups live inside the script folder too: keep `tgiann-media/` when you update the script, see [Updating from an Older Version](https://docs.fivemstats.net/tgiann-fivem-stats-script/updating-from-an-older-version.md).

On Linux the backups folder and files are readable by the server's user only.
