mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-13 08:13:36 -04:00
fix: delete failed database backup records and restore Cloud backups with orphan replica rows (#12507)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
@@ -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())));
|
||||
}
|
||||
|
||||
@@ -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 </root/coolify-backup.dmp
|
||||
restore_section() {
|
||||
docker exec -i coolify-db pg_restore --exit-on-error --no-acl --no-owner --section="$1" -U coolify -d coolify </root/coolify-backup.dmp
|
||||
}
|
||||
restore_section pre-data
|
||||
restore_section data
|
||||
# Coolify Cloud backups leave out the rows of log and execution tables, such as
|
||||
# scheduled_database_backup_executions. Rows that point to them must go before
|
||||
# post-data adds the foreign keys.
|
||||
docker exec coolify-db psql -q -U coolify -d coolify -v ON_ERROR_STOP=1 -c "
|
||||
DO \$\$
|
||||
DECLARE deleted bigint;
|
||||
BEGIN
|
||||
IF to_regclass('public.database_backup_s3_replicas') IS NOT NULL THEN
|
||||
DELETE FROM database_backup_s3_replicas r
|
||||
WHERE NOT EXISTS (SELECT 1 FROM scheduled_database_backup_executions e WHERE e.id = r.execution_id);
|
||||
GET DIAGNOSTICS deleted = ROW_COUNT;
|
||||
RAISE NOTICE 'Deleted % database_backup_s3_replicas rows without an execution', deleted;
|
||||
END IF;
|
||||
END
|
||||
\$\$;"
|
||||
restore_section post-data
|
||||
|
||||
# Drop cached data of the fresh installation.
|
||||
REDIS_PASSWORD=$(grep '^REDIS_PASSWORD=' .env | cut -d= -f2-)
|
||||
|
||||
Reference in New Issue
Block a user