From cd8abbf7b42e19b3c5d543c2a1f664300ff5fb20 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Tue, 10 Nov 2026 11:00:05 +0100 Subject: [PATCH 1/2] fix(cleanup): delete failed database backup records after the retention days Backup retention removes only successful runs, so failed runs stayed in scheduled_database_backup_executions forever. A failed run has no local file and no S3 copy, so the daily database cleanup can delete its record. Co-Authored-By: Claude Opus 5.5 --- .changes/kept-the-records-of-failed-database.md | 6 ++++++ app/Console/Commands/CleanupDatabase.php | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 .changes/kept-the-records-of-failed-database.md diff --git a/.changes/kept-the-records-of-failed-database.md b/.changes/kept-the-records-of-failed-database.md new file mode 100644 index 0000000000..a3aefab4c9 --- /dev/null +++ b/.changes/kept-the-records-of-failed-database.md @@ -0,0 +1,6 @@ +--- +type: fixed +--- +Kept the records of failed database backups forever + +- The daily database cleanup deletes failed database backups that are older than 60 days diff --git a/app/Console/Commands/CleanupDatabase.php b/app/Console/Commands/CleanupDatabase.php index e3bdee090f..ffb4c7df06 100644 --- a/app/Console/Commands/CleanupDatabase.php +++ b/app/Console/Commands/CleanupDatabase.php @@ -48,6 +48,10 @@ class CleanupDatabase extends Command $this->cleanupTable('scheduled_task_executions', 'created_at', now()->subDays($keep_days)); + // Backup retention removes only successful runs. A failed run has no file, so only its record is left. + $this->cleanupTable('scheduled_database_backup_executions', 'created_at', now()->subDays($keep_days), fn (Builder $query) => $query + ->where('status', 'failed')); + $this->cleanupTable('github_runner_executions', 'created_at', now()->subDays($keep_days), fn (Builder $query) => $query ->whereNotIn('status', array_map(fn (GithubRunnerStatus $status): string => $status->value, GithubRunnerStatus::active()))); } From 1a71543f6a3c8adb6dc5f2c6ec9aa9c35f67e5f8 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Tue, 10 Nov 2026 11:00:05 +0100 Subject: [PATCH 2/2] fix(scripts): restore Coolify Cloud backups with orphan S3 replica rows The Coolify Cloud backup leaves out the rows of scheduled_database_backup_executions but keeps database_backup_s3_replicas, so pg_restore failed when it added db_backup_s3_replicas_execution_fk. Restore by section and delete the orphan replica rows before post-data. Co-Authored-By: Claude Opus 5.5 --- scripts/restore-backup-vm.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/scripts/restore-backup-vm.sh b/scripts/restore-backup-vm.sh index c60d6d6b8b..8e3abbe700 100755 --- a/scripts/restore-backup-vm.sh +++ b/scripts/restore-backup-vm.sh @@ -308,7 +308,27 @@ echo "SELF_HOSTED=${SELF_HOSTED}" >>.env docker exec coolify-db psql -q -U coolify -d postgres -v ON_ERROR_STOP=1 \ -c 'DROP DATABASE coolify WITH (FORCE)' -c 'CREATE DATABASE coolify OWNER coolify' echo "Running pg_restore..." -docker exec -i coolify-db pg_restore --exit-on-error --no-acl --no-owner -U coolify -d coolify