@ConsoleCommand(description = "Export a database", splitInWords = false, onlineHelp = "Console-Command-Export") public void exportDatabase(@ConsoleParameter(name = "options", description = "Export options") final String iText) throws IOException { checkForDatabase(); out.println(new StringBuilder("Exporting current database to: ").append(iText).append(" in GZipped JSON format ...")); final List<String> items = OStringSerializerHelper.smartSplit(iText, ' '); final String fileName = items.size() <= 1 || items.get(1).charAt(0) == '-' ? null : items.get(1); final String options = fileName != null ? iText.substring(items.get(0).length() + items.get(1).length() + 1).trim() : iText; try { new ODatabaseExport(currentDatabase, fileName, this).setOptions(options).exportDatabase().close(); } catch (ODatabaseExportException e) { printError(e); } }
@ConsoleCommand(description = "Restore a database into the current one", splitInWords = false, onlineHelp = "Console-Command-Restore") public void restoreDatabase(@ConsoleParameter(name = "options", description = "Restore options") final String text) throws IOException { checkForDatabase(); final List<String> items = OStringSerializerHelper.smartSplit(text, ' '); if (items.size() < 2) try { syntaxError("restoreDatabase", getClass().getMethod("restoreDatabase", String.class)); return; } catch (NoSuchMethodException e) { } final String fileName = items.size() <= 0 || (items.get(1)).charAt(0) == '-' ? null : items.get(1); final long startTime = System.currentTimeMillis(); try { // FULL RESTORE message("\nRestoring database '%s' from full backup...", text); final FileInputStream f = new FileInputStream(fileName); try { currentDatabase.restore(f, null, null, this); } finally { f.close(); } } catch (ODatabaseImportException e) { printError(e); } finally { message("\nDatabase restored in %.2f seconds", ((float) (System.currentTimeMillis() - startTime) / 1000)); } }
@ConsoleCommand(description = "Displays the status of the cluster nodes") public void clusterStatus() throws IOException { checkForRemoteServer(); try { message("\nCluster status:"); ODocument clusterStatus = ((OrientDBRemote) OrientDBInternal.extract(orientDB)) .getClusterStatus(currentDatabaseUserName, currentDatabaseUserPassword); out.println(clusterStatus.toJSON("attribSameRow,alwaysFetchEmbedded,fetchPlan:*:0")); } catch (Exception e) { printError(e); } }
@ConsoleCommand(description = "Import a database into the current one", splitInWords = false, onlineHelp = "Console-Command-Import") public void importDatabase(@ConsoleParameter(name = "options", description = "Import options") final String text) throws IOException { checkForDatabase(); message("\nImporting database " + text + "..."); final List<String> items = OStringSerializerHelper.smartSplit(text, ' '); final String fileName = items.size() <= 0 || (items.get(1)).charAt(0) == '-' ? null : items.get(1); final String options = fileName != null ? text.substring((items.get(0)).length() + (items.get(1)).length() + 1).trim() : text; try { if (currentDatabase.getStorage().isRemote()) { ODatabaseImportRemote databaseImport = new ODatabaseImportRemote(currentDatabase, fileName, this); databaseImport.setOptions(options); databaseImport.importDatabase(); databaseImport.close(); } else { ODatabaseImport databaseImport = new ODatabaseImport(currentDatabase, fileName, this); databaseImport.setOptions(options); databaseImport.importDatabase(); databaseImport.close(); } } catch (ODatabaseImportException e) { printError(e); } }
@ConsoleCommand(description = "Export the current record in the requested format", onlineHelp = "Console-Command-Export-Record") public void exportRecord(@ConsoleParameter(name = "format", description = "Format, such as 'json'") final String iFormat, @ConsoleParameter(name = "options", description = "Options", optional = true) String iOptions) throws IOException { checkForDatabase(); checkCurrentObject(); final ORecordSerializer serializer = ORecordSerializerFactory.instance().getFormat(iFormat.toLowerCase(Locale.ENGLISH)); if (serializer == null) { message("\nERROR: Format '" + iFormat + "' was not found."); printSupportedSerializerFormat(); return; } else if (!(serializer instanceof ORecordSerializerStringAbstract)) { message("\nERROR: Format '" + iFormat + "' does not export as text."); printSupportedSerializerFormat(); return; } if (iOptions == null || iOptions.length() <= 0) { iOptions = "rid,version,class,type,keepTypes,alwaysFetchEmbedded,fetchPlan:*:0,prettyPrint"; } try { out.println(currentRecord.toJSON(iOptions)); } catch (ODatabaseExportException e) { printError(e); } }
@ConsoleCommand(description = "Compare two databases") public void compareDatabases(@ConsoleParameter(name = "db1-url", description = "URL of the first database") final String iDb1URL, @ConsoleParameter(name = "db2-url", description = "URL of the second database") final String iDb2URL, @ConsoleParameter(name = "username", description = "User name", optional = false) final String iUserName, @ConsoleParameter(name = "password", description = "User password", optional = false) final String iUserPassword, @ConsoleParameter(name = "detect-mapping-data", description = "Whether RID mapping data after DB import should be tried to found on the disk", optional = true) String autoDiscoveringMappingData) throws IOException { try { final ODatabaseCompare compare = new ODatabaseCompare(iDb1URL, iDb2URL, iUserName, iUserPassword, this); compare.setAutoDetectExportImportMap(autoDiscoveringMappingData != null ? Boolean.valueOf(autoDiscoveringMappingData) : true); compare.setCompareIndexMetadata(true); compare.compare(); } catch (ODatabaseExportException e) { printError(e); } }
@ConsoleCommand(description = "Export a database schema") public void exportSchema(@ConsoleParameter(name = "output-file", description = "Output file path") final String iOutputFilePath) throws IOException { checkForDatabase(); message("\nExporting current database to: " + iOutputFilePath + "..."); try { ODatabaseExport exporter = new ODatabaseExport(currentDatabase, iOutputFilePath, this); exporter.setIncludeRecords(false); exporter.exportDatabase().close(); } catch (ODatabaseExportException e) { printError(e); } }
@ConsoleCommand(description = "Check database integrity", splitInWords = false) public void checkDatabase(@ConsoleParameter(name = "options", description = "Options: -v", optional = true) final String iOptions) throws IOException { checkForDatabase(); if (!(currentDatabase.getStorage() instanceof OAbstractPaginatedStorage)) { message("\nCannot check integrity of non-local database. Connect to it using local mode."); return; } boolean verbose = iOptions != null && iOptions.contains("-v"); message("\nChecking storage."); try { ((OAbstractPaginatedStorage) currentDatabase.getStorage()).check(verbose, this); } catch (ODatabaseImportException e) { printError(e); } message("\nChecking indexes.\n"); OCheckIndexTool indexTool = new OCheckIndexTool(); indexTool.setDatabase(currentDatabase); indexTool.setOutputListener(this); indexTool.setVerbose(true); indexTool.run(); }