Skip to content
Platform status
Servergilde
Guides · Backups

Metin2 server backup with mysqldump, test and restore

Dumping the databases with mysqldump, getting a copy off the box and practising the restore before you actually need it.

Updated November 26, 2026 · 10 min read

Commands are sh/bash. If you're root on FreeBSD you may still be in csh (the default up to FreeBSD 13), so type sh first. "Badly placed ()'s" or "Ambiguous output redirect" means you're still in csh.

What to back up

Everything that changes in game is in the database: accounts, chars, items, guilds, yang. On most files that's account, player and common, and those get dumped every day. To see what your cores actually use, look at conf.txt of the db core (SQL_ACCOUNT, SQL_PLAYER, SQL_COMMON) and the channel CONFIG (PLAYER_SQL, COMMON_SQL, LOG_SQL). Extra databases for a website, forum or item shop go in too.

log is usually bigger than all the others together and the game doesn't need it to run. Keep it anyway, it's what you dig through when hunting dupes (see detecting dupes) or when a player swears he lost something. It just gets its own schedule, once a week is enough.

Server files, quests and CONFIG aren't in the database at all. Tar them after every change and adjust the path to your files:

# tar -czf /backup/mt2/files-$(date +%F).tar.gz --exclude='*.core' --exclude='syslog*' --exclude='syserr*' /usr/game

MyISAM and locking

Lots of Metin2 files still run MyISAM, and MyISAM has no transactions. Dump without a lock and item gets read at a different moment than player. If two people trade in between, your restored backup has missing or duplicated items. Check what engines you have:

SELECT table_schema, engine, COUNT(*) FROM information_schema.tables WHERE table_schema IN ('account', 'player', 'common', 'log') GROUP BY table_schema, engine;

If everything is InnoDB, use --single-transaction and nothing gets locked. With MyISAM or a mix we go with --lock-all-tables, a global read lock on all databases for as long as the dump runs. Every write waits until it's done, so measure it once on your data:

# time mysqldump --lock-all-tables player > /dev/null

More than a few seconds and you want it in your quietest hour. That's also why log isn't in the script. If it's several GB, the global lock holds up the whole server until it's through. Dump it separately with --lock-tables and only log has to wait.

Then there's the db core. It keeps changed chars and items in memory and writes them in batches (PLAYER_CACHE_FLUSH_SECONDS and ITEM_CACHE_FLUSH_SECONDS in conf.txt on many files). So a live dump has whatever the db core wrote up to that point, which is fine for the daily one. Before a migration or a big update, shut everything down clean (channels, auth, db last) and dump after. The db core flushes its cache on exit, which is why you never kill -9 it.

The script

Don't dump as root or as the cores' user. Make one that can only read:

CREATE USER 'backup'@'localhost' IDENTIFIED BY 'LongRandomPassword'; GRANT SELECT, LOCK TABLES, SHOW VIEW, TRIGGER, EVENT ON account.* TO 'backup'@'localhost'; GRANT SELECT, LOCK TABLES, SHOW VIEW, TRIGGER, EVENT ON player.* TO 'backup'@'localhost'; GRANT SELECT, LOCK TABLES, SHOW VIEW, TRIGGER, EVENT ON common.* TO 'backup'@'localhost'; GRANT RELOAD ON *.* TO 'backup'@'localhost';

RELOAD is for the global lock. TRIGGER has to be in there because player often has triggers, and without it the dump aborts.

The password goes in a file only root can read, not in the script and not in the crontab. With -p it ends up in shell history and briefly in the process list, mysqldump even warns you about that.

# cat > /root/.backup.cnf <<'EOF' [client] user=backup password=LongRandomPassword EOF # chmod 600 /root/.backup.cnf

The script itself, /root/bin/mt2-backup.sh:

#!/bin/sh PATH=/usr/local/bin:/usr/bin:/bin DEST=/backup/mt2 DBS="account player common" LOCK=--lock-all-tables STAMP=$(date +%Y-%m-%d_%H%M) umask 077 mkdir -p "$DEST" failed=0 for db in $DBS; do file="$DEST/$STAMP-$db.sql.gz" mysqldump --defaults-extra-file=/root/.backup.cnf $LOCK \ --no-tablespaces --hex-blob "$db" | gzip > "$file.part" if gzip -dc "$file.part" | tail -n 1 | grep -q "Dump completed"; then mv "$file.part" "$file" echo "$(date '+%F %T') ok $file $(du -h "$file" | cut -f1)" else echo "$(date '+%F %T') ERROR: dump of $db is incomplete" >&2 failed=1 fi done find "$DEST" -maxdepth 1 -name '*.sql.gz*' -mtime +14 -delete exit $failed

