Skip to content

Commit

Permalink
Add new flag to force full backup creation (#165)
Browse files Browse the repository at this point in the history
- Adds new command option to --backup
- Calls BackupController with the new options value
- Updates tests
- Updates documentation

Resolves #164
{minor}

Signed-off-by: Esta Nagy <[email protected]>
  • Loading branch information
nagyesta authored Feb 27, 2024
1 parent 9d869d3 commit 4301f68
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions file-barj-job/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Execute the following command (assuming that your executable is named accordingl
java -jar build/libs/file-barj-job.jar \
--backup \
--config config.json \
--force-full-backup false \
--threads 2
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected void doBackup(final BackupProperties properties) throws IOException {
final var config = new ObjectMapper().reader().readValue(properties.getConfig().toFile(), BackupJobConfiguration.class);
final var startTimeMillis = System.currentTimeMillis();
log.info("Bootstrapping backup operation...");
new BackupController(config, false)
new BackupController(config, properties.isForceFullBackup())
.execute(properties.getThreads());
final var endTimeMillis = System.currentTimeMillis();
final var durationMillis = (endTimeMillis - startTimeMillis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public class BackupProperties {
@NonNull
private final Path config;
private final int threads;
private final boolean forceFullBackup;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class CliBackupParser extends GenericCliParser<BackupProperties> {

private static final String THREADS = "threads";
private static final String CONFIG = "config";
private static final String FORCE_FULL = "force-full-backup";

/**
* Creates a new {@link CliBackupParser} instance and sets the input arguments.
Expand All @@ -22,9 +23,11 @@ public CliBackupParser(final String[] args) {
super("java -jar file-barj-job.jar --" + Task.BACKUP.getCommand(), args, commandLine -> {
final var config = Path.of(commandLine.getOptionValue(CONFIG)).toAbsolutePath();
final var threads = Integer.parseInt(commandLine.getOptionValue(THREADS, "1"));
final var forceFull = Boolean.parseBoolean(commandLine.getOptionValue(FORCE_FULL, "false"));
return BackupProperties.builder()
.config(config)
.threads(threads)
.forceFullBackup(forceFull)
.build();
});
}
Expand All @@ -46,6 +49,14 @@ protected Options createOptions() {
.numberOfArgs(1)
.type(Path.class)
.argName("config_file")
.desc("Defines where the configuration file can be found.").build());
.desc("Defines where the configuration file can be found.").build())
.addOption(Option.builder()
.longOpt(FORCE_FULL)
.required(false)
.hasArg(true)
.numberOfArgs(1)
.type(Boolean.class)
.argName("boolean")
.desc("Forces the creation of a full backup if true.").build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ void testConstructorShouldCollectAndSetConfigurationValuesWhenAllArgsArePassed()
//given
final var configPath = Path.of("config.json");
final var threads = 2;
final var args = new String[] {"--config", configPath.toString(), "--threads", String.valueOf(threads)};
final var forceFull = true;
final var args = new String[] {
"--config", configPath.toString(),
"--threads", String.valueOf(threads),
"--force-full-backup", String.valueOf(forceFull)
};

//when
final var underTest = new CliBackupParser(args);
Expand All @@ -53,13 +58,15 @@ void testConstructorShouldCollectAndSetConfigurationValuesWhenAllArgsArePassed()
//then
Assertions.assertEquals(configPath.toAbsolutePath(), actual.getConfig());
Assertions.assertEquals(threads, actual.getThreads());
Assertions.assertEquals(forceFull, actual.isForceFullBackup());
}

@Test
void testConstructorShouldCollectAndSetConfigurationValuesWhenRequiredArgsArePassed() {
//given
final var configPath = Path.of("config.json");
final var threads = 1;
final var forceFull = false;
final var args = new String[] {"--config", configPath.toString()};

//when
Expand All @@ -69,5 +76,6 @@ void testConstructorShouldCollectAndSetConfigurationValuesWhenRequiredArgsArePas
//then
Assertions.assertEquals(configPath.toAbsolutePath(), actual.getConfig());
Assertions.assertEquals(threads, actual.getThreads());
Assertions.assertEquals(forceFull, actual.isForceFullBackup());
}
}

0 comments on commit 4301f68

Please sign in to comment.