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()))); } 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