How to back up a FiveM server: database, resources and txData

Back up your FiveM server: mysqldump or HeidiSQL for the database, resources, server.cfg and txData, scheduled backups, off-server copies and how to restore.

A disk dies, a bad script drops a table, a host closes your account, or you delete the wrong folder. If your only copy of the server is on the server, you start again from zero and your players lose their characters. This guide covers what to back up, how to automate it, and how to restore.

What to back up

What Why Where
Database Characters, money, vehicles, inventories, everything players own MariaDB or MySQL
server.cfg Your server settings and the start order server data folder
resources folder Your scripts and their config files server data folder
txData txAdmin settings, admin accounts, ban history and the action log the txData folder

The FiveM server binaries (artifacts) do not need a backup. You can download them again, see updating server artifacts.

Warning: server.cfg can hold your license key, database password and Discord tokens. Keep backups private and never post them in a public place.

Back up the database

With mysqldump

mysqldump ships with MariaDB and MySQL. Replace the user and database name with yours:

bash
mysqldump -u root -p --single-transaction --routines --databases es_extended > backup.sql
  • --single-transaction takes a consistent copy of InnoDB tables without locking the server.
  • --routines includes stored procedures.
  • --databases adds the CREATE DATABASE statement, so a restore is simpler.

Put the date in the file name, so copies do not overwrite each other:

bash
mysqldump -u root -p --single-transaction --routines --databases es_extended > "backup_$(date +%F).sql"

To run it without a password prompt, store the credentials in a protected option file (such as ~/.my.cnf on Linux) instead of typing them in the command.

With HeidiSQL

If you prefer a graphical tool:

  1. Connect to the server in HeidiSQL.
  2. Right-click the database and choose Export database as SQL.
  3. Select all tables, choose Create for the structure and Insert for the data, and pick a target file.
  4. Click Export.

Do this by hand before risky changes. For regular backups, automate it.

Back up files

Compress the folders you want to keep:

bash
tar -czf server_files_$(date +%F).tar.gz server.cfg resources txData

On Windows, PowerShell can do the same:

powershell
Compress-Archive -Path server.cfg, resources, txData -DestinationPath "server_files_$(Get-Date -Format yyyy-MM-dd).zip"

Run it from the folder that holds those items, or use full paths. Skip cache folders if your backups become huge; they are rebuilt when the server runs.

Schedule it

Linux: cron

Open the crontab with crontab -e and add a line. This runs the dump every day at 04:00:

cron
0 4 * * * mysqldump --single-transaction --routines --databases es_extended > /backups/db_$(date +\%F).sql

Inside crontab, % must be escaped as \%. The user running it needs access to the database through an option file, as described above.

Windows: Task Scheduler

Save your backup commands in a backup.ps1 script, then create a daily task:

powershell
schtasks /Create /SC DAILY /ST 04:00 /TN "FiveM backup" /TR "powershell -ExecutionPolicy Bypass -File C:\fivem\backup.ps1"

Or use the Task Scheduler app: create a basic task, set a daily trigger, and choose the script as the action.

Pick a time when few players are online, such as just before your scheduled restart.

Delete old backups

Backups pile up. Keep, for example, the last 7 daily copies and a few weekly ones. A small cleanup in the script is enough:

bash
find /backups -name "db_*.sql" -mtime +14 -delete

Keep backups off the server

The rule is simple: a backup that lives on the same machine is not a real backup. Copy it somewhere else after each run:

  • another server or home machine, with scp or rsync over SSH,
  • a cloud storage service, with a tool such as rclone,
  • a different disk that is not part of the same machine, as a minimum.

Test that the copy arrives. Check the destination now and then.

Restore a backup

A backup you have never restored is a hope, not a backup. Try a restore on a test database now.

  1. Stop the FiveM server from txAdmin, so nothing writes during the restore.
  2. Restore the database:
bash
mysql -u root -p < backup.sql

Because the dump used --databases, it recreates the database itself. If you exported with HeidiSQL, choose Run SQL file in the tool and select the file.

  1. Put server.cfg and the resources folder back, and the txData folder if txAdmin was lost.
  2. Start the server and watch the console for database errors. See oxmysql connection errors if the connection fails.

Restoring overwrites current data in those tables, so do it on purpose and keep a copy of the current state first.

Before every change

Before updating a framework, adding a script that edits tables, or running an SQL file from a download, take a quick manual dump. It takes seconds and saves a lot of trouble.

Checklist

Symptom Fix
No backup at all Run mysqldump today, then schedule it
Dump asks for a password in a scheduled job Use an option file with the credentials
Backups only on the server Copy them to another machine or storage
Disk fills up Delete backups older than your retention period
Lost txAdmin settings or admins Restore the txData folder
Restore fails on import Check the SQL file is complete and the database user has the rights
Unsure the backup works Restore it to a test database and check the tables

Quick answers

What is the most important thing to back up?

The database. Characters, money, vehicles and inventories all live there, and you cannot rebuild them. Resources and config can be re-downloaded or re-created, but player data cannot.

How often should I back up?

Back up the database at least once a day, and before every update or big script change. A busy server can run it every few hours.

Is a backup on the same machine enough?

No. A disk failure, a deleted server or a ransomware attack takes the backup with it. Copy backups to another machine or storage service.

Scripts that skip this problem

Tebex TemplateA code-free premium theme for your Tebex store, edited entirely from the Tebex panel.View script β†’Item Creator V2Create usable items with animations, props, effects and more β€” without writing code.View script β†’Shop CreatorBuild a shop in under a minute β€” owners, employees, vaults and robberies included.View script β†’

Keep reading