OrientDB Manual

Console - IMPORT

Imports a database to the current one opened. The input file is in JSON format using the Export-Format generated by Console Command Export tool. By default the file is compressed using the GZIP algorithm. The Export/Import commands allow to migrate between engine releases without loosing data. Use the Export command to generate the JSON file to import. Look also to Backup Database and Restore Database commands.

Syntax

import database <input-file> [-preserveClusterIDs = <true|false>]
                             [-merge = <true|false>]
                             [-migrateLinks = <true|false>]
                             [-rebuildIndexes = <true|false>]

Where:

  • input-file: input file path
  • -preserveClusterIDs: allows to keep the same cluster ids during import. Valid only for plocal storage. Import tool usually creates temporary clusters to keep cluster ids the same, but this approach fails some times so if you use plocal storage it is recommended to set this parameter during DB import.
  • -merge: merges the database to import into the current one. Security classes (ORole, OUser and OIdentity) are always preserved. By default is false that means overwrite current database (but security classes). Since 1.6.1.
  • -migrateLinks: Migrate links after import. This is needed to update all the references to the new RID. By default is true that means all the links are updated. Set it to false to speed up the importing only when -merge=true and if you're very sure no other existent records are linking the records you're importing. Since 1.6.1.
  • -rebuildIndexes: Rebuild indexes after import. By default is true that means all the indexes are rebuilt. Set it to false to speed up the importing only when you're very sure indexes aren't impacted from import. Since 1.6.1.

See also

Example

> 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

Troubleshooting

If during the importing you experience that "Imported cluster 'XXX' has id=6 different from the original: 5" means that your database was created with an ancient version of OrientDB:

- 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)

To fix it just drop the ORIDs class before to import the database:

orientdb> drop class ORIDs
orientdb> import database ...

Import API

Import command can be used in Java and any language on top of the JVM by using the class ODatabaseImport. Example:

ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:/temp/mydb");
db.open("admin", "admin");
try{
  OCommandOutputListener listener = new OCommandOutputListener() {
    @Override
    public void onMessage(String iText) {
      System.out.print(iText);
    }
  };

  ODatabaseImport import = new ODatabaseImport(db, "/temp/export/export.json.gz", listener);
  import.importDatabase();
  import.close();
} finally {
  db.close();
}