Add automated backup system with SQLite VACUUM
- Implement backup package with SQLite VACUUM INTO for safe backups - Add scheduler with configurable interval (default: 24h) - Add retention policy with automatic cleanup (default: 7 days) - Add optional gzip compression (~10x size reduction) - Add comprehensive tests for backup creation and cleanup - Integrate backup scheduler in main.go with graceful shutdown - Add backup configuration variables (BACKUP_ENABLED, BACKUP_INTERVAL, BACKUP_RETENTION_DAYS, BACKUP_PATH, BACKUP_COMPRESS) - Backups run automatically in background goroutine - Coverage: backup package 52.7%
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"apocapoc-api/internal/application/queries"
|
||||
"apocapoc-api/internal/i18n"
|
||||
"apocapoc-api/internal/infrastructure/auth"
|
||||
"apocapoc-api/internal/infrastructure/backup"
|
||||
"apocapoc-api/internal/infrastructure/config"
|
||||
"apocapoc-api/internal/infrastructure/crypto"
|
||||
"apocapoc-api/internal/infrastructure/email"
|
||||
@@ -55,6 +56,27 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
backupInterval, err := parseDuration(cfg.BackupInterval)
|
||||
if err != nil {
|
||||
logger.Fatal().Err(err).Msg("Invalid BACKUP_INTERVAL")
|
||||
}
|
||||
|
||||
backupRetentionDays, err := strconv.Atoi(cfg.BackupRetentionDays)
|
||||
if err != nil {
|
||||
logger.Fatal().Err(err).Msg("Invalid BACKUP_RETENTION_DAYS")
|
||||
}
|
||||
|
||||
backupScheduler := backup.NewScheduler(db.Conn(), backup.Config{
|
||||
Enabled: cfg.BackupEnabled == "true",
|
||||
Interval: backupInterval,
|
||||
RetentionDays: backupRetentionDays,
|
||||
Path: cfg.BackupPath,
|
||||
Compress: cfg.BackupCompress == "true",
|
||||
DatabasePath: cfg.DBPath,
|
||||
})
|
||||
backupScheduler.Start()
|
||||
defer backupScheduler.Stop()
|
||||
|
||||
jwtExpiryHours, err := parseJWTExpiry(cfg.JWTExpiry)
|
||||
if err != nil {
|
||||
logger.Fatal().Err(err).Msg("Invalid JWT_EXPIRY")
|
||||
|
||||
Reference in New Issue
Block a user