BSMBasil Saji Mathew

Guide

How to Automate MySQL Backups for a FiveM Server (ESX, QBCore, Qbox)

Your FiveM database holds everything players care about: characters, money, vehicles, houses and inventories. One bad script update, a corrupted table or a hacked panel can wipe it. Automatic, tested backups are the cheapest insurance a server owner can buy. This guide covers a simple setup that works for ESX, QBCore, Qbox and standalone servers.

What to back up

  • The MySQL or MariaDB database used by oxmysql or mysql-async. This is the critical one.
  • Your resources and configuration (the resources folder, server.cfg, any custom framework configs).
  • Uploaded assets such as custom maps or vehicle streams, if you cannot re-download them.

Step 1: Dump the database consistently

Use mysqldump with --single-transaction so InnoDB tables are dumped consistently without locking the server while players are online. Keep credentials out of the command line by putting them in ~/.my.cnf and setting its permissions to 600.

#!/usr/bin/env bash
set -euo pipefail
DB="fivem"
DEST="/var/backups/fivem"
STAMP=$(date +%F_%H%M)
mkdir -p "$DEST"
mysqldump --single-transaction --routines --triggers "$DB" | gzip > "$DEST/$DB-$STAMP.sql.gz"
# keep 14 days of backups
find "$DEST" -name "$DB-*.sql.gz" -mtime +14 -delete

Step 2: Schedule it

On Linux, add a cron entry. This runs every six hours:

0 */6 * * * /opt/backup/fivem-backup.sh

On Windows, create a Task Scheduler task that runs the script on a repeating trigger. Pick a frequency based on how much play you can afford to lose: a busy roleplay server should back up at least every few hours.

Step 3: Copy backups off the machine

A backup stored on the same disk as the database is not a backup. Copy it to another server over SFTP, or to object storage, and encrypt it before it leaves the machine. The Automatic SFTP Backup System I wrote does multi-server SFTP sync with AES-256 encryption, compression, database dumps and retention cleanup.

Step 4: Get a Discord alert

A backup that fails silently is the most dangerous kind. Post the result to a Discord channel with a webhook:

curl -H "Content-Type: application/json" \
  -d '{"content":"FiveM DB backup finished"}' "$DISCORD_WEBHOOK_URL"

Send a different message on failure so you can spot problems at a glance. My FiveM Database Backup tool does MySQL backups for ESX, QBCore, Qbox and standalone servers with gzip compression, retention cleanup and Discord alerts built in.

Step 5: Test your restore

Once a month, restore a backup into a test database and start a test server against it. This is the only way to know your backups work.

gunzip < fivem-2026-11-27_0600.sql.gz | mysql fivem_restore_test

Frequently asked questions

How often should I back up a FiveM database?

For an active server, every 4 to 6 hours is a sensible default. Keep daily copies for two weeks and weekly copies for longer.

Will mysqldump lag my server?

With --single-transaction it does not lock InnoDB tables, but it still uses disk and CPU. Run it off-peak if your database is large.