Skip to content

Commit

Permalink
Moved automatic backup cfg to file automatic-backup.json (Issue #5329)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Nov 18, 2015
1 parent 6a2490f commit 6f9fabb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
18 changes: 2 additions & 16 deletions graphdb/config/orientdb-server-config.xml
Expand Up @@ -48,21 +48,8 @@
<handler class="com.orientechnologies.orient.server.handler.OAutomaticBackup">
<parameters>
<parameter name="enabled" value="false"/>
<!-- CAN BE: FULL_BACKUP, INCREMENTAL_BACKUP, EXPORT -->
<parameter name="mode" value="FULL_BACKUP"/>
<!-- OPTION FOR EXPORT -->
<parameter name="exportOptions" value=""/>
<parameter name="delay" value="4h"/>
<parameter name="firstTime" value="23:00:00"/>
<parameter name="target.directory" value="backup"/>
<parameter name="target.fileName" value="${DBNAME}-${DATE:yyyyMMddHHmmss}.zip"/>
<parameter name="compressionLevel" value="9"/>
<parameter name="bufferSize" value="1048576"/>
<!--${DBNAME} AND ${DATE:} VARIABLES ARE SUPPORTED -->
<parameter name="db.include" value=""/>
<!-- DEFAULT: NO ONE, THAT MEANS ALL DATABASES. USE COMMA TO SEPARATE MULTIPLE DATABASE NAMES -->
<parameter name="db.exclude" value=""/>
<!-- USE COMMA TO SEPARATE MULTIPLE DATABASE NAMES -->
<!-- LOCATION OF JSON CONFIGURATION FILE -->
<parameter name="config" value="${ORIENTDB_HOME}/config/automatic-backup.json"/>
</parameters>
</handler>
<!-- SERVER SIDE SCRIPT INTERPRETER. WARNING, THIS CAN BE A SECURITY HOLE BECAUSE MALICIOUS CODE COULD BE INJECTED.
Expand Down Expand Up @@ -94,7 +81,6 @@
</parameters>
</handler>


</handlers>
<network>
<sockets>
Expand Down
11 changes: 11 additions & 0 deletions server/config/automatic-backup.json
@@ -0,0 +1,11 @@
{
"enabled": true,
"mode": "FULL_BACKUP",
"exportOptions": "",
"delay": "4h",
"firstTime": "23:00:00",
"targetDirectory": "backup",
"targetFileName": "${DBNAME}-${DATE:yyyyMMddHHmmss}.zip",
"compressionLevel": 9,
"bufferSize": 1048576
}
Expand Up @@ -69,7 +69,7 @@ public enum MODE {
FULL_BACKUP, INCREMENTAL_BACKUP, EXPORT
}

private String configFile = "${ORIENTDB_HOME}/config/backup.json";
private String configFile = "${ORIENTDB_HOME}/config/automatic-backup.json";
private Date firstTime = null;
private long delay = -1;
private int bufferSize = 1048576;
Expand All @@ -96,7 +96,7 @@ public void config(final OServer iServer, final OServerParameterConfiguration[]
final File f = new File(OSystemVariableResolver.resolveSystemVariables(configFile));
if (!f.exists())
throw new OConfigurationException(
"Automatic backup configuration file '" + configFile + "' not found. Automatic Backup will be disabled");
"Automatic Backup configuration file '" + configFile + "' not found. Automatic Backup will be disabled");
break;

// LEGACY <v2.2: CONVERT ALL SETTINGS IN JSON
Expand All @@ -115,7 +115,7 @@ else if (param.name.equalsIgnoreCase("db.exclude") && param.value.trim().length(
else if (param.name.equalsIgnoreCase("target.fileName"))
configuration.field("targetFileName", param.value);
else if (param.name.equalsIgnoreCase("bufferSize"))
configuration.field("bufferSize", param.value);
configuration.field("bufferSize", Integer.parseInt(param.value));
else if (param.name.equalsIgnoreCase("compressionLevel"))
configuration.field("compressionLevel", Integer.parseInt(param.value));
else if (param.name.equalsIgnoreCase("mode"))
Expand All @@ -140,7 +140,7 @@ else if (param.name.equalsIgnoreCase("exportOptions"))
// CREATE BACKUP FOLDER(S) IF ANY
filePath.mkdirs();

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

final TimerTask timerTask = new TimerTask() {
Expand Down Expand Up @@ -231,20 +231,22 @@ private void configure() {
configuration = new ODocument().fromJSON(configurationContent);
} catch (IOException e) {
OException.wrapException(new OConfigurationException(
"Cannot load Automatic backup configuration file '" + configFile + "'. Automatic Backup will be disabled"), e);
"Cannot load Automatic Backup configuration file '" + configFile + "'. Automatic Backup will be disabled"), e);
}

} else {
// AUTO CONVERT XML CONFIGURATION (<v2.2) TO JSON FILE
try {
f.getParentFile().mkdirs();
f.createNewFile();
OIOUtils.writeFile(f, configuration.toJSON());
OIOUtils.writeFile(f, configuration.toJSON("prettyPrint"));

OLogManager.instance().info(this, "Automatic Backup: migrated configuration to file '%s'", f);
} catch (IOException e) {
OException
.wrapException(
new OConfigurationException(
"Cannot create Automatic backup configuration file '" + configFile + "'. Automatic Backup will be disabled"),
"Cannot create Automatic Backup configuration file '" + configFile + "'. Automatic Backup will be disabled"),
e);
}
}
Expand Down

0 comments on commit 6f9fabb

Please sign in to comment.