Console - IMPORT

Imports an exported database into the current one open. Import process doesn't lock the database, so any concurrent operations are allowed, but they could interfere in the import process causing errors.

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

IMPORT DATABASE <input-file> [-format = <format>]
                             [-preserveClusterIDs = <true|false>]
                             [-deleteRIDMapping = <true|false>]
                             [-merge = <true|false>]
                             [-migrateLinks = <true|false>]
                             [-rebuildIndexes = <true|false>]
  • <format> Is the input file format. If not specified, OrientDB tries to recognize it. The available formats are (since v2.2.8):
  • orientdb, the OrientDB export file format
  • graphml, for Graph XML
  • graphson, for Graph JSON
  • <input-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.
  • -deleteRIDMapping Defines whether you want to preserve the dictionary index used by the import to map old RIDs to new RIDs. The index name is ___exportImportRIDMap and you could use in your application. By default the index is removed after the import.
  • -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:

    orientdb> IMPORT DATABASE C:/temp/petshop.export -preserveClusterIDs=true
    
    Importing records...
    - Imported records into the cluster 'internal': 5 records
    - Imported records into the cluster 'index': 4 records
    - Imported records into the cluster 'default': 1022 records
    - Imported records into the cluster 'orole': 3 records
    - Imported records into the cluster 'ouser': 3 records
    - Imported records into the cluster 'csv': 100 records
    - Imported records into the cluster 'binary': 101 records
    - Imported records into the cluster 'account': 1005 records
    - Imported records into the cluster 'company': 9 records
    - Imported records into the cluster 'profile': 9 records
    - Imported records into the cluster 'whiz': 1000 records
    - Imported records into the cluster 'address': 164 records
    - Imported records into the cluster 'city': 55 records
    - Imported records into the cluster 'country': 55 records
    - Imported records into the cluster 'animalrace': 3 records
    - Imported records into the cluster 'ographvertex': 102 records
    - Imported records into the cluster 'ographedge': 101 records
    - 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.

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:

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

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

    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:

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

Importing records...

  • Creating cluster 'company'...Error on database import happened just before line 16, column 52 com.orientechnologies.orient.core.exception.OConfigurationException: Imported cluster 'company has id=6 different from the original: 5 at com.orientechnologies.orient.core.db.tool.ODatabaseImport.importClusters( ODatabaseImport.java:500) at com.orientechnologies.orient.core.db.tool.ODatabaseIMport.importDatabase( ODatabaseImport.java:121)

  • Drop the ORIDs class:

    orientdb> DROP CLASS ORIDs
    
  • Import the database:

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

The database now imports without error.