PATH is set because cron runs with a tiny search path and on FreeBSD mysqldump lives in /usr/local/bin. --defaults-extra-file has to be the first option. --hex-blob writes binary columns as hex, and player keeps skills and the quickslot bar as binary.

The part we care about most is the grep for "Dump completed". mysqldump writes that line at the very end, and in a pipe the shell only sees whether gzip worked. If the dump dies halfway, the file keeps its .part suffix and the script exits with an error. All InnoDB? Set LOCK to --single-transaction. On newer MariaDB the tool is mariadb-dump, the old name usually still works.

Run it once by hand:

# chmod 700 /root/bin/mt2-backup.sh # /root/bin/mt2-backup.sh # ls -lh /backup/mt2

Then into root's crontab (crontab -e), every day at 4:30:

30 4 * * * /root/bin/mt2-backup.sh >> /var/log/mt2-backup.log 2>&1

cron uses the server clock, so check date first. % means something special in a crontab line, that's why the date stuff lives in the script. FreeBSD also has periodic, just don't use both or the backup runs twice.

14 days of retention covers a dead disk, not a dupe nobody notices for three weeks. So keep weekly and monthly copies too, these lines go above the find:

mkdir -p "$DEST/weekly" "$DEST/monthly" [ "$(date +%u)" = 7 ] && cp "$DEST/$STAMP"-*.sql.gz "$DEST/weekly/" [ "$(date +%d)" = 01 ] && cp "$DEST/$STAMP"-*.sql.gz "$DEST/monthly/" find "$DEST/weekly" -name '*.sql.gz' -mtime +56 -delete find "$DEST/monthly" -name '*.sql.gz' -mtime +365 -delete

That's 14 daily, 8 weekly and 12 monthly restore points, and with the encrypted copies from below roughly 48 times one backup. Check df -h, especially if the backup folder is on the same partition as the database. Fill that up and the whole server stops.

Getting a copy off the server

A backup that only exists on the game server is gone when the disk dies, the host suspends you or someone gets root. One copy has to be somewhere else. account has your players' passwords and email addresses, so it leaves the server encrypted or not at all.

With openssl you need a key file. Put a copy of the key in your password manager, without it every backup is useless:

# openssl rand -base64 48 > /root/.backup.key # chmod 600 /root/.backup.key

This goes into the script right before the retention part:

for f in "$DEST/$STAMP"-*.sql.gz; do openssl enc -aes-256-cbc -salt -pbkdf2 -iter 200000 \ -in "$f" -out "$f.enc" -pass file:/root/.backup.key || failed=1 rclone copy "$f.enc" offsite:my-bucket/mt2/ || failed=1 done

Decrypting:

# openssl enc -d -aes-256-cbc -pbkdf2 -iter 200000 -in FILE.sql.gz.enc -out FILE.sql.gz -pass file:/root/.backup.key

-pbkdf2 needs OpenSSL 1.1.1 or newer, on really old systems use gpg. gpg can also do it with a public key, and we like that setup: the server can encrypt but can't decrypt anything, so whoever takes over the box still can't read your old backups.

offsite is an rclone remote. Almost every host sells S3 compatible storage and rclone talks to all of them: install it (pkg install rclone or apt install rclone), run rclone config, add a remote of type s3 called offsite. If your provider can do it, give the server a write-only access key and let a lifecycle rule on their side expire old files, then nobody on the game server can delete your backups.

Got a second server or a machine at home? scp works too. We'd rather have the second machine pull the files with rsync over SSH, as a user that can read nothing but the backup folder. That way the game server has no access to the backup machine at all.

Testing the backup

Honestly the step almost everyone skips. You don't know a backup works until you've restored it. At least once a month, load one into a scratch database, at a quiet time because the import hits the disk. The dumps have no CREATE DATABASE or USE in them, so the data goes wherever you pipe it. As root:

# mysql -e "CREATE DATABASE test_player" # gzip -dc /backup/mt2/2026-11-12_0430-player.sql.gz | mysql test_player

No errors? Compare row counts per table against live:

for t in $(mysql -N -e "SHOW TABLES" test_player); do a=$(mysql -N -e "SELECT COUNT(*) FROM \`$t\`" test_player) b=$(mysql -N -e "SELECT COUNT(*) FROM \`$t\`" player) printf '%-30s %10s %10s\n' "$t" "$a" "$b" done

Small differences are normal, people kept playing after the backup. If item or player shows 0 rows in the copy, or a fraction of live, something's broken: aborted dump, missing privileges or the wrong file. A table that's missing completely wasn't in the backup. Look at a few chars you know, then drop the copy:

