Console - BACKUP

Executes a complete backup on the currently opened database. It then compresses the backup file using the ZIP algorithm. You can then restore a database from backups, using the RESTORE DATABASE command. You can automate backups using the Automatic-Backup server plugin.

Backups and restores are similar to the EXPORT DATABASE and IMPORT DATABASE, but they offer better performance than these options.

NOTE: OrientDB Community Edition does not support backing up remote databases. OrientDB Enterprise Edition does support this feature. For more information on how to implement this with Enterprise Edition, see Remote Backups.

Syntax:

  1. BACKUP DATABASE <output-file> [-incremental] [-compressionLevel=<compressionLevel>] [-bufferSize=<bufferSize>]
  • <output-file> Defines the path to the backup file.
  • -incremental Option to execute an incremental backup. When enabled, it computes the data to backup as all new changes since the last backup. Available in OrientDB Enterprise Edition version 2.2 or later.
  • -compressionLevel Defines the level of compression for the backup file. Valid levels are 0 to 9. The default is 9. Available in 1.7 or later.
  • -bufferSize Defines the compression buffer size. By default, this is set to 1MB. Available in 1.7 or later.

Example:

  • Backing up a database:
  1. orientdb> CONNECT plocal:../databases/mydatabase admin admin
  2. orientdb> BACKUP DATABASE /backups/mydb.zip
  3.  
  4. Backing current database to: database mydb.zip
  5. Backup executed in 0.52 seconds

Backup API

In addition to backups called through the Console, you can also manage backups through the Java API. Using this, you can perform either a full or incremental backup on your database.

Full Backup

In Java or any other language that runs on top of the JVM, you can initiate a full backup by using the backup() method on a database instance.

  1. db.backup(out, options, callable, listener, compressionLevel, bufferSize);
  • out Refers to the OutputStream that it uses to write the backup content. Use a FileOutputStream to make the backup persistent on disk.
  • options Defines backup options as a Map<String, Object> object.
  • callable Defines the callback to execute when the database is locked.
  • listener Defines the listened called for backup messages.
  • compressionLevel Defines the level of compression for the backup. It supports levels between 0 and 9, where 0 equals no compression and 9 the maximum. Higher compression levels do mean smaller files, but they also mean the backup requires more from the CPU at execution time.
  • bufferSize Defines the buffer size in bytes. The larger the buffer, the more efficient the comrpession.

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. OutputStream out = new FileOutputStream("/temp/mydb.zip");
  11. db.backup(out,null,null,listener,9,2048);
  12. } finally {
  13. db.close();
  14. }

Incremental Backup

As of version 2.2, OrientDB Enterprise Edition supports incremental backups executed through Java or any language that runs on top of the JVM, using the incrementalBackup() method against a database instance.

  1. db.incrementalBackup(backupDirectory);
  • backupDirectory Defines the directory where it generates the incremental backup files.

It is important that previous incremental backup files are present in the same directory, in order to compute the database portion to back up, based on the last incremental backup.

Example:

  1. ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:/temp/mydb");
  2. db.open("admin", "admin");
  3. try{
  4. db.backup("/var/backup/orientdb/mydb");
  5. } finally {
  6. db.close();
  7. }

For more information, see: