A Java-based automated backup tool that creates compressed ZIP archives of directories with support for both one-time and scheduled backups.
- Create compressed ZIP backups of directories
- One-time backup execution
- Scheduled automatic backups (cron-like)
- Command-line interface
- Easy-to-use startup scripts
- Clean Domain-Driven Design architecture
- Java 21 or higher
- Maven 3.6 or higher
mvn clean packageThis will create an executable JAR file at target/backup-tool-1.0-SNAPSHOT.jar
# Make the script executable
chmod +x backup.sh
# One-time backup
./backup.sh /path/to/source /path/to/destination
# Scheduled backup (every 5 minutes for testing)
./backup.sh /path/to/source /path/to/destination 5
# Or edit the script to set default values and run
./backup.sh# One-time backup
backup.bat C:\path\to\source C:\path\to\destination
# Scheduled backup (every 5 minutes for testing)
backup.bat C:\path\to\source C:\path\to\destination 5
# Or edit the script to set default values and run
backup.bat# One-time backup
java -jar target/backup-tool-1.0-SNAPSHOT.jar /path/to/source /path/to/destination
# Scheduled backup (every 5 minutes)
java -jar target/backup-tool-1.0-SNAPSHOT.jar /path/to/source /path/to/destination 5- source (required) - The directory you want to backup
- destination (required) - The directory where backups will be stored
- interval_minutes (optional) - If provided, runs backup every N minutes. If omitted, runs once and exits.
# Backup your Documents folder to a Backups directory
java -jar target/backup-tool-1.0-SNAPSHOT.jar ~/Documents ~/Backups# Run backup every 5 minutes (good for testing)
java -jar target/backup-tool-1.0-SNAPSHOT.jar ~/Documents ~/Backups 5# Run backup every 60 minutes
java -jar target/backup-tool-1.0-SNAPSHOT.jar ~/Documents ~/Backups 60# Run backup every 24 hours (1440 minutes)
java -jar target/backup-tool-1.0-SNAPSHOT.jar ~/Documents ~/Backups 1440- The tool creates a ZIP archive of the source directory
- The archive is stored in the destination directory with a timestamp
- Format:
backup-<timestamp>.zip - For scheduled mode, the process runs in the background at the specified interval
- Press Ctrl+C to stop the scheduled backup service
backup-tool/
├── src/main/java/io/github/devcavin/
│ ├── App.java # Main application entry point
│ ├── application/usecase/ # Use case layer
│ │ ├── CreateBackupJobUseCase.java
├── ListArchiveUseCase.java
│ │ ├── RunBackupJobUseCase.java
│ │ └── ListBackupJobsUseCase.java
│ ├── domain/ # Domain layer
│ │ ├── entity/
│ │ │ ├── BackupJob.java
│ │ │ └── Archive.java
│ │ ├── repository/
│ │ │ ├── BackupJobRepository.java
│ │ │ └── ArchiveRepository.java
│ │ ├── service/
│ │ │ ├── BackupService.java
│ │ │ ├── ArchiveCreator.java
│ │ │ └── ArchiveStorage.java
│ │ ├── valueobject/
│ │ │ ├── BackupName.java
│ │ │ ├── SourcePath.java
│ │ │ └── DestinationPath.java
│ │ └── enums/
│ │ └── BackupStatus.java
│ └── infrastructure/ # Infrastructure layer
│ ├── archive/local/
│ │ ├── LocalArchiveCreator.java
│ │ └── LocalArchiveStorage.java
│ ├── repository/memory/
│ │ ├── InMemoryBackupJobRepository.java
│ │ └── InMemoryArchiveRepository.java
│ └── scheduler/
│ └── ScheduledBackupService.java
├── backup.sh # Linux/Mac startup script
├── backup.bat # Windows startup script
├── pom.xml
└── README.md
Edit the startup scripts to set your preferred default values:
backup.sh (Linux/Mac):
DEFAULT_SOURCE="/home/user/documents"
DEFAULT_DESTINATION="/home/user/backups"
DEFAULT_INTERVAL="" # or set to number for scheduledbackup.bat (Windows):
set DEFAULT_SOURCE=C:\Users\%USERNAME%\Documents
set DEFAULT_DESTINATION=C:\Users\%USERNAME%\Backups
set DEFAULT_INTERVAL=Create a service file /etc/systemd/system/backup-tool.service:
[Unit]
Description=Automated Backup Service
After=network.target
[Service]
Type=simple
User=yourusername
WorkingDirectory=/path/to/backup-tool
ExecStart=/usr/bin/java -jar /path/to/backup-tool/target/backup-tool-1.0-SNAPSHOT.jar /source /destination 60
Restart=always
[Install]
WantedBy=multi-user.targetThen:
sudo systemctl daemon-reload
sudo systemctl enable backup-tool
sudo systemctl start backup-tool- Open Task Scheduler
- Create Basic Task
- Set trigger to "When the computer starts"
- Action: Start a program
- Program:
javaw.exe - Arguments:
-jar C:\path\to\backup-tool.jar C:\source C:\destination 60
MIT License
Pull requests are welcome!