# mysql -e "SELECT name, level, last_play FROM test_player.player ORDER BY last_play DESC LIMIT 5" # mysql -e "DROP DATABASE test_player"

Same for account and common. Test again after every change to the script, after a database upgrade and after moving servers.

Restoring

Only with the cores stopped. At startup the db core reads which item IDs are taken and it keeps chars in memory. Restore under a running db core and its memory no longer matches the database, and the next flush writes right over what you just imported.

  1. Pick the restore point. Newest one after a dead disk, the last one before the problem after a dupe or a broken quest.
  2. Announce maintenance and stop channels, then auth, db last. Make sure nothing is left with pgrep -lx 'game|db' (use your binary names if they're different).
  3. Run the backup script once by hand anyway. Even a broken state can be useful later, for example to pull single chars out of it.
  4. Decrypt if the files come from the offsite copy.
  5. Import as root:
    # gzip -dc /backup/mt2/2026-11-12_0430-account.sql.gz | mysql account # gzip -dc /backup/mt2/2026-11-12_0430-player.sql.gz | mysql player # gzip -dc /backup/mt2/2026-11-12_0430-common.sql.gz | mysql common
    The dump drops and recreates every table it has. Tables that are in the database but not in the backup stay as they are.
  6. Count rows like in the test, check a few accounts and chars you know, and on MyISAM run mysqlcheck --check player.
  7. Start db, auth, then channels, and keep an eye on syserr while they come up. Reading syserr covers that part.

Always all three from the same point in time. Yesterday's player with today's account means items bought with shop credit since then are gone while the credit is already spent.

If it's just one char, don't roll back everybody. Restore into a scratch database and copy that char over by hand. It's manual work since char, items, quest states and affects are spread over several tables.

Server doesn't boot at all anymore? Get to the disk through your host's rescue system, mount the data partition and copy the database folder (/var/db/mysql on FreeBSD, /var/lib/mysql on Linux) plus your files to another machine. The database isn't running at that point, so a file copy is fine here. Restore on the same MySQL or MariaDB version and run mysqlcheck --check --all-databases afterwards.

Things that bite people

Copying the data folder while the database is running. You catch MyISAM files mid-write and InnoDB files without a matching redo log, and that copy often won't even start. File copies only with the database stopped, otherwise mysqldump.

Triggers remember who created them (DEFINER). Import as a different user and you get ERROR 1227 (42000) with "Access denied". If that user doesn't exist on the new server, the trigger fails later with ERROR 1449. Import as root, create the user, or strip the clause on import:

# gzip -dc player.sql.gz | sed -E 's/DEFINER=`[^`]+`@`[^`]+`//g' | mysql player

Navicat backups are their own format that only Navicat can restore, the schedule only runs while your PC is on, and it's very slow with big databases. mysqldump on the server and mysql in the shell is a lot faster.

And read the log now and then. A changed password or a full disk and the script fails for weeks without anyone noticing. If a backup is suddenly way smaller than yesterday's, something's off.

Backups with Servergilde

It starts free with the server check, which looks every day at whether your server has backups of its own and how old they are. From the Plus plan (7.99 euros per month, see pricing) the Servergilde agent takes over the daily backup of account, player and common, encrypted on your server with an optional copy on a second server in Germany, and if you allow it, it regularly restores one into a scratch database to check it. The details are on the backups page, and for the rest of the server there's how to secure a Metin2 server.

Frequently asked questions

Can I back up the database while the server is running?
Yes. With MyISAM tables use --lock-all-tables so item and player are read at the same moment, with pure InnoDB use --single-transaction. The dump then has whatever the db core has written so far. That's fine for the daily backup, but before a migration shut the cores down cleanly first.
How often should I back up my Metin2 server?
account, player and common every day, the big log database separately and less often, once a week is enough. Keep weekly and monthly copies as well, since a dupe can go unnoticed for weeks.
Can I just copy the MySQL data folder?
Only with the database stopped. While it runs you catch MyISAM files mid-write and InnoDB files without a matching redo log, and that copy often won't start. Otherwise use mysqldump.
How do I restore a Metin2 backup?
Stop the cores (channels, auth, db last), back up the current state once more, then import each database as root, for example gzip -dc 2026-11-12_0430-player.sql.gz | mysql player. Always restore account, player and common from the same point in time. Then count rows and start db, auth and the channels in that order.
Why do I get ERROR 1227 when importing a dump?
It shows up when triggers carry a DEFINER and you import as a different user. Import as root, create that user, or strip the DEFINER clause with sed while importing.

Have your backups checked

The free server check looks every day at whether your server has a recent backup.