Terminal Terminal | Web Web
Home  //  Play

Manticore Backup

Difficulty: Beginner
Estimated Time: 10 minutes

Manticoresearch - Backup

In this tutorial, you will learn how to use the 'manticore-backup' tool provided by Manticore Search.

Manticore Backup

Step 1 of 5

Introduction

You may need to regularly back up your tables to be able to recover them later in case of necessity. Manticore Search provides a manticore-backup tool to let you do this.

manticore-backup is included in the official installation package and enabled by default. Otherwise, e.g., if you've installed your Manticore Search instance manually, you'll need PHP>=8.1.10 installed as well as the specific modules of the Manticore's manticor-executor, a part of the manticore-extra package.

Also note that:

  • manticore-backup must have access to the data dir of your Manticore instance.
  • We recommend running manticore-backup under the roor user to let it transfer the ownership of the files being backed up. Otherwise, a backup is made without ownership transfer.
  • The tool is not available for Windows yet.

Backing up tables

Let's create tables in Manticore and back them up.

Connect to Manticore and create two test tables:

mysql -P9306 -h0 -e 'CREATE TABLE test1 (f TEXT); CREATE TABLE test2 (f TEXT); SHOW TABLES'

To back up all tables, you can use the 'manticore-backup' command:

manticore-backup --config=/your_manticore_config_path --backup-dir=/your_backup_dir

Note that you can omit the config flag. In such case, the default Manticore config path will be used.

Let's run our backup:

manticore-backup --backup-dir=/backup

ls /backup

As you see from the tool's output, the tables are successfully backed up to the /backup directory from where you can restore them later.

Restoring tables

Now let's delete the tables and restore them from the backup we've just created.

mysql -P9306 -h0 -e 'DROP TABLE test1; DROP TABLE test2; SHOW TABLES;'

To see information of previously made backups, use the corresponding --restore flag:

manticore-backup --backup-dir=/backup --restore

To start restoring, set the name of your backup as the value of the --restore flag.

manticore-backup --backup-dir=your_backup_directory --restore=your_backup_name

Before restoring, you must make sure the following conditions are satisfied:

  • There can't be any Manticore instance running on the same host and port as the one being restored.
  • The old manticore.json file must not exist.
  • The old configuration file must not exist.
  • The old data directory must exist and be empty.

If you forget to do one of the things above the tool will give you a corresponding hint, so you don't have to memorize them.

Let's try to start backup with our previous backup's name:

BACKUP_NAME=$(manticore-backup --backup-dir=/backup --restore | grep backup | awk {'print $1'} | tail -n 1)

manticore-backup --backup-dir=/backup --restore=$BACKUP_NAME

As you see, the manticore-backup has given you the hint about what must be done. So, let's fulfill all the necessary actions.

Stop the Manticore daemon:

searchd --stop

Remove the old manticore.json and manticore.conf files:

rm -rf /var/lib/manticore/manticore.json /etc/manticoresearch/manticore.conf

Empty the Manticore data directory:

rm -rf /var/lib/manticore/* /var/lib/manticore/.*

Now we can safely run restoring:

manticore-backup --backup-dir=/backup --restore=$BACKUP_NAME

Finally, let's restart the daemon and check if our tables are successfully restored:

searchd

mysql -P9306 -h0 -e 'SHOW TABLES;'

Backing up and restoring specific tables

To back up specific tables only, use the --tables flag followed by a comma-separated list of table names:

manticore-backup --backup-dir=/your_backup_directory --tables=your_table_1,your_table_2,your_table_N

Let's backup only the test1 table:

manticore-backup --backup-dir=/backup --tables=test1

Delete all tables again:

mysql -P9306 -h0 -e 'DROP TABLE test1; DROP TABLE test2;'

But this time we'll restore only the table we've specified, i.e. test1.

Repeat all the preparatory actions:

searchd --stop

rm -rf /var/lib/manticore/manticore.json /etc/manticoresearch/manticore.conf

rm -rf /var/lib/manticore/* /var/lib/manticore/.*

And start restoring:

BACKUP_NAME=$(manticore-backup --backup-dir=/backup --restore | grep backup | awk {'print $1'} | tail -n 1)

manticore-backup --backup-dir=/backup --restore=$BACKUP_NAME

Let's look at the results:

searchd

mysql -P9306 -h0 -e 'SHOW TABLES;'

Indeed, as we see, only the test1 table has been restored.

Backing up and restoring tables via MySQL client

Also, you have an alternative way to backup/restore your tables by using MySQL client. (As in case of manticoresearch-backup, it's not supported in Windows yet)

To do this, connect to the client and run the simple command BACKUP ... TO /path/to/your/backup

Note that the following conditions need to be satisfied:

  • the path to the backup should not contain special symbols or spaces, as they are not supported.
  • Manticore Buddy is launched (it is by default).

mysql -P9306 -h0

Create the second test table again:

CREATE TABLE test2 (f TEXT);

And run backup:

BACKUP TABLES test1, test2 TO /backup_mysql;

If you want to backup a single table only, use the following syntax:

BACKUP TABLE test1 TO /backup_mysql;

exit

Make sure, backups are successfully created:

ls /backup_mysql

Now, let's reconnect to the client and delete the test1 table:

mysql -P9306 -h0 -e "DROP TABLE test1;"

Then, get the name of the table's backup and run the IMPORT query to restore the table:

BACKUP_NAME=$(ls /backup_mysql | grep 'backup-' | tail -n 1)

mysql -P9306 -h0 -e "IMPORT TABLE test1 FROM '/backup_mysql/$BACKUP_NAME/data/test1/test1'"

Let's look at the result:

mysql -P9306 -h0 -e "SHOW TABLES"

As we see, the test1 table has been successfully restored. Note that you can only import a single table at a time.