-
Notifications
You must be signed in to change notification settings - Fork 325
Closed as not planned
Labels
bugSomething isn't workingSomething isn't workingstaleNo recent activity has been detected on this issue/PR and it will be closedNo recent activity has been detected on this issue/PR and it will be closed
Description
Description
The takeBackup() function writes directly to the final backup file path using pg_dump's --file parameter. If the backup fails midway (disk full, process killed, etc.), a partial backup file may be left behind. This is similar to bug #4718 which was fixed for export files by using atomic writes (write to temp file, then rename).
Severity
HIGH - File corruption / partial backups
Reproduction
- Start backup operation
- Kill process or fill disk during backup
- Partial
.dumpfile remains in backup directory - Subsequent operations may attempt to use corrupt backup file
Expected Behavior
Backup should use atomic write pattern: write to temp file, verify success, then rename to final location.
Test Reference
Test: TestTakeBackup_AtomicWrite in pkg/db/db_local/backup_test.go:150 (skipped)
Suggested Fix
// Write to temp file first
tempFile := filepath.Join(os.TempDir(), fmt.Sprintf("steampipe-backup-%d.tmp", time.Now().Unix()))
cmd := pgDumpCmd(ctx,
fmt.Sprintf("--file=%s", tempFile),
// ... other args
)
if err := cmd.Run(); err != nil {
os.Remove(tempFile)
return err
}
// Move to final location atomically
return os.Rename(tempFile, filepaths.DatabaseBackupFilePath())Related Code
pkg/db/db_local/backup.go:127-149
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingstaleNo recent activity has been detected on this issue/PR and it will be closedNo recent activity has been detected on this issue/PR and it will be closed