Other functions

LAST_INSERT_ID()

Returns ids of documents inserted or replaced by last statement in the current session.

The same value can be also received via @@session.last_insert_id variable:

  1. mysql> select @@session.last_insert_id;
  2. +--------------------------+
  3. | @@session.last_insert_id |
  4. +--------------------------+
  5. | 11,32 |
  6. +--------------------------+
  7. 1 rows in set
  8. mysql> select LAST_INSERT_ID();
  9. +------------------+
  10. | LAST_INSERT_ID() |
  11. +------------------+
  12. | 25,26,29 |
  13. +------------------+
  14. 1 rows in set

SELECT @@system_variable

  1. SELECT @@system_variable [LIMIT [offset,] row_count]

This is currently a placeholder query that does nothing and reports success. That is in order to keep compatibility with frameworks and connectors that automatically execute this statement.

However @@session.last_insert_id and LAST_INSERT_ID() report ID of documents these were inserted or replaced well at last statement.

  1. mysql> select @@session.last_insert_id;
  2. +--------------------------+
  3. | @@session.last_insert_id |
  4. +--------------------------+
  5. | 11,32 |
  6. +--------------------------+
  7. 1 rows in set
  8. mysql> select LAST_INSERT_ID();
  9. +------------------+
  10. | LAST_INSERT_ID() |
  11. +------------------+
  12. | 25,26,29 |
  13. +------------------+
  14. 1 rows in set

CONNECTION_ID()

Returns current connection id.

  1. mysql> select CONNECTION_ID();
  2. +-----------------+
  3. | CONNECTION_ID() |
  4. +-----------------+
  5. | 6 |
  6. +-----------------+
  7. 1 row in set (0.00 sec)

▪️ Securing and compacting a table

Backup and restore

It’s crucial to regularly back up your tables to recover them in case of system crashes, hardware failure, or data corruption/loss. Backups are also necessary before upgrading to a new version of Manticore Search that changes the table format, and for transferring data to another system when migrating to a new server.

The manticore-backup tool, included in the official Manticore Search packages, automates the process of backing up tables for an instance running in RT mode.

Installation

If you followed the official installation instructions, you should already have everything installed and don’t need to worry. Otherwise, manticore-backup requires PHP 8.1.10 and specific modules or manticore-executor, which is a part of the manticore-extra package, and you need to ensure that one of these is available.

Note that manticore-backup is not available for Windows yet.

How to use

First, make sure you’re running manticore-backup on the same server where the Manticore instance you are about to back up is running.

Second, we recommend running the tool under the root user so the tool can transfer ownership of the files you are backing up. Otherwise, a backup will be also made but with no ownership transfer. In either case, you should make sure that manticore-backup has access to the data dir of the Manticore instance.

The only required argument for manticore-backup is --backup-dir, which specifies the destination for the backup. If you don’t provide any additional arguments, manticore-backup will:

  • locate a Manticore instance running with the default configuration
  • create a subdirectory in the --backup-dir directory with a timestamped name
  • backup all tables found in the instance
  • Example

Example

  1. manticore-backup --config=path/to/manticore.conf --backup-dir=backupdir

