DatabaseOps { public static String backup(DatasetGraphSwitchable container) { checkSupportsAdmin(container); Path dbPath = container.getContainerPath(); Path backupDir = dbPath.resolve(BACKUPS_DIR); if ( ! Files.exists(backupDir) ) IOX.createDirectory(backupDir); DatasetGraph dsg = container; Pair<OutputStream, Path> x = openUniqueFileForWriting(backupDir, BACKUPS_FN, "nq.gz"); try (OutputStream out2 = x.getLeft(); OutputStream out1 = new GZIPOutputStream(out2, 8 * 1024); OutputStream out = new BufferedOutputStream(out1)) { Txn.executeRead(dsg, ()->RDFDataMgr.write(out, dsg, Lang.NQUADS)); } catch (IOException e) { throw IOX.exception(e); } return x.getRight().toString(); }  static String backup(DatasetGraphSwitchable container); static void compact(DatasetGraphSwitchable container); static final String dbPrefix; static final String SEP; }
@Test public void backup_1() { DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(dir); Txn.executeWrite(dsg, ()-> { dsg.add(quad2); dsg.add(quad1); }); String file1 = DatabaseMgr.backup(dsg); DatasetGraph dsg2 = RDFDataMgr.loadDatasetGraph(file1); Txn.executeRead(dsg, ()-> { assertTrue(dsg.contains(quad1)); assertEquals(2, dsg.getDefaultGraph().size()); assertTrue(dsg2.getDefaultGraph().isIsomorphicWith(dsg.getDefaultGraph())); }); String file2 = DatabaseMgr.backup(dsg); assertNotEquals(file1, file2); }