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.
import database <input-file> [-preserveClusterIDs = <true|false>]
[-merge = <true|false>]
[-migrateLinks = <true|false>]
[-rebuildIndexes = <true|false>]
Where:
> 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
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 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();
}