File BaRJ (File Backup and Restore Java) is a multi-platform backup utility for files. It is intended to be a highly configurable tool that can create secure backups of preconfigured files and folders and can be easily scheduled.
This module gives a higher level API implementing complex backup operations using the File BaRJ Cargo format at its core.
Warning
File BaRJ is a free tool that is provided "as is", without warranty of any kind. It might be the perfect tool you need, or leave you with gigabytes of encrypted hot mess instead of your precious data. By using it, you accept the risk of data loss (among others).
<dependency>
<groupId>com.github.nagyesta.file-barj</groupId>
<artifactId>file-barj-core</artifactId>
<version>RELEASE</version>
</dependency>
implementation("com.github.nagyesta.file-barj:file-barj-core:+")
//configuring the backup job
final var configuration = BackupJobConfiguration.builder()
.backupType(BackupType.FULL)
.fileNamePrefix("test")
.compression(CompressionAlgorithm.BZIP2)
.hashAlgorithm(HashAlgorithm.SHA256)
.duplicateStrategy(DuplicateHandlingStrategy.KEEP_EACH)
.destinationDirectory(Path.of("/tmp/backup"))
.sources(Set.of(BackupSource.builder()
.path(BackupPath.of(Path.of("/source/dir")))
.build()))
.chunkSizeMebibyte(1)
.encryptionKey(null)
.build();
final var backupParameters = BackupParameters.builder()
.job(configuration)
.forceFull(false)
.build();
final var backupController = new BackupController(backupParameters);
//executing the backup
backupController.execute(1);
final var mergeParameters = MergeParameters.builder()
.backupDirectory(Path.of("/tmp/backup"))
.fileNamePrefix("prefix")
.kek(null) //optional key encryption key
.rangeStartEpochSeconds(123L) //Backup start epoch seconds for the first file of the range (inclusive)
.rangeEndEpochSeconds(234L) //Backup start epoch seconds for the last file of the range (inclusive)
.build();
final var mergeController = new MergeController(mergeParameters);
mergeController.execute(false);
//configuring the restore job
final var restoreTargets = new RestoreTargets(
Set.of(new RestoreTarget(BackupPath.of("/source/dir"), Path.of("/tmp/restore/to"))));
final var restoreTask = RestoreTask.builder()
.restoreTargets(restoreTargets)
.dryRun(true)
.threads(1)
.deleteFilesNotInBackup(false)
.includedPath(BackupPath.of("/source/dir")) //optional path filter
.permissionComparisonStrategy(PermissionComparisonStrategy.STRICT) //optional
.build();
final var restoreParameters = RestoreParameters.builder()
.backupDirectory(Path.of("/tmp/backup"))
.fileNamePrefix("test")
.kek(null)
.atPointInTime(123456L)
.build();
final var restoreController = new RestoreController(restoreParameters);
//executing the restore
restoreController.execute(restoreTask);
//configuring the inspection job
final var backupDir = Path.of("/backup/directory");
final var outputFile = Path.of("/backup/directory");
final var inspectParameters = InspectParameters.builder()
.backupDirectory(backupDir)
.fileNamePrefix("file-prefix")
.kek(null)
.build();
final var controller = new IncrementInspectionController(inspectParameters);
//list the summary of the available increments
controller.inspectIncrements(System.out);
//list the contents of the latest backup increment
controller.inspectContent(Long.MAX_VALUE, outputFile);
//configuring the deletion job
final var backupDir = Path.of("/backup/directory");
final var outputFile = Path.of("/backup/directory");
final var deletionParameters = IncrementDeletionParameters.builder()
.backupDirectory(backupDir)
.fileNamePrefix("file-prefix")
.kek(null)
.build();
final var controller = new IncrementDeletionController(deletionParameters);
//Delete all backup increments:
// - starting with the one created at 123456
// - until (exclusive) the next full backup
controller.deleteIncrementsUntilNextFullBackupAfter(123456L);
Please read more about the BaRJ backup jobs here.