wal-g icon indicating copy to clipboard operation
wal-g copied to clipboard

Fix backup ordering to use creation time instead of modification time (Issue #694)

Open NikolayS opened this issue 4 weeks ago • 1 comments

This PR fixes issue #694 where WAL-G relies on storage modification time for backup ordering, which leads to incorrect results when, for example, backups are moved between storage tiers (updating modification times).

  • backup-fetch LATEST now uses creation time from metadata
  • Falls back gracefully when metadata unavailable
  • backup-list --detail already shows creation time (no changes needed)

Before (Bug):

  • Backup A created at 10:00, uploaded at 10:05
  • Backup B created at 12:00, uploaded at 12:05
  • Backup A re-uploaded at 13:00 (modification time updated)
  • $ wal-g backup-fetch LATEST -- incorrectly selects Backup A (has latest modification time 13:00)

After (Fixed):

  • $ wal-g backup-fetch LATEST -- correctly selects Backup B (has latest creation time 12:00)

NikolayS avatar Dec 02 '25 04:12 NikolayS

Local testing -- done,

ran standalone tests that verify the core logic without requiring external dependencies:

Test Suite 1: Core Selection Logic (5/5 passed)

Test 1: Select by creation time (metadata available) ✓ PASS: Selected backup_new (by creation time)

Test 2: Fallback to modification time (no metadata) ✓ PASS: Selected backup_2 (by modification time)

Test 3: Mixed scenario (partial metadata) ✓ PASS: Selected backup_A (by creation time)

Test 4: Issue #694 bug scenario reproduction ✓ PASS: Selected node_B_backup (by creation time)

Test 5: Empty backups list ✓ PASS: Correctly returned NO_BACKUP_FOUND

Test Suite 2: Sorting Logic (3/3 passed)

Test 1: Sort by creation time ✓ PASS: Sorted order: [backup_A backup_B backup_C]

Test 2: Issue #694 - Re-uploaded backup scenario ✓ PASS (creation time): Sorted order: [backup_oldest backup_middle backup_newest] Note (mod time - old behavior): Would have sorted as: [backup_middle backup_newest backup_oldest] This is WRONG because backup_oldest appears last due to re-upload!

Test 3: LATEST backup selection from sorted list ✓ PASS: LATEST is backup_C (correct - newest by creation time)

NikolayS avatar Dec 02 '25 04:12 NikolayS