> 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/updating-from-an-older-version.md).

# Updating from an Older Version

How to update the script without losing your data, and what changed since older versions.

{% hint style="warning" %}
Take a database backup before you update.
{% endhint %}

## What is gone

| Old                                                                                                     | Now                                                                                                                             |
| ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| A separate API port (3737) and `tgiann_stats_http_port` / `tgiann_stats_http_host`                      | The panel connects through the game port. Remove the convars                                                                    |
| Statistics in `tgiann_stats_*` MySQL tables                                                             | Stored by the media service in `tgiann-media/stats.db`. Nothing is written to your game database any more                       |
| Retention, ignored items and AFK time in `config.lua`                                                   | Edited in the panel: [Settings > Game script](https://docs.fivemstats.net/panel/settings.md#game-script)                        |
| Node backups in the resource's `backups/` folder, `yarn` and `package.json`                             | Backups by the media service, set on the [Backups](https://docs.fivemstats.net/panel/backups.md) page. No `yarn` install needed |
| `tgiann-media/` in your server data folder and the `tgiann_media_storage` convar (earlier 3.x versions) | `tgiann-media/` inside the script folder, because FXServer's sandbox blocks folders outside resources. Remove the convar        |

## Steps

1. Stop the server.
2. Copy your data out of the old version:
   * `tgiann-fivem-stats-script/tgiann-media/`: statistics, logs, screenshots, videos and backups.
   * Earlier 3.x versions kept `tgiann-media/` in your server data folder (next to `resources`) instead. Copy that one.
   * Coming from 1.x or 2.x: the old script's `backups/` folder, if it has one.
3. Delete the old `tgiann-fivem-stats-script` folder and put the new one in its place.
4. Put the folders from step 2 into the new script folder: `tgiann-fivem-stats-script/tgiann-media/` and `tgiann-fivem-stats-script/backups/`.
5. Make sure `server.cfg` has `set sv_enableHttpServer true`, your `tgiann_stats_secret_key` and `add_unsafe_child_process_permission "tgiann-fivem-stats-script"`, see [Installation](https://docs.fivemstats.net/tgiann-fivem-stats-script/installation.md). Remove `tgiann_media_storage` if you set it.
6. Open the media port (and port 80 for automatic HTTPS), see [Ports and Firewall](https://docs.fivemstats.net/tgiann-fivem-stats-script/ports-and-firewall.md).
7. Start the server. Coming from 1.x, change the port in the panel to the game port: [Settings > Connection](https://docs.fivemstats.net/panel/settings.md#connection).

{% hint style="warning" %}
Starting the server before step 4 makes an empty `tgiann-media` folder with a new API key. Stop the server again and replace that folder with your copy.
{% endhint %}

## How old data comes over

* **Statistics**: the old `tgiann_stats_*` tables are imported once, in parts, on the first start. The console prints `stats: imported <n> rows from <table>` for each. If the server stops halfway, the import continues on the next start. The old tables are not deleted; drop them yourself once the panel shows your history.
* **Backups**: files in the script's `backups/` folder (step 4) are moved to `tgiann-media/backups/` and your old backup settings are kept.
* **Settings**: coming from 1.x or 2.x they start from the defaults. Check them once in [Settings > Game script](https://docs.fivemstats.net/panel/settings.md#game-script). From 3.x they are in `tgiann-media/settings.json` and come over with the folder.
