Documentation
¶
Index ¶
- func CleanupOldWALFiles(archiveDir string, maxAge time.Duration) (int, error)
- func RestoreToPoint(ctx context.Context, config PITRConfig, runner *restic.Runner, ...) error
- func RunBaseBackup(ctx context.Context, cfg PITRConfig) (string, error)
- func SetupPostgresWAL(cfg PITRConfig) (configLines string, archiveDir string, err error)
- func StartWALUploader(ctx context.Context, config PITRConfig, runner *restic.Runner, ...)
- func UploadBaseBackup(ctx context.Context, runner *restic.Runner, backupDir string, ...) (string, error)
- func VerifyRecovery(ctx context.Context, config PITRConfig) error
- type PITRConfig
- type WALStatus
- type WALUploader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanupOldWALFiles ¶
CleanupOldWALFiles removes WAL files older than the specified duration.
func RestoreToPoint ¶ added in v0.10.0
func RestoreToPoint(ctx context.Context, config PITRConfig, runner *restic.Runner, targetTime time.Time, restoreDir string) error
RestoreToPoint performs a point-in-time recovery by:
- Finding the most recent base backup before targetTime via restic snapshots
- Restoring the base backup from restic to restoreDir
- Restoring WAL files from restic to the WAL archive directory
- Configuring PostgreSQL recovery settings for the target time
- Starting PostgreSQL with recovery mode
The runner should be the same restic runner used for PITR backups (base + WAL).
func RunBaseBackup ¶
func RunBaseBackup(ctx context.Context, cfg PITRConfig) (string, error)
RunBaseBackup executes pg_basebackup and stores the result.
func SetupPostgresWAL ¶
func SetupPostgresWAL(cfg PITRConfig) (configLines string, archiveDir string, err error)
SetupPostgresWAL generates the postgresql.conf changes needed for WAL archiving. Returns the config lines to add and the archive directory path.
func StartWALUploader ¶ added in v0.10.0
func StartWALUploader(ctx context.Context, config PITRConfig, runner *restic.Runner, interval time.Duration)
StartWALUploader watches the WAL archive directory and uploads new files to S3 via restic. It blocks until ctx is cancelled.
func UploadBaseBackup ¶ added in v0.10.0
func UploadBaseBackup(ctx context.Context, runner *restic.Runner, backupDir string, config PITRConfig) (string, error)
UploadBaseBackup uploads a base backup directory to S3 via restic. The backup is tagged with "pitr-base" for easy identification.
func VerifyRecovery ¶ added in v0.10.0
func VerifyRecovery(ctx context.Context, config PITRConfig) error
VerifyRecovery connects to PostgreSQL and checks that it is running and accepting connections after recovery. Returns nil if healthy.
Types ¶
type PITRConfig ¶
type PITRConfig struct {
DatabaseType string `json:"database_type"` // "postgresql" or "mysql"
ConnectionHost string `json:"connection_host"`
ConnectionPort int `json:"connection_port"`
DatabaseName string `json:"database_name"`
User string `json:"user"`
Password string `json:"password"`
WALArchiveDir string `json:"wal_archive_dir"`
BaseBackupDir string `json:"base_backup_dir"`
WALArchiveInterval int `json:"wal_archive_interval"` // seconds
BaseBackupCron string `json:"base_backup_cron"`
}
PITRConfig defines the configuration for point-in-time recovery.
type WALStatus ¶
type WALStatus struct {
LastWALArchived string `json:"last_wal_archived"`
WALArchiveCount int `json:"wal_archive_count"`
LastBaseBackup string `json:"last_base_backup"`
CurrentRPOSeconds int `json:"current_rpo_seconds"`
ArchiveDirSizeBytes int64 `json:"archive_dir_size_bytes"`
}
WALStatus reports the current state of WAL archiving.
func GetWALStatus ¶
func GetWALStatus(cfg PITRConfig) WALStatus
GetWALStatus returns the current state of WAL archiving.
type WALUploader ¶ added in v0.10.0
type WALUploader struct {
// contains filtered or unexported fields
}
WALUploader watches the WAL archive directory and uploads new files to S3 using restic. It runs on a configurable interval and tracks which files have already been uploaded to avoid duplicates.
func NewWALUploader ¶ added in v0.10.0
func NewWALUploader(config PITRConfig, runner *restic.Runner, interval time.Duration) *WALUploader
NewWALUploader creates a WAL uploader that uses the given restic runner to back up WAL files. The runner should be configured with a dedicated restic repo (or tagged separately) for WAL archives.
func (*WALUploader) LastUploadTime ¶ added in v0.10.0
func (u *WALUploader) LastUploadTime() time.Time
LastUploadTime returns the time of the last successful WAL upload.
func (*WALUploader) Run ¶ added in v0.10.0
func (u *WALUploader) Run(ctx context.Context)
Run starts the upload loop. Blocks until ctx is cancelled.
func (*WALUploader) UploadedCount ¶ added in v0.10.0
func (u *WALUploader) UploadedCount() int
UploadedCount returns the number of WAL files that have been uploaded.