diff --git a/modules/kubernetes/uptime-kuma/main.tf b/modules/kubernetes/uptime-kuma/main.tf index e55e9f1e..64b90644 100644 --- a/modules/kubernetes/uptime-kuma/main.tf +++ b/modules/kubernetes/uptime-kuma/main.tf @@ -108,3 +108,67 @@ module "ingress" { "gethomepage.dev/pod-selector" = "" } } + +locals { + namespace = "db-backups" + backup_pvc = "sqlite-backup-pvc" + sqlite_db_path = "/data/mydatabase.db" # Path to your SQLite DB in the source pod + backup_dir = "/backups" +} + + +# CronJob for daily SQLite backups +resource "kubernetes_cron_job_v1" "postgresql-backup" { + metadata { + name = "backup" + namespace = "uptime-kuma" + } + spec { + concurrency_policy = "Replace" + failed_jobs_history_limit = 5 + schedule = "0 */6 * * *" + # schedule = "* * * * *" + starting_deadline_seconds = 10 + successful_jobs_history_limit = 3 + job_template { + metadata {} + spec { + backoff_limit = 3 + ttl_seconds_after_finished = 10 + template { + metadata {} + spec { + container { + name = "backup" + image = "alpine/sqlite:latest" + command = ["/bin/sh", "-c", <<-EOT + set -e + export now=$(date +"%Y_%m_%d_%H_%M") + echo "Backing up SQLite database to /app/data/backup/backup_$now.sqlite" + sqlite3 /app/data/kuma.db ".backup /app/data/backup/backup_$now.sqlite" + echo "Backup completed. Deleting old backups..." + + # Rotate - delete last log file + cd /app/data/backup + find . -name "*.sqlite" -type f -mtime +7 -delete # 7 day retention of backups + echo "Old backups deleted." + EOT + ] + volume_mount { + name = "data" + mount_path = "/app/data" + } + } + volume { + name = "data" + nfs { + server = "10.0.10.15" + path = "/mnt/main/uptime-kuma" + } + } + } + } + } + } + } +}