Skip to main content

Backing up MySQL and MariaDB databases

GBM AI Server dumps your MySQL or MariaDB databases with the server's own tool and, with the binary log, brings a database back to any second: the account, which databases, what lands in the backup, and how to restore one.

Updated
On this page

A database job on GBM AI Server backs up the databases of a MySQL or MariaDB server. GBM AI dumps them with the server's own tool, one consistent .sql file per database, and stores those files like any other: compressed, encrypted if the job is, checked, kept by its retention and copied to its second place. With the Incremental type it also copies the server's binary log between the dumps, so a database comes back to any second, not only to the time of a dump.

Before you start#

  • The MySQL add-on to GBM AI Server: MySQL and MariaDB backups come with it, one purchase for the server (Buy the add-on on the job's What step). The Server trial includes it. SQL Server has an add-on of its own.

  • An account on the database server that may read what it dumps. A dedicated one is best, for example:

    sql
    CREATE USER 'gbm_backup'@'localhost' IDENTIFIED BY 'a long password';
    GRANT SELECT, SHOW VIEW, TRIGGER, EVENT, LOCK TABLES ON *.* TO 'gbm_backup'@'localhost';

    If the account may not read scheduled events, GBM AI leaves them out and says so in the backup's log (Export log on its report).

    Grant the rights on the whole server (*.*, as above) or on whole databases (ON `shop`.*). An account granted single tables would dump only those, and nothing would say the others are missing; GBM AI checks this and says so when you sign in, and such a database is not backed up (E-DB-004) rather than half kept.

  • The server's dump tool on this PC. GBM AI uses mysqldump (MySQL) or mariadb-dump (MariaDB), the one that comes with the server; it ships none of its own. On the database's own server it is found in the server's bin folder. To back up a server that runs on another PC, install the MySQL or MariaDB client tools on this one.

  • For a restore to any second, the binary log (the Incremental type):

    • the server keeps a binary log in row format. MySQL 8 does by default. MariaDB does not: add these lines under [mysqld] in the server's my.ini, then restart the server:

      ini
      log_bin=mariadb-bin
      binlog_format=ROW
      server_id=1
    • the account may read it:

      sql
      GRANT RELOAD, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO 'gbm_backup'@'localhost';
    • the server's mysqlbinlog (mariadb-binlog for MariaDB) is on this PC, beside its dump tool.

    The What step checks all three when you sign in, and gives you the lines or the statement to copy.

  • Files and databases are two jobs. A job backs up files and folders, or databases. To back up both, make one job of each.

Step 1: Make a database job#

  1. Click New backup. On the Job step, under What does this job back up?, choose Databases and give the job a name. (On a new server, the welcome screen's Databases card does the same.)
  2. Where: choose where the backups go, as for any job.
  3. What: MySQL or MariaDB is chosen. Fill in Server (localhost for this PC), Port (3306 when empty), User name and Password. The password is sent to the agent once and stored encrypted on this PC; it is never shown again, and an edited job keeps it while the field stays empty. It is kept for that server and user only: change the server, the port or the user name and GBM AI asks for the password again.
  4. Click Sign in and list databases. GBM AI shows the server's version and the dump tool it will use. If it finds no tool, it says so now, not on the night of the first backup. Under Binary log it says Ready, or what the server still needs, with the lines for its my.ini or the GRANT for the account and a Copy button.
  5. Which databases: Every database, new ones too (a database created later is backed up without changing the job), or Only these and tick them. The server's own databases (mysql, sys, information_schema, performance_schema) are never included, so the server's user accounts and their grants are not in the backup: keep a script of them.

Wizard step 3 - databases on a MySQL serverWizard step 3 - databases on a MySQL server

Step 2: Settings and schedule#

  • Backup type:

    • Full: a whole dump of each database every run. A database comes back as it was at one of them.
    • Incremental: a dump a day, and the server's binary log between: a database comes back to any second. It can be chosen once the What step finds the binary log ready, and a new job takes it then.
  • Retention: Keep the backups of the last 35 days (Incremental: Restore to any moment in the last 35 days), or the days you choose; about one dump of each database a day.

  • Schedule:

    • Full: a dump every day at 02:00, under Full backups.
    • Incremental: the dumps every day at 02:00 and Binary log backups every 15 minutes. Each copies the binary log since the one before, so the 15 minutes are the most a restore can lose.

    Change them on the Schedule step, or choose Manual only.

  • Staging folder: each run dumps the databases into this folder first, then stores the dumps and empties it. It is GBM AI's own folder on the system drive unless you choose another with room for the dumps.

What a backup holds#

Each run writes:

  • one file per database, <database>.sql, as mysqldump writes it, with tables, views, routines, triggers and (when the account may read them) events;
  • binary columns written as hexadecimal, so no byte changes on the way back;
  • no CREATE DATABASE line, so a dump restores into a database of any name.

InnoDB tables are dumped at one consistent moment without being locked (--single-transaction), so the database stays in use. Tables of other engines (MyISAM) are read as they are; one written to during the dump may not match the others.

Each database is dumped on its own. A dump must end with the tool's Dump completed line; one that does not, or a tool that fails on a database (a view whose definer was dropped, a table changed mid-dump), means that database is not backed up: GBM AI never stores a half dump as if it were whole. The other databases are dumped and stored all the same.

The binary log (Incremental)#

A dump of an Incremental job notes where the server's binary log stood at that moment (a <database>.sql.json beside it). The runs between the dumps dump nothing: each closes the server's current binary-log file and copies the files closed since the last run into the point's binlog folder, with the server's own mysqlbinlog. The run's report shows a Binary log row with the files and their size.

The run takes a dump of each database again, and says why on its report, when:

  • the server deleted binary-log files before GBM AI copied them (its binlog_expire_logs_seconds, or a PURGE BINARY LOGS);
  • another MySQL server answers at the job's address.

Restores to any second go on from those dumps. If no binary log is kept for an hour (or three of the job's intervals for it), GBM AI tells you once a day: Binary log backups of the job have stopped.

When a database is not backed up#

A database the run could not dump, or one the job names that the server no longer has, is a failure for the job's alerts: the notification and the e-mail say "1 of 3 databases was not backed up" and name it. The run's report has a Databases list with each database, its dump's size, or why it was not backed up. The same databases missed again are told once a day.

Restoring a database#

Straight into the server#

  1. On Restore, open a point of the job. The Databases card beside the files lists the databases it holds.
  2. Click Into the server… beside the one you want.
  3. Choose where it goes:
    • As a new database (the default): give it a name the server does not have yet. The database already there is not touched, so you can compare the two or copy back only what you need.
    • Over the database it was made of: GBM AI first saves that database as it is now, with the server's own dump tool, then replaces it. If the restore fails, it puts the saved one back. The saved copy is kept for 7 days in the databases\before-restore folder of GBM AI's data folder (%ProgramData%\GBM AI for the service). Type the database's name to confirm.
  4. With the binary log (an Incremental job: the card says Any moment since a time), choose Bring it back to: Newest, or A moment and the date and time, to the second. GBM AI loads the dump, then replays the binary log after it up to that second (the changes made in that second included).
  5. Sign in with an account that may create and drop databases, such as root. The job's backup account usually may not: it only reads. The server and port are the job's; the password is used for this restore only and is not kept.

Restore - a database into the serverRestore - a database into the server

The report says which database it went into and how many tables it has, and with the binary log the moment it was brought back to; over a database, it also says where the one it replaced is kept.

GBM AI reads the binary log it will replay before it changes anything on the server:

  • Statements about the server's accounts (CREATE USER, GRANT, SET PASSWORD and the like) are left out: restoring a database never changes who may sign in.
  • A statement that changes another database (for example DROP TABLE other.tmp run while shop was the session's database) stops the restore before it starts: choose a moment before the one it names.
  • Restoring as a new database, a statement that names the database itself (ALTER TABLE shop.orders ..., or the DROP DATABASE and CREATE DATABASE an earlier restore over it wrote) would change the database on the server, not the new one: the restore stops before it starts. Choose a moment before it, or restore the database over itself.

As a file#

  1. On Restore, open a point of the job and pick the .sql file of the database. Restore it to another folder (in its own place, the job's staging folder, the next run would empty it).

  2. Load it into the server yourself with the server's client:

    text
    mysql -u root -p -e "CREATE DATABASE shop_restored"
    mysql -u root -p shop_restored < shop.sql

    (mariadb instead of mysql on MariaDB.)

Windows Server Core and scripts#

Server Core has no window: set the job up on a PC with one and export it (Export job JSON…), or write the job file, then on the server:

text
gbm db check --host localhost --user gbm_backup
gbm job import shop-db.json --db-password-stdin < db-password.txt
gbm db check --job "Shop DB"
gbm job run "Shop DB"
gbm restore --set latest --job "Shop DB" --databases
gbm restore --set latest --job "Shop DB" --database shop --as shop_copy --user root --db-password-stdin < root-password.txt
gbm restore --set latest --job "Shop DB" --database shop --over --user root --db-password-stdin < root-password.txt
gbm restore --set latest --job "Shop DB" --database shop --as shop_then --at "2026-11-22 14:30:15" --user root --db-password-stdin < root-password.txt

--at (a job of the Incremental type) brings the database back to that second; without it, to the newest the binary log reaches. On a Full job's dump it is refused: that dump comes back as it was when it was made. gbm db check --json has a binlog part: on, format, ready, and why not (off, format, rights, tool) with the GRANT for the missing rights.

gbm db check signs in as the job would and lists the server's databases and the dump tool it found; it fails, as the backup would, when it finds no tool. The password is asked for without being shown, or read from the input (--password-stdin, --db-password-stdin) or from GBM_DB_PASSWORD; it is never typed on the command line. An exported job file never holds it. gbm job run --json prints the run's record, with each database's dump or why it was not backed up. In the job file the databases look like this:

json
"databases": { "kind": "mysql", "host": "localhost", "port": 3306, "user": "gbm_backup", "names": ["shop", "crm"] }

Leave names out to back up every database of the server's users, new ones too. Add "staging": "D:\\GBM staging" for a staging folder of your own. The job's "options": { "type": "incremental" } makes it a job of the binary log; "full" dumps every run.

Troubleshooting#

CodeWhat happenedWhat to do
E-DB-001The database server refused the sign-in, or did not answerCheck the server, port, user name and password in the job, and that the database service is running
E-DB-002No mysqldump or mariadb-dump on this PCInstall the MySQL or MariaDB client tools on this PC, or back up from the database's own server
E-DB-003A database the job names is not on the serverIt was renamed or dropped: open the job and choose its databases again. The others are backed up meanwhile
E-DB-004A database could not be dumped, or the account may read only some of its tablesThe report names it and what the server said; usually the account lacks a right (SELECT, SHOW VIEW, TRIGGER, EVENT, LOCK TABLES) on the whole database, or a view's definer no longer exists
E-DB-005A database could not be restored into the serverThe report says what the server said. A new database needs a name the server does not have yet; the account needs the right to create databases and their routines. Over a database, it is back as it was
A binary-log run failsThe server keeps no binary log, keeps it in statement format, the account lacks a right, or mysqlbinlog is missingThe report says which. Sign in on the job's What step: it gives the my.ini lines or the GRANT. Or choose the Full type. The Settings step keeps the Incremental type only once the What step found the binary log ready
E-DB-004 naming a file of question marks (????.sql)The database's name has letters this Windows's language settings do not cover (Arabic on an English Windows). MySQL's own tools read their command line in that language and get question marksBack up from a Windows whose system locale covers the letters (Settings ▸ Time & language ▸ Language & region ▸ Administrative language settings ▸ Change system locale), use a name in plain letters, or MariaDB, whose tools take any name
A restore to a moment stops before it startsThe binary log after the dump holds a statement that would change another database, or the database itself when restored under another nameThe message names the moment: choose an earlier one, or restore the database over itself
E-LIC-011 on a database job's runsThe job was made in the Server trial and the Server licence has no add-on for its kindAdd the MySQL add-on (or the SQL Server add-on) in Editions & store. Restoring the job's backups keeps working without it

Was this article helpful?