Restore MariaDB from a mariabackup Backup
Restore MariaDB from a mariabackup backup on a Linux VPS: stop the server, prepare the backup files, copy them back into the data directory, fix ownership and start MariaDB again.
- Intermediate
- Linux VPS
- 6 min read
To restore MariaDB from a mariabackup backup you prepare the backup files, move the current data directory aside, copy the prepared files back with mariabackup --copy-back, fix ownership and start the server. This guide walks through the whole procedure on a Linux VPS, including incremental backups and the errors you are most likely to hit.
A mariabackup restore is a full-instance restore. It replaces every database on the server with the state captured in the backup. If you only need one database back, use a logical dump instead — see restore a MySQL database from a mysqldump file.
Before you start
You need:
- Root or sudo access to the VPS, and a working SSH session. If you are not connected yet, follow connect to your Linux VPS with SSH.
- A mariabackup backup directory, for example
/var/backups/mariadb/full. A full backup containsxtrabackup_checkpoints,ibdata1,mysql/and one directory per database. - The same MariaDB major version as the server that produced the backup. mariabackup is version-sensitive; check the vendor's documentation if you are moving between major releases.
- Free disk space at least equal to the size of the backup plus the current data directory, because you will keep the old directory until you are sure the restore worked.
Everything below stops MariaDB and replaces the live data directory. Take a copy of the current /var/lib/mysql before you touch it, and confirm you have a second backup you trust. If the restore fails halfway you will need that copy to get back online.
Confirm the data directory path first, because some installs use /var/lib/mysql and others use a custom path:
mysql -e "SELECT @@datadir, @@version;"Note the version string. It should match the version that created the backup.
Stop MariaDB and move the old data directory
Stop the service and make sure nothing is holding the data directory open:
sudo systemctl stop mariadb
sudo systemctl status mariadbThe status output should say inactive (dead). Then move the current data directory out of the way and create an empty one:
sudo mv /var/lib/mysql /var/lib/mysql.old.$(date +%F)
sudo mkdir -p /var/lib/mysqlmariabackup --copy-back refuses to write into a directory that already contains data, so this step is not optional.
Prepare the mariabackup files
A mariabackup backup is not usable until it has been prepared. Preparation applies the redo log so the InnoDB tables are consistent and the server can open them.
sudo mariabackup --prepare --target-dir=/var/backups/mariadb/fullYou will see a long stream of InnoDB output. The last line should look like:
[00] 2026-01-01 10:14:02 completed OK!If you also have incremental backups, prepare the base first, then each increment in order:
sudo mariabackup --prepare --target-dir=/var/backups/mariadb/full
sudo mariabackup --prepare --target-dir=/var/backups/mariadb/full \
--incremental-dir=/var/backups/mariadb/inc1Run --prepare on a copy of the backup if you want to keep the original untouched. Once prepared, the directory is modified in place.
Restore MariaDB from the prepared backup
With the data directory empty and the backup prepared, copy the files back:
sudo mariabackup --copy-back \
--target-dir=/var/backups/mariadb/full \
--datadir=/var/lib/mysqlIf the backup lives on the same filesystem and you do not need to keep it, --move-back is faster because it renames files instead of copying them:
sudo mariabackup --move-back --target-dir=/var/backups/mariadb/full --datadir=/var/lib/mysqlEither way, the command ends with completed OK!. If it stops with a permissions error, check that you ran it with sudo.
Fix ownership and start MariaDB
The copied files belong to root. MariaDB runs as the mysql user and will not start until ownership is corrected:
sudo chown -R mysql:mysql /var/lib/mysql
sudo find /var/lib/mysql -type d -exec chmod 750 {} \;
sudo find /var/lib/mysql -type f -exec chmod 640 {} \;Start the service and watch the log:
sudo systemctl start mariadb
sudo systemctl status mariadb
sudo tail -n 50 /var/log/mysql/error.logOn Debian and Ubuntu the error log may be at /var/log/mysql/error.log; on AlmaLinux and Rocky it is usually /var/log/mariadb/mariadb.log. If the service is active (running) and the log shows Ready for connections, the restore worked.
Check it works
Connect and confirm the data is what you expect:
mysql -e "SHOW DATABASES;"
mysql -e "SELECT user, host FROM mysql.user;"
mysql -e "SELECT COUNT(*) FROM your_app_db.orders;"Check that the application databases are present, that the user accounts are back, and that a table you know returns a sensible row count. Then open the site or application and log in. Once you are satisfied, keep the old directory for a few days before deleting it:
sudo du -sh /var/lib/mysql.old.*If you restored an incremental chain, the base plus every increment must be applied in order. A base-only restore will look successful but will be missing recent data.
Troubleshooting
- `mariabackup: error: cannot open ./xtrabackup_checkpoints` — you pointed
--target-dirat the wrong folder, or the backup was never completed. Check the path and that the file exists. - `--copy-back` fails with "data directory is not empty" — the target still contains files. Move
/var/lib/mysqlaside again and recreate it empty before retrying. - MariaDB will not start, log shows `Permission denied` on `ibdata1` — ownership was not fixed. Re-run the
chown -R mysql:mysql /var/lib/mysqlstep. - Log shows `Unsupported redo log format` or an InnoDB version error — the mariabackup binary and the MariaDB server version do not match the backup. Install the matching version, or restore into a server of the same major release.
- Server starts but tables are missing — you restored an incremental backup without preparing the base first, or you copied the wrong target directory. Re-run the prepare step in the correct order.
Next steps
- Need a single database rather than the whole instance? Use restore a MySQL database from a mysqldump file.
- Set up regular logical dumps alongside your physical backups with back up and restore MySQL databases with mysqldump.
- If the server was compromised before the restore, read incident response: preserving forensic evidence from a compromised Linux server before you overwrite anything.
- Check that the restored instance has enough memory for its workload with tune MySQL and MariaDB memory settings for a small VPS.
- Ready to run MariaDB on a fresh machine? See Linux VPS hosting.
Was this guide helpful?
Still stuck?
Ask RunRacks AI for a quick answer, or open a ticket and our team will take a look at your server.
Related guides
Databases
Reset a Forgotten MySQL Root Password on Linux
Recover access to MySQL or MariaDB on a Linux VPS by starting the server with skip-grant-tables, setting a new root password and restarting normally.
- Intermediate
- Linux VPS
- 5 min read
Databases
MySQL Point-in-Time Recovery Using Binary Logs
Recover a MySQL or MariaDB database to an exact moment after a bad write or dropped table by restoring a full backup and replaying binary logs up to the incident.
- Advanced
- Linux VPS
- 7 min read
Databases
How to create a database and user for a web app in MySQL or MariaDB
Set up a utf8mb4 database and a dedicated user with a strong password for WordPress, Laravel or any web app, then test the login before you configure the app.
- Beginner
- Linux VPS
- 4 min read