Skip to content

Synchronize gpbackup history with the standby coordinator. - #111

Merged
tuhaihe merged 19 commits into
apache:mainfrom
woblerr:sync_standby
Aug 13, 2026
Merged

Synchronize gpbackup history with the standby coordinator.#111
tuhaihe merged 19 commits into
apache:mainfrom
woblerr:sync_standby

Conversation

@woblerr

@woblerr woblerr commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

closes: #90

gpbackup_history.db is stored on the active primary coordinator and is not automatically available on the standby. After a failover, the promoted coordinator may have missing or outdated backup history, which affects backup discovery and management.

This change keeps the cluster history database synchronized with an available standby coordinator:

  • gpbackup automatically synchronizes history after a successful backup.
  • gpBackMan automatically synchronizes history after commands that delete backups or clean history.
  • The new gpbackman history-sync command allows synchronization to be started manually.
  • Automatic synchronization is best-effort: failures are reported as warnings and do not change the result of a successful primary command.
  • Automatic synchronization can be disabled with --no-history-sync-standby.

Only gpbackup_history.db is synchronized. Backup data, reports, and other backup artifacts are not included.

Unit and end-to-end coverage were added, and the related user documentation was updated.

@woblerr
woblerr marked this pull request as ready for review August 7, 2026 21:28
@woblerr

woblerr commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

PR is ready for review.

@tuhaihe
tuhaihe requested a review from MisterRaindrop August 8, 2026 01:22

@MisterRaindrop MisterRaindrop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found two issues in the standby history synchronization path.

Comment thread backup/history_standby_sync.go Outdated
Comment thread backup/history_standby_sync.go
Expose --history-sync-standby-timeout as integer seconds in gpbackup and sync-capable gpBackMan commands. Use int to match existing CLI conventions, default to 300 seconds, and cap values at one day to catch accidental settings without excluding slow transfers.

Create one context deadline after SQLite snapshot validation and share its remaining budget across rsync and remote install. This keeps discovery and local snapshot work outside the limit and prevents each transport stage from restarting the timeout.

Run rsync and ssh with CommandContext and BatchMode so stalled processes are terminated without waiting for interactive authentication.

Use an independent 120-second context for failure cleanup so remote temporary files can still be removed after the transport deadline expires while cleanup remains bounded. Preserve both primary and cleanup errors and keep automatic synchronization best-effort while history-sync stays strict.
Pass remote paths with rsync's `-s` option so shell metacharacters are not interpreted by the remote shell, and document the resulting rsync 3.0.0 requirement.
When rsync or ssh succeeds and the context deadline fires immediately after, the successful transfer was incorrectly treated as a timeout. Only prefer ctx.Err() when the command itself returned an error.
@woblerr

woblerr commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator Author

The following changes were made based on the review:

  • Added --history-sync-standby-timeout to gpbackup and sync-capable gpBackMan commands. The option accepts integer seconds from 1 to 86400 and defaults to 300. A single deadline starts after VACUUM INTO and PRAGMA quick_check, then shares its remaining budget between rsync and remote install. If either transport stage fails, remote temporary-file cleanup runs with an independent 120-second timeout, including when the main deadline has already expired.
  • Added context cancellation and SSH batch mode to prevent stalled transport commands from blocking backup cleanup.
  • Protected remote rsync paths with -s and documented rsync 3.0.0 as the minimum supported version.
  • Fixed context error handling so successful rsync and SSH commands are not reported as timed out.

@MisterRaindrop MisterRaindrop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tuhaihe
tuhaihe merged commit 6d61e7e into apache:main Aug 13, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Sync gpbackup_history.db to standby coordinator after backup.

3 participants