Console - RESTORE DATABASE

Restores a database from a backup. It must be done against a new database. It does not support restores that merge with an existing database. If you need to backup and restore to an existing database, use the EXPORT DATABASE and IMPORT DATABASE commands.

OrientDB Enterprise Edition version 2.2 and major, support incremental backup.

To create a backup file to restore from, use the BACKUP DATABASE command.

Syntax

  1. RESTORE DATABASE <backup-file>|<incremental-backup-directory>
  • <backup-file> Defines the database file you want to restore.
  • <incremental-backup-directory> Defines the database directory you want to restore from an incremental backup. Available only in OrientDB Enterprise Edition version 2.2 and major.

Example of full restore

  • Create a new database to receive the restore:

    1. orientdb> CREATE DATABASE PLOCAL:/tmp/mydb
  • Restore the database from the mydb.zip backup file:

    1. orientdb {db=/tmp/mydb}> RESTORE DATABASE /backups/mydb.zip

Example of incremental restore

This is available only in OrientDB Enterprise Edition version 2.2 and major.

  • Open a database to receive the restore:

    1. orientdb> CONNECT PLOCAL:/tmp/mydb
  • Restore the database from the /backup backup directory:

    1. orientdb {db=/tmp/mydb}> RESTORE DATABASE /backup

For more information, see the BACKUP DATABASE, EXPORT DATABASE, IMPORT DATABASE commands. For more information on other commands, see Console Commands.

Restore API

In addition to the console commands, you can also execute restores through the Java API or with any language that can run on top of the JVM using the restore() method against the database instance.

  1. db.restore(in, options, callable, listener);
  • in Defines the InputStream used to read the backup content. Uses a FileInputStream to read the backup content from disk.
  • options Defines backup options, such as Map<String, Object> object.
  • callable Defines the callback to execute when the database is locked.
  • listener Listener called for backup messages.
  • compressionLevel Defines the Zip Compression level, between 0 for no compression and 9 for maximum compression. The greater the compression level, the smaller the final backup content and the greater the CPU and time it takes to execute.
  • bufferSize Buffer size in bytes, the greater the buffer the more efficient the compression.

Example

  1. ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:/temp/mydb");
  2. db.open("admin", "admin");
  3. try{
  4. OCommandOutputListener listener = new OCommandOutputListener() {
  5. @Override
  6. public void onMessage(String iText) {
  7. System.out.print(iText);
  8. }
  9. };
  10. InputStream out = new FileInputStream("/temp/mydb.zip");
  11. db.restore(in,null,null,listener);
  12. } finally {
  13. db.close();
  14. }