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

controldb working

parent 6a1656fd
......@@ -22,6 +22,7 @@ public class BackupConfig {
private String controlDbUrl;
private String backupPath;
private String axonPath;
private List<BackupJob> jobs;
......
......@@ -22,17 +22,27 @@ public class ControlDBBackupService {
public void backup(BackupJob job) {
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()) {
try {
copy(dbDump, config.getJobs().get(0).getControlDbPath());
log.info("Created and copied db dump in {}", stopwatch);
} finally {
dbDump.delete();
}
copy(dbDump, pathToSave);
log.info("Created and copied db dump {} for {} to {} in {}", dbDump.getName(), job.getName(), pathToSave, stopwatch);
}
}
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 {
try {
backupService.run(job);
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) {
task.getStatus().put(job.getName(), ERROR);
log.error("Failed job {}", job.getName(), e);
......
......@@ -34,4 +34,13 @@ public class BackupTask {
return new BackupTask(id, jobs, statuses);
}
@Override
public String toString() {
return "BackupTask{" +
"id='" + id + '\'' +
", timestamp=" + timestamp +
", status=" + status +
'}';
}
}
......@@ -27,13 +27,14 @@ backup:
snapshotsUrl: /v1/backup/filenames?type=Snapshot
controlDbUrl: /v1/backup/createControlDbBackup
backupPath: ./backup/
axonPath: ./axon/
jobs:
- name: axondb1
axondbToken: dummy-token
axondbHost: http://127.0.0.1:8023/axondb
eventsPath: ./axon/axondb1/events/
snapshotsPath: ./axon/axondb1/events/
controlDbPath: ./axon/axondb1/controldb/
eventsPath: /events/
snapshotsPath: /events/
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