Importing DB into embedded server

Hello,

I am trying to set up a small test environment within the test code (using the embedded server) and wanted to import an existing graph with a few hundred vertices and edges to test against. I have exported the DB via OrientDB Studio but I have not found a solution. This approach from 2.1 is the only thing I have found, which I wasn’t able to get working (we are using 3.0.23 so I think it is probably not the intended route).

I have managed to create a DB (via the OrientDB Java API) and also start the server using the code described in the docs. But do you have any advice on how to import a database into OrientDB using the Java API?

import/export via java api works for me in 3.0.27

public void exportDatabase(OutputStream os) throws IOException {
    try (ODatabaseDocumentInternal db = server.openDatabase(dbName)) {
        ODatabaseExport export = new ODatabaseExport(db, os, (String iText)->{System.out.println(iText);});
        try {
            export.exportDatabase();
        }
        finally {
            export.close();
        }
    }
}

public void importDatabase(InputStream is) throws IOException {
    try (ODatabaseDocumentInternal db = server.openDatabase(dbName)) {
        ODatabaseImport import_ = new ODatabaseImport(db, is, (String iText)->{System.out.println(iText);});
        try {
            import_.importDatabase();
        }
        finally {
            import_.close();
        }
    }
}

btw. Why not to do ODatabaseExport/ODatabaseImport implements AutoClosable?

Thank you! It seems I was on the right track then. Btw, do you know if it is possible to avoid creating the “databases” directory in the EmbeddedServer and does the system database OSystem have to use plocal or is it possible to keep everything in memory? I attached a part of the log below as an example.

2020-01-21 14:35:00:227 INFO  Loading configuration from input stream [OServerConfigurationLoaderXml]
2020-01-21 14:35:00:550 INFO  OrientDB Server v3.0.21 - Veloce (build 1d8b0c01ca8fe12a516bba355681e3ec8b218d1d, branch 3.0.x) is starting up... [OServer]
2020-01-21 14:35:00:627 INFO  34359738368 B/32768 MB/32 GB of physical memory were detected on machine [ONative]
2020-01-21 14:35:00:627 INFO  Detected memory limit for current process is 34359738368 B/32768 MB/32 GB [ONative]
2020-01-21 14:35:00:628 INFO  JVM can use maximum 7282MB of heap memory [OMemoryAndLocalPaginatedEnginesInitializer]
2020-01-21 14:35:00:628 INFO  Because OrientDB is running outside a container 12% of memory will be left unallocated according to the setting 'memory.leftToOS' not taking into account heap memory [OMemoryAndLocalPaginatedEnginesInitializer]
2020-01-21 14:35:00:629 INFO  OrientDB auto-config DISKCACHE=21,553MB (heap=7,282MB os=32,768MB) [orientechnologies]
2020-01-21 14:35:00:629 INFO  System is started under an effective user : `esebtor` [OEngineLocalPaginated]
2020-01-21 14:35:00:629 INFO  Allocation of 327605 pages. [OEngineLocalPaginated]
2020-01-21 14:35:00:798 INFO  Directory /Users/esebtor/work/zipper_jobexecutionstats_service/databases does not exist, try to create it. [OrientDBEmbedded]
2020-01-21 14:35:00:814 INFO  WAL maximum segment size is set to 7,054 MB [OrientDBEmbedded]
2020-01-21 14:35:00:815 INFO  Databases directory: /Users/esebtor/work/zipper_jobexecutionstats_service/databases [OServer]
2020-01-21 14:35:00:845 INFO  Creating the system database 'OSystem' for current server [OSystemDatabase]
2020-01-21 14:35:01:003 INFO  Storage 'plocal:/Users/esebtor/work/zipper_jobexecutionstats_service/databases/OSystem' is created under OrientDB distribution : 3.0.21 - Veloce (build 1d8b0c01ca8fe12a516bba355681e3ec8b218d1d, branch 3.0.x) [OLocalPaginatedStorage]