Skip to content

Commit

Permalink
Issue #8245 has been fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii0lomakin committed May 3, 2018
1 parent 865edc4 commit 5ebbd80
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWriteAheadLog;

import java.io.*;
import java.nio.channels.FileChannel;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public Object execute(final ODistributedRequestId requestId, final OServer iServ
backupFile.getParentFile().mkdirs();
backupFile.createNewFile();

final FileOutputStream fileOutputStream = new FileOutputStream(backupFile);
final File resultedBackup = backupFile;
final FileOutputStream fileOutputStream = new FileOutputStream(resultedBackup);

final File completedFile = new File(backupFile.getAbsolutePath() + ".completed");
if (completedFile.exists())
Expand Down Expand Up @@ -142,6 +143,7 @@ public void onMessage(String iText) {

} catch (Exception e) {
OLogManager.instance().error(this, "Cannot execute backup of database '%s' for deploy database", e, databaseName);
resultedBackup.delete();
} finally {
try {
fileOutputStream.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.metadata.security.OSecurityNull;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber;
import com.orientechnologies.orient.server.OServer;
import com.orientechnologies.orient.server.config.OServerParameterConfiguration;
import com.orientechnologies.orient.server.plugin.OServerPluginAbstract;
Expand Down Expand Up @@ -78,11 +79,11 @@ public enum MODE {
private MODE mode = MODE.FULL_BACKUP;
private String exportOptions;

private String targetDirectory = "backup";
private String targetFileName;
private String targetDirectory = "backup";
private String targetFileName;
private Set<String> includeDatabases = new HashSet<String>();
private Set<String> excludeDatabases = new HashSet<String>();
private OServer serverInstance;
private OServer serverInstance;

@Override
public void config(final OServer iServer, final OServerParameterConfiguration[] iParams) {
Expand Down Expand Up @@ -128,7 +129,7 @@ else if (param.name.equalsIgnoreCase("exportOptions"))
// LOAD CFG FROM JSON FILE. THIS FILE, IF SPECIFIED, OVERWRITE DEFAULT AND XML SETTINGS
configure();

if(enabled) {
if (enabled) {
if (delay <= 0)
throw new OConfigurationException("Cannot find mandatory parameter 'delay'");
if (!targetDirectory.endsWith("/"))
Expand All @@ -143,8 +144,8 @@ else if (param.name.equalsIgnoreCase("exportOptions"))
filePath.mkdirs();

OLogManager.instance()
.info(this, "Automatic Backup plugin installed and active: delay=%dms, firstTime=%s, targetDirectory=%s", delay, firstTime,
targetDirectory);
.info(this, "Automatic Backup plugin installed and active: delay=%dms, firstTime=%s, targetDirectory=%s", delay,
firstTime, targetDirectory);

final TimerTask timerTask = new TimerTask() {
@Override
Expand Down Expand Up @@ -214,7 +215,8 @@ public void run() {

} catch (Exception e) {

OLogManager.instance().error(this, "Error on backup of database '" + dbURL + "' to directory: " + targetDirectory, e);
OLogManager.instance()
.error(this, "Error on backup of database '" + dbURL + "' to directory: " + targetDirectory, e);
errors++;

} finally {
Expand All @@ -232,9 +234,8 @@ public void run() {
else
Orient.instance().scheduleTask(timerTask, firstTime, delay);

}else {
OLogManager.instance()
.info(this, "Automatic Backup plugin is disabled");
} else {
OLogManager.instance().info(this, "Automatic Backup plugin is disabled");
}
}

Expand Down Expand Up @@ -348,17 +349,29 @@ protected void incrementalBackupDatabase(final String dbURL, String iPath, final
protected void fullBackupDatabase(final String dbURL, final String iPath, final ODatabaseDocumentInternal db) throws IOException {
OLogManager.instance().info(this, "AutomaticBackup: executing full backup of database '%s' to %s", dbURL, iPath);

final FileOutputStream fileOutputStream = new FileOutputStream(iPath);
final File backupFile = new File(iPath);
try {
db.backup(fileOutputStream, null, null, new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
OLogManager.instance().info(this, iText);
}
}, compressionLevel, bufferSize);
} finally {
fileOutputStream.close();
final FileOutputStream fileOutputStream = new FileOutputStream(backupFile);
try {
db.backup(fileOutputStream, null, null, new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
OLogManager.instance().info(this, iText);
}
}, compressionLevel, bufferSize);
} finally {
fileOutputStream.close();
}
} catch (IOException e) {
OLogManager.instance().errorNoDb(this, "Error during backup, backup file %s will be deleted", e, backupFile);
backupFile.delete();
throw e;
} catch (RuntimeException e) {
OLogManager.instance().errorNoDb(this, "Error during backup, backup file %s will be deleted", e, backupFile);
backupFile.delete();
throw e;
}

}

protected void exportDatabase(final String dbURL, final String iPath, final ODatabaseDocumentInternal db) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class OConsoleDatabaseApp extends OrientConsole implements OCommandOutput
private int lastPercentStep;
private String currentDatabaseUserName;
private String currentDatabaseUserPassword;
private int maxMultiValueEntries = 10;
private int maxMultiValueEntries = 10;

public OConsoleDatabaseApp(final String[] args) {
super(args);
Expand Down Expand Up @@ -2296,6 +2296,12 @@ else if (parName.equalsIgnoreCase("compressionLevel"))
if (f.exists())
f.delete();
throw e;
} catch (IOException e) {
fos.close();
File f = new File(fileName);
if (f.exists())
f.delete();
throw e;
}
}
} catch (ODatabaseExportException e) {
Expand Down

0 comments on commit 5ebbd80

Please sign in to comment.