Search in sources :

Example 6 with ODatabaseImport

use of com.orientechnologies.orient.core.db.tool.ODatabaseImport in project orientdb by orientechnologies.

the class AutomaticBackupTest method testExport.

//// @Test
// //TODO: move to EE test suite
// public void testIncrementalBackup() throws IOException, ClassNotFoundException, MalformedObjectNameException,
// InstanceAlreadyExistsException, NotCompliantMBeanException, MBeanRegistrationException {
// if (new File(BACKUPDIR + "/" + DBNAME).exists())
// OFileUtils.deleteRecursively(new File(BACKUPDIR + "/" + DBNAME));
//
// final OAutomaticBackup aBackup = new OAutomaticBackup();
//
// final OServerParameterConfiguration[] config = new OServerParameterConfiguration[] {
// new OServerParameterConfiguration("firstTime",
// new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000))),
// new OServerParameterConfiguration("delay", "1d"), new OServerParameterConfiguration("mode", "INCREMENTAL_BACKUP"),
// new OServerParameterConfiguration("target.directory", BACKUPDIR) };
//
// aBackup.config(server, config);
//
// try {
// Thread.sleep(5000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
//
// aBackup.sendShutdown();
//
// final ODatabaseDocumentTx database2 = new ODatabaseDocumentTx(URL2);
// if (database2.exists())
// database2.open("admin", "admin").drop();
// database2.create(BACKUPDIR + "/" + DBNAME);
//
// Assert.assertEquals(database2.countClass("TestBackup"), 1);
// }
@Test
public void testExport() throws IOException, ClassNotFoundException, MalformedObjectNameException, InstanceAlreadyExistsException, NotCompliantMBeanException, MBeanRegistrationException {
    if (new File(BACKUPDIR + "/fullExport.json.gz").exists())
        new File(BACKUPDIR + "/fullExport.json.gz").delete();
    final OAutomaticBackup aBackup = new OAutomaticBackup();
    final OServerParameterConfiguration[] config = new OServerParameterConfiguration[] { new OServerParameterConfiguration("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000))), new OServerParameterConfiguration("delay", "1d"), new OServerParameterConfiguration("mode", "EXPORT"), new OServerParameterConfiguration("target.directory", BACKUPDIR), new OServerParameterConfiguration("target.fileName", "fullExport.json.gz") };
    aBackup.config(server, config);
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    aBackup.sendShutdown();
    final ODatabaseDocumentTx database2 = new ODatabaseDocumentTx(URL2);
    if (database2.exists())
        database2.open("admin", "admin").drop();
    database2.create();
    new ODatabaseImport(database2, BACKUPDIR + "/fullExport.json.gz", null).importDatabase();
    Assert.assertEquals(database2.countClass("TestBackup"), 1);
}
Also used : ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 7 with ODatabaseImport

use of com.orientechnologies.orient.core.db.tool.ODatabaseImport in project orientdb by orientechnologies.

the class DbImportExportTest method testDbImport.

@Test(dependsOnMethods = "testDbExport")
public void testDbImport() throws IOException {
    final File importDir = new File(testPath + "/" + NEW_DB_PATH);
    if (importDir.exists())
        for (File f : importDir.listFiles()) f.delete();
    else
        importDir.mkdir();
    ODatabaseDocumentTx database = new ODatabaseDocumentTx(getStorageType() + ":" + testPath + "/" + NEW_DB_URL);
    database.create();
    ODatabaseImport dbImport = new ODatabaseImport(database, testPath + "/" + exportFilePath, this);
    // UNREGISTER ALL THE HOOKS
    for (ORecordHook hook : new ArrayList<ORecordHook>(database.getHooks().keySet())) {
        database.unregisterHook(hook);
    }
    dbImport.setPreserveRids(true);
    dbImport.setDeleteRIDMapping(false);
    dbImport.importDatabase();
    dbImport.close();
    database.close();
}
Also used : ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) ArrayList(java.util.ArrayList) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) File(java.io.File) ORecordHook(com.orientechnologies.orient.core.hook.ORecordHook) Test(org.testng.annotations.Test)

Example 8 with ODatabaseImport

use of com.orientechnologies.orient.core.db.tool.ODatabaseImport in project orientdb by orientechnologies.

the class ObjectExportImportTest method testExportImport.

@Test
public void testExportImport() throws IOException {
    OObjectDatabaseTx db = new OObjectDatabaseTx("memory:test");
    db.create();
    db.setAutomaticSchemaGeneration(true);
    db.getMetadata().getSchema().synchronizeSchema();
    assertNotNull(db.getMetadata().getSchema().getClass("ODocumentWrapper"));
    byte[] bytes;
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    new ODatabaseExport(db.getUnderlying(), byteOutputStream, new OCommandOutputListener() {

        @Override
        public void onMessage(String iText) {
        }
    }).exportDatabase().close();
    bytes = byteOutputStream.toByteArray();
    OObjectDatabaseTx db1 = new OObjectDatabaseTx("memory:test1");
    db1.create();
    db1.setAutomaticSchemaGeneration(true);
    db1.getMetadata().getSchema().synchronizeSchema();
    InputStream input = new ByteArrayInputStream(bytes);
    new ODatabaseImport(db1.getUnderlying(), input, new OCommandOutputListener() {

        @Override
        public void onMessage(String iText) {
        }
    }).importDatabase().close();
    assertNotNull(db1.getMetadata().getSchema().getClass("ODocumentWrapper"));
}
Also used : ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) ODatabaseExport(com.orientechnologies.orient.core.db.tool.ODatabaseExport) Test(org.testng.annotations.Test)

Aggregations

ODatabaseImport (com.orientechnologies.orient.core.db.tool.ODatabaseImport)8 File (java.io.File)5 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)4 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)3 ODatabaseExport (com.orientechnologies.orient.core.db.tool.ODatabaseExport)3 IOException (java.io.IOException)3 ORecordHook (com.orientechnologies.orient.core.hook.ORecordHook)2 OServerParameterConfiguration (com.orientechnologies.orient.server.config.OServerParameterConfiguration)2 FileInputStream (java.io.FileInputStream)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 Test (org.junit.Test)2 Test (org.testng.annotations.Test)2 OIOException (com.orientechnologies.common.io.OIOException)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1 OObjectDatabaseTx (com.orientechnologies.orient.object.db.OObjectDatabaseTx)1