Console - IMPORT

Imports an exported database into the current one open.

The input file must use the JSON Export Format, as generated by the EXPORT command. By default, this file is compressed using the GZIP algorithm.

With EXPORT, this command allows you to migrate between releases without losing data, by exporting data from the old version and importing it into the new version.

Syntax

  1. IMPORT DATABASE <input-file> [-preserveClusterIDs = <true|false>]
  2. [-merge = <true|false>]
  3. [-migrateLinks = <true|false>]
  4. [-rebuildIndexes = <true|false>]
  • <inputy-file> Defines the path to the file you want to import.
  • -preserveClusterIDs Defines whether you want to preserve cluster ID’s during the import. When turned off, the import creates temporary cluster ID’s, which can sometimes fail. This option is only valid with PLocal storage.
  • -merge Defines whether you want to merge the import with the data already in the current database. When turned off, the default, the import overwrites current data, with the exception of security classes, (ORole, OUser, OIdentity), which it always preserves. This feature was introduced in version 1.6.1.
  • -migrateLinks Defines whether you want to migrate links after the import. When enabled, this updates all references from the old links to the new Record ID’s. By default, it is enabled. Advisable that you only turn it off when merging and you’re certain no other existent records link to those you’re importing. This feature was introduced in version 1.6.1.
  • -rebuildIndexes Defines whether you want to rebuild indexes after the import. By default, it does. You can set it to false to speed up the import, but do so only when you’re certain the import doesn’t affect indexes. This feature was introduced in version 1.6.1.

Example

  • Import the database petshop.export:

    1. orientdb> IMPORT DATABASE C:/temp/petshop.export -preserveClusterIDs=true
    2.  
    3. Importing records...
    4. - Imported records into the cluster 'internal': 5 records
    5. - Imported records into the cluster 'index': 4 records
    6. - Imported records into the cluster 'default': 1022 records
    7. - Imported records into the cluster 'orole': 3 records
    8. - Imported records into the cluster 'ouser': 3 records
    9. - Imported records into the cluster 'csv': 100 records
    10. - Imported records into the cluster 'binary': 101 records
    11. - Imported records into the cluster 'account': 1005 records
    12. - Imported records into the cluster 'company': 9 records
    13. - Imported records into the cluster 'profile': 9 records
    14. - Imported records into the cluster 'whiz': 1000 records
    15. - Imported records into the cluster 'address': 164 records
    16. - Imported records into the cluster 'city': 55 records
    17. - Imported records into the cluster 'country': 55 records
    18. - Imported records into the cluster 'animalrace': 3 records
    19. - Imported records into the cluster 'ographvertex': 102 records
    20. - Imported records into the cluster 'ographedge': 101 records
    21. - Imported records into the cluster 'graphcar': 1 records

For more information on backups, restores, and exports, see: BACKUP, RESTORE and EXPORT commands, and the ODatabaseImport Java class. For the JSON format, see Export File Format.

For more information on other commands, see Console Commands.

Import API

In addition to the Console, you can also manage imports through the Java API, and with any language that runs on top of the JVM, using the ODatabaseImport class.

  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. ODatabaseImport import = new ODatabaseImport(db, "/temp/export/export.json.gz", listener);
  11. import.importDatabase();
  12. import.close();
  13. } finally {
  14. db.close();
  15. }

Troubleshooting

Validation Errors

Occasionally, you may encounter validation errors during imports, usually shown as an OValidationException exception. Beginning with version 2.2, you can disable validation at the database-level using the ALTER DATABASE command, to allow the import to go through.

  1. Disable validation for the current database:

    1. orientdb> ALTER DATABASE validation false
  2. Import the exported database:

    1. orientdb> IMPORT DATABASE /path/to/my_data.export -preserveClusterIDs=TRUE
  3. Re-enable validation:

    1. orientdb> ALTER DATABASE validation true

Cluster ID’s

During imports you may occasionally encounter an error that reads: Imported cluster 'XXX' has id=6 different from the original: 5. Typically occurs in databases that were created in much older versions of OrientDB. You can correct it using the DROP CLASS on the class ORIDs, then attempting the import again.

  1. Import the database:

    1. orientdb> IMPORT DATABASE /path/to/old_data.export
    2.  
    3. Importing records...
    4. - Creating cluster 'company'...Error on database import happened just before line
    5. 16, column 52 com.orientechnologies.orient.core.exception.OConfigurationException:
    6. Imported cluster 'company has id=6 different from the original: 5 at
    7. com.orientechnologies.orient.core.db.tool.ODatabaseImport.importClusters(
    8. ODatabaseImport.java:500) at
    9. com.orientechnologies.orient.core.db.tool.ODatabaseIMport.importDatabase(
    10. ODatabaseImport.java:121)
  • Drop the ORIDs class:

    1. orientdb> DROP CLASS ORIDs
  • Import the database:

    1. orientdb> IMPORT DATABASE /path/to/old_data.export

The database now imports without error.