brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: mariadb-backup copies the database files of a running server, and prepare makes them usable

Database
~/tips/tip-database-mariadb-backup-physical

mariadb-backup --backup --target-dir=/backup/full --user=root --password

Takes a fast physical backup of a live MariaDB server instead of a slow SQL dump.

A SQL dump of a big database is slow to make and slower to restore, because every row gets inserted again. mariadb-backup copies the data files themselves while the server keeps running.

mariadb-backup --backup --target-dir=/backup/full --user=root --password
mariadb-backup --prepare --target-dir=/backup/full

The first step copies the files and records the changes that came in during the copy. Right after it, the files are not consistent yet. The --prepare step applies that log, and only then is the directory a clean copy that a server can start from. Both runs end with completed OK! when things went well, and I’d check for that line in any script.

To restore, stop the server, make sure the data directory is empty, copy the files back and fix the owner:

mariadb-backup --copy-back --target-dir=/backup/full
chown -R mysql:mysql /var/lib/mysql

A few things trip people up. The backup only fits the same major MariaDB version, so it is not a way to move data between versions; use a dump for that. --copy-back refuses to write into a data directory that still has files, and that is a good thing, because it protects whatever is there. In Docker, run it inside the MariaDB container so the tool and the server versions match.

Further reading: Full backup and restore with mariadb-backup

More Database tips mariadb -e 'CREATE DATABASE IF NOT EXISTS blog' mariadb-dump --no-create-info --insert-ignore shop orders > orders-rows.sql SELECT table_schema, table_name, CHECKSUM TABLE shop.orders; services: All Database tips (53) All topics

Link