add cronjob to periodically backup the immich postgres[ci skip]

This commit is contained in:
Viktor Barzin 2024-11-30 22:32:02 +00:00
parent d1d591bf94
commit d7c27afab5
No known key found for this signature in database
GPG key ID: 4056458DBDBF8863
2 changed files with 52 additions and 0 deletions

View file

@ -223,3 +223,55 @@ resource "kubernetes_ingress_v1" "photos" {
}
}
}
resource "kubernetes_cron_job_v1" "postgresql-backup" {
metadata {
name = "postgresql-backup"
namespace = "immich"
}
spec {
concurrency_policy = "Replace"
failed_jobs_history_limit = 5
schedule = "0 */6 * * *"
# schedule = "* * * * *"
starting_deadline_seconds = 10
successful_jobs_history_limit = 10
job_template {
metadata {}
spec {
backoff_limit = 3
ttl_seconds_after_finished = 10
template {
metadata {}
spec {
container {
name = "postgresql-backup"
image = "postgres:16.4-bullseye"
command = ["/bin/sh", "-c", <<-EOT
export now=$(date +"%Y_%m_%d_%H_%M")
PGPASSWORD=${var.postgresql_password} pg_dumpall -h immich-postgresql -U immich > /backup/dump_$now.sql
# Rotate - delete last log file
cd /backup
find . -name "dump_*.sql" -type f -mtime +14 -delete # 14 day retention of backups
EOT
]
volume_mount {
name = "postgresql-backup"
mount_path = "/backup"
}
}
volume {
name = "postgresql-backup"
nfs {
path = "/mnt/main/immich/data-immich-postgresql"
server = "10.0.10.15"
}
}
}
}
}
}
}
}

Binary file not shown.