Partial Backup and Restore with Mariabackup

You are viewing an old version of this article. View the current version here.

When using Mariabackup, you have the option of performing partial backups. Partial backups allow you to choose which databases or tables to backup, rather than backing up all databases and tables on the server. This page documents how to perform partial backups.

Backing up the Database Server

Just like with full backups, in order to back up the database, you need to run Mariabackup with the --backup option to tell it to perform a backup and with the --target-dir option to tell it where to place the backup files. The target directory must be empty or not exist.

For a partial backup, there are a few other arguments that you can provide as well:

  • To tell it which databases to backup, you can provide the --databases option.
  • To tell it which databases to exclude from the backup, you can provide the --databases-exclude option.
  • To tell it to check a file for the databases to backup, you can provide the --databases-file option.
  • To tell it which tables to backup, you can use the --tables option.
  • To tell it which tables to exclude from the backup, you can provide the --databases-exclude option.
  • To tell it to check a file for the databases to backup, you can provide the --tables-file option.

The non-file partial backup options support regex in the database and table names.

For example, to take a backup of any database that starts with the string app1_ and any table in those databases that start with the string tab_, run the following command:

$ mariabackup --backup \
   --target-dir=/var/mariadb/backup/ \
   --databases='app1_*' --tables='tab_*' \
   --user backup_user --password backup_passwd

The time the backup takes depends on the size of the databases or tables you're backing up. You can cancel the backup if you need to, as the backup process does not modify the database.

Mariabackup writes the backup files the target directory. If the target directory doesn't exist, then it creates it. If the target directory exists and contains files, then it raises an error and aborts.

Preparing the Backup

Just like with full backups, the data files that Mariabackup creates in the target directory are not point-in-time consistent, given that the data files are copied at different times during the backup operation. If you try to restore from these files, InnoDB notices the inconsistencies and crashes to protect you from corruption. In fact, for partial backups, the backup is not even a completely functional MariaDB data directory, so InnoDB would raise more errors than it would for full backups. This point will also be very important to keep in mind during the restore process.

Before you can restore from a backup, you first need to prepare it to make the data files consistent. You can do so with the --prepare command option. For partial backups, you also need to add the --export option.

$ mariabackup --prepare --export \
   --target-dir=/var/mariadb/backup/ \
   --user backup_user --password backup_passwd

If this operation completes without error, then the backup is ready to be restored.

Restoring from the Backup

The restore process for partial backups is quite different than the process for full backups. A partial backup is not a completely functional data directory. The data dictionary in the InnoDB system tablespace will still contain entries for the databases and tables that were not included in the backup.

Rather than using the --copy-back or the --move-back, each tablespace file will have to be manually imported into the target server. This process is exactly the same as it is for importing transportable tablespaces.

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.