This guide shows how to perform
backup and restore operations on
SAP HANA Express and manage them from a
Spring Boot application.
1. Backup in SAP HANA
Run SQL for a full backup:
BACKUP DATA USING FILE ('backup_2025');
This creates a backup file in the configured HANA backup directory.
2. Restore in SAP HANA
To restore from a backup:
RECOVER DATA USING FILE ('backup_2025') CLEAR LOG;
This restores the database to the state at the time of the backup.
3. Automating Backup with Spring Boot
Create a service to trigger SQL commands via JDBC.
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@Service
public class BackupService {
private final JdbcTemplate jdbc;
public BackupService(JdbcTemplate jdbc) {
this.jdbc = jdbc;
}
public void backup() {
jdbc.execute("BACKUP DATA USING FILE ('backup_spring')");
}
public void restore() {
jdbc.execute("RECOVER DATA USING FILE ('backup_spring') CLEAR LOG");
}
}
4. Expose REST Endpoints
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/db")
public class BackupController {
private final BackupService service;
public BackupController(BackupService service) {
this.service = service;
}
@PostMapping("/backup")
public String backup() {
service.backup();
return "Backup completed!";
}
@PostMapping("/restore")
public String restore() {
service.restore();
return "Restore completed!";
}
}
5. Test the Endpoints
Run Spring Boot and call:
POST /db/backup → creates backup file
POST /db/restore → restores from backup
6. Best Practices
- Store backups in a secure external location.
- Schedule backups using Spring Scheduler or a cron job.
- Test restore regularly to ensure reliability.
image quote pre code