Response

  1. Copyright (c) 2023, Manticore Software LTD (https://manticoresearch.com)
  2. Manticore config file: /etc/manticoresearch/manticore.conf
  3. Tables to backup: all tables
  4. Target dir: /mnt/backup/
  5. Manticore config
  6. endpoint = 127.0.0.1:9308
  7. Manticore versions:
  8. manticore: 5.0.2
  9. columnar: 1.15.4
  10. secondary: 1.15.4
  11. 2022-10-04 17:18:39 [Info] Starting the backup...
  12. 2022-10-04 17:18:39 [Info] Backing up config files...
  13. 2022-10-04 17:18:39 [Info] config files - OK
  14. 2022-10-04 17:18:39 [Info] Backing up tables...
  15. 2022-10-04 17:18:39 [Info] pq (percolate) [425B]...
  16. 2022-10-04 17:18:39 [Info] OK
  17. 2022-10-04 17:18:39 [Info] products (rt) [512B]...
  18. 2022-10-04 17:18:39 [Info] OK
  19. 2022-10-04 17:18:39 [Info] Running sync
  20. 2022-10-04 17:18:42 [Info] OK
  21. 2022-10-04 17:18:42 [Info] You can find backup here: /mnt/backup/backup-20221004171839
  22. 2022-10-04 17:18:42 [Info] Elapsed time: 2.76s
  23. 2022-10-04 17:18:42 [Info] Done

To back up specific tables only, use the --tables flag followed by a comma-separated list of tables, for example --tables=tbl1,tbl2. This will only backup the specified tables and ignore the rest.

  • Example

Example

  1. manticore-backup --backup-dir=/mnt/backup/ --tables=products

Response

  1. Copyright (c) 2023, Manticore Software LTD (https://manticoresearch.com)
  2. Manticore config file: /etc/manticoresearch/manticore.conf
  3. Tables to backup: products
  4. Target dir: /mnt/backup/
  5. Manticore config
  6. endpoint = 127.0.0.1:9308
  7. Manticore versions:
  8. manticore: 5.0.3
  9. columnar: 1.16.1
  10. secondary: 0.0.0
  11. 2022-10-04 17:25:02 [Info] Starting the backup...
  12. 2022-10-04 17:25:02 [Info] Backing up config files...
  13. 2022-10-04 17:25:02 [Info] config files - OK
  14. 2022-10-04 17:25:02 [Info] Backing up tables...
  15. 2022-10-04 17:25:02 [Info] products (rt) [512B]...
  16. 2022-10-04 17:25:02 [Info] OK
  17. 2022-10-04 17:25:02 [Info] Running sync
  18. 2022-10-04 17:25:06 [Info] OK
  19. 2022-10-04 17:25:06 [Info] You can find backup here: /mnt/backup/backup-20221004172502
  20. 2022-10-04 17:25:06 [Info] Elapsed time: 4.82s
  21. 2022-10-04 17:25:06 [Info] Done

Arguments

ArgumentDescription
—backup-dir=pathThis is the path to the backup directory where the backup will be stored. The directory must already exist. This argument is required and has no default value. On each backup run, manticore-backup will create a subdirectory in the provided directory with a timestamp in the name (backup-[datetime]), and will copy all required tables to it. So the —backup-dir is a container for all your backups, and it’s safe to run the script multiple times.
—restore[=backup]Restore from —backup-dir. Just —restore lists available backups. —restore=backup will restore from <—backup-dir>/backup.
—config=/path/to/manticore.confPath to Manticore config. This is optional. If it’s not passed, a default one for your operating system will be used. It’s used to get the host and port to communicate with the Manticore daemon.
—tables=tbl1,tbl2, …Semicolon-separated list of tables that you want to back up. To back up all tables, omit this argument. All the provided tables must exist in the Manticore instance you are backing up from, or the backup will fail.
—compressWhether the backed up files should be compressed. Not enabled by default.
—unlockIn rare cases when something goes wrong, tables can be left in a locked state. Use this argument to unlock them.
—versionShow the current version.
—helpShow this help.

BACKUP SQL command reference

You can also back up your data through SQL by running the simple command BACKUP TO /path/to/backup.

Note, this command is not supported in Windows yet.

General syntax of BACKUP

  1. BACKUP
  2. [{TABLE | TABLES} a[, b]]
  3. [{OPTION | OPTIONS}
  4. async = {on | off | 1 | 0 | true | false | yes | no}
  5. [, compress = {on | off | 1 | 0 | true | false | yes | no}]
  6. ]
  7. TO path_to_backup

For instance, to back up tables a and b to the /backup directory, run the following command:

  1. BACKUP TABLES a, b TO /backup

There are options available to control and adjust the backup process, such as:

  • async: makes the backup non-blocking, allowing you to receive a response with the query ID immediately and run other queries while the backup is ongoing. The default value is 0.
  • compress: enables file compression using zstd. The default value is 0. For example, to run a backup of all tables in async mode with compression enabled to the /tmp directory:
  1. BACKUP OPTION async = yes, compress = yes TO /tmp

Important considerations

  1. The path should not contain special symbols or spaces, as they are not supported.
  2. Ensure that Manticore Buddy is launched (it is by default).

Restore

To restore a Manticore instance from a backup, use the manticore-backup command with the --backup-dir and --restore arguments. For example: manticore-backup --backup-dir=/path/to/backups --restore. If you don’t provide any argument for --restore, it will simply list all the backups in the --backup-dir.

  • Example

Example

  1. manticore-backup --backup-dir=/mnt/backup/ --restore

Response

  1. Copyright (c) 2023, Manticore Software LTD (https://manticoresearch.com)
  2. Manticore config file:
  3. Backup dir: /tmp/
  4. Available backups: 3
  5. backup-20221006144635 (Oct 06 2022 14:46:35)
  6. backup-20221006145233 (Oct 06 2022 14:52:33)
  7. backup-20221007104044 (Oct 07 2022 10:40:44)

To start a restore job, run manticore-backup with the flag --restore=backup name, where backup name is the name of the backup directory within the --backup-dir. Note that:

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

If all conditions are met, the restore will proceed. The tool will provide hints, so you don’t have to memorize them. It’s crucial to avoid overwriting existing files, so make sure to remove them prior to the restore if they still exist. Hence all the conditions.

  • Example

Example

  1. manticore-backup --backup-dir=/mnt/backup/ --restore=backup-20221007104044

Response

  1. Copyright (c) 2023, Manticore Software LTD (https://manticoresearch.com)
  2. Manticore config file:
  3. Backup dir: /tmp/
  4. 2022-10-07 11:17:25 [Info] Starting to restore...
  5. Manticore config
  6. endpoint = 127.0.0.1:9308
  7. 2022-10-07 11:17:25 [Info] Restoring config files...
  8. 2022-10-07 11:17:25 [Info] config files - OK
  9. 2022-10-07 11:17:25 [Info] Restoring state files...
  10. 2022-10-07 11:17:25 [Info] config files - OK
  11. 2022-10-07 11:17:25 [Info] Restoring data files...
  12. 2022-10-07 11:17:25 [Info] config files - OK
  13. 2022-10-07 11:17:25 [Info] The backup '/tmp/backup-20221007104044' was successfully restored.
  14. 2022-10-07 11:17:25 [Info] Elapsed time: 0.02s
  15. 2022-10-07 11:17:25 [Info] Done