Commit 8d7fc706 authored by Evgeni Sladkovskii's avatar Evgeni Sladkovskii
Browse files

controldb working

parent 6a1656fd
...@@ -22,6 +22,7 @@ public class BackupConfig { ...@@ -22,6 +22,7 @@ public class BackupConfig {
private String controlDbUrl; private String controlDbUrl;
private String backupPath; private String backupPath;
private String axonPath;
private List<BackupJob> jobs; private List<BackupJob> jobs;
......
...@@ -22,17 +22,27 @@ public class ControlDBBackupService { ...@@ -22,17 +22,27 @@ public class ControlDBBackupService {
public void backup(BackupJob job) { public void backup(BackupJob job) {
Stopwatch stopwatch = createStarted(); Stopwatch stopwatch = createStarted();
File dbDump = new File(axonDbClient.createControlDbDump(job.getAxondbHost())); String dumpPath = axonDbClient.createControlDbDump(job.getAxondbHost());
File dbDump = dbDump(job, dumpPath);
String pathToSave = pathToSave(job);
if (dbDump.exists()) { if (dbDump.exists()) {
try { copy(dbDump, pathToSave);
copy(dbDump, config.getJobs().get(0).getControlDbPath()); log.info("Created and copied db dump {} for {} to {} in {}", dbDump.getName(), job.getName(), pathToSave, stopwatch);
log.info("Created and copied db dump in {}", stopwatch);
} finally {
dbDump.delete();
}
} }
}
private File dbDump(BackupJob job, String dumpPath) {
int fileStart = dumpPath.lastIndexOf('/');
if (fileStart < 0) throw new IllegalArgumentException("Wrong controldb dump path " + dumpPath);
String filename = dumpPath.substring(fileStart + 1);
String path = config.getAxonPath() + job.getName() + job.getControlDbPath() + filename;
return new File(path);
}
private String pathToSave(BackupJob job) {
return config.getBackupPath() + job.getName() + "/";
} }
} }
...@@ -39,7 +39,7 @@ public class BackupRunner { ...@@ -39,7 +39,7 @@ public class BackupRunner {
try { try {
backupService.run(job); backupService.run(job);
task.getStatus().put(job.getName(), DONE); task.getStatus().put(job.getName(), DONE);
log.info("Finished job {} in {}", job.getName(), sw); log.info("Finished job {} for {} in {}", job.getName(), task, sw);
} catch (RuntimeException e) { } catch (RuntimeException e) {
task.getStatus().put(job.getName(), ERROR); task.getStatus().put(job.getName(), ERROR);
log.error("Failed job {}", job.getName(), e); log.error("Failed job {}", job.getName(), e);
......
...@@ -34,4 +34,13 @@ public class BackupTask { ...@@ -34,4 +34,13 @@ public class BackupTask {
return new BackupTask(id, jobs, statuses); return new BackupTask(id, jobs, statuses);
} }
@Override
public String toString() {
return "BackupTask{" +
"id='" + id + '\'' +
", timestamp=" + timestamp +
", status=" + status +
'}';
}
} }
...@@ -27,13 +27,14 @@ backup: ...@@ -27,13 +27,14 @@ backup:
snapshotsUrl: /v1/backup/filenames?type=Snapshot snapshotsUrl: /v1/backup/filenames?type=Snapshot
controlDbUrl: /v1/backup/createControlDbBackup controlDbUrl: /v1/backup/createControlDbBackup
backupPath: ./backup/ backupPath: ./backup/
axonPath: ./axon/
jobs: jobs:
- name: axondb1 - name: axondb1
axondbToken: dummy-token axondbToken: dummy-token
axondbHost: http://127.0.0.1:8023/axondb axondbHost: http://127.0.0.1:8023/axondb
eventsPath: ./axon/axondb1/events/ eventsPath: /events/
snapshotsPath: ./axon/axondb1/events/ snapshotsPath: /events/
controlDbPath: ./axon/axondb1/controldb/ controlDbPath: /controldata/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment