walg

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 22 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackupMetadata

type BackupMetadata struct {
	BackupName       string         `json:"backup_name"`
	Time             string         `json:"time"`
	WalFileName      string         `json:"wal_file_name"`
	StorageName      string         `json:"storage_name"`
	StartTimeString  string         `json:"start_time"`
	FinishTimeString string         `json:"finish_time"`
	DateFmt          string         `json:"date_fmt"`
	Hostname         string         `json:"hostname"`
	DataDir          string         `json:"data_dir"`
	PGVersion        int            `json:"pg_version"`
	StartLSN         uint64         `json:"start_lsn"`
	FinishLSN        uint64         `json:"finish_lsn"`
	IsPermanent      bool           `json:"is_permanent"`
	SystemIdentifier int            `json:"system_identifier"`
	UncompressedSize int            `json:"uncompressed_size"`
	CompressedSize   int            `json:"compressed_size"`
	UserData         map[string]any `json:"user_data"`
}

BackupMetadata represents single backup metadata returned by wal-g on "wal-g backup-list --detail --json"

func (*BackupMetadata) FinishTime

func (m *BackupMetadata) FinishTime() (time.Time, error)

func (*BackupMetadata) GetDependentBackups

func (m *BackupMetadata) GetDependentBackups(ctx context.Context, backupList []BackupMetadata, includeIndirect bool) []BackupMetadata

GetDependentBackups returns a list of backups that depend on the current backup. This is determined by analyzing backup names, where delta backups include their base backup's WAL ID. For example: - base_000000010000000100000040 (full backup) - base_000000010000000100000046_D_000000010000000100000040 (delta backup depending on the full backup) - base_000000010000000100000061_D_000000010000000100000046 (delta backup depending on the previous delta)

If includeIndirect is true, it will also include indirect dependencies (dependencies of dependencies). For example, if A depends on the current backup, and B depends on A, then B is an indirect dependency of the current backup and will be included in the result if includeIndirect is true.

func (*BackupMetadata) HasMatchingTimeline

func (m *BackupMetadata) HasMatchingTimeline(targetTimeline string) bool

func (*BackupMetadata) StartTime

func (m *BackupMetadata) StartTime() (time.Time, error)

func (*BackupMetadata) Timeline

func (m *BackupMetadata) Timeline() int

func (*BackupMetadata) TimelineStr

func (m *BackupMetadata) TimelineStr() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client encapsulates all wal-g operations for a given configuration. Create it with NewClient after building a Config via NewConfigFromBackupConfig.

func NewClient

func NewClient(config *Config) *Client

NewClient creates a new Client from the provided Config.

func NewClientFromBackupConfig

func NewClientFromBackupConfig(backupConfig *v1beta1.BackupConfigWithSecrets, pgMajorVersion int) *Client

NewClientFromBackupConfig is a convenience constructor that builds a Config from a BackupConfigWithSecrets and pgMajorVersion, then wraps it in a Client.

func (*Client) BackupFetch

func (c *Client) BackupFetch(ctx context.Context, targetDir, backupName string) (*cmd.RunResult, error)

BackupFetch runs `wal-g backup-fetch` to restore a named backup into targetDir.

func (*Client) BackupPush

func (c *Client) BackupPush(ctx context.Context, pgdata string, userDataJSON string) (*cmd.RunResult, error)

BackupPush runs `wal-g backup-push` for the given PGDATA directory with optional user data.

func (*Client) Config

func (c *Client) Config() *Config

Config returns the underlying Config held by this Client.

func (*Client) DeleteAllBackupsAndWALsInStorage

func (c *Client) DeleteAllBackupsAndWALsInStorage(ctx context.Context) (*cmd.RunResult, error)

DeleteAllBackupsAndWALsInStorage removes all backups and WAL segments from storage.

func (*Client) DeleteBackup

func (c *Client) DeleteBackup(ctx context.Context, backupName string) (*cmd.RunResult, error)

DeleteBackup deletes a backup and runs garbage collection using wal-g.

func (*Client) FindMostSuitableBackupForRecovery

func (c *Client) FindMostSuitableBackupForRecovery(
	ctx context.Context,
	backupList []BackupMetadata,
	recoveryTarget cnpgv1.RecoveryTarget,
) (*BackupMetadata, error)

FindMostSuitableBackupForRecovery finds the backup that should be used to fulfill a PITR request via target parameters specified within RecoveryTarget.

func (*Client) GetBackupByName

func (c *Client) GetBackupByName(ctx context.Context, backupList []BackupMetadata, name string) *BackupMetadata

GetBackupByName finds a backup by name in the provided list. Returns nil if no backup with the given name is found.

func (*Client) GetBackupByUserData

func (c *Client) GetBackupByUserData(
	ctx context.Context,
	backupList []BackupMetadata,
	userData map[string]any,
) (*BackupMetadata, error)

GetBackupByUserData finds the most recent wal-g backup matching the provided user data. Returns (nil, nil) if no matching backup is found.

func (*Client) GetBackupsList

func (c *Client) GetBackupsList(ctx context.Context) ([]BackupMetadata, error)

GetBackupsList fetches the full list of backups from wal-g storage.

func (*Client) GetLatestBackup

func (c *Client) GetLatestBackup(ctx context.Context, backupList []BackupMetadata) (*BackupMetadata, error)

GetLatestBackup returns the latest backup from the provided list.

func (*Client) MarkBackupPermanent

func (c *Client) MarkBackupPermanent(ctx context.Context, backupName string) error

MarkBackupPermanent marks a backup as permanent so it cannot be deleted by `wal-g delete everything` and is ignored during WAL retention. Marking backups as permanent is useful for user-created backups which should be stored indefinitely.

func (*Client) StorageCheckReadable

func (c *Client) StorageCheckReadable(ctx context.Context) (*cmd.RunResult, error)

StorageCheckReadable verifies that the configured storage is accessible for reading by running `wal-g st check read`.

func (*Client) StorageCheckWritable

func (c *Client) StorageCheckWritable(ctx context.Context) (*cmd.RunResult, error)

StorageCheckWritable verifies that the configured storage is accessible for writing by running `wal-g st check write`.

func (*Client) StorageLsTotalSize

func (c *Client) StorageLsTotalSize(ctx context.Context, path string) (int64, error)

StorageLsTotalSize runs `wal-g st ls <path>` and sums up the sizes of all listed objects. The output format is: "obj <size> <date> <time> <timezone> <filename>" Returns total size in bytes.

func (*Client) UnmarkBackupPermanent

func (c *Client) UnmarkBackupPermanent(ctx context.Context, backupName string) error

UnmarkBackupPermanent removes the permanent mark from a backup. This is useful when a backup needs to be deleted after being marked permanent. Does nothing and returns no error if the backup is already not marked permanent.

func (*Client) WALFetch

func (c *Client) WALFetch(ctx context.Context, sourceWalName, destinationFileName string) (*cmd.RunResult, error)

WALFetch restores a WAL segment from object storage using wal-g. Returns the RunResult so callers can inspect the exit code (e.g. 74 = WAL not found).

func (*Client) WALPush

func (c *Client) WALPush(ctx context.Context, sourceFileName string) (*cmd.RunResult, error)

WALPush archives a WAL segment to object storage using wal-g.

func (*Client) WALShow

func (c *Client) WALShow(ctx context.Context) ([]WALTimelineInfo, error)

WALShow retrieves detailed WAL timeline information by running `wal-g wal-show --detailed-json`. Returns a list of WALTimelineInfo entries, each representing a timeline with its segments, backups, and integrity status.

type Config

type Config struct {
	// WALG params
	AWSAccessKeyID                    string `json:"AWS_ACCESS_KEY_ID,omitempty"`
	AWSEndpoint                       string `json:"AWS_ENDPOINT,omitempty"`
	AWSS3ForcePathStyle               bool   `json:"AWS_S3_FORCE_PATH_STYLE,omitempty"`
	AWSRegion                         string `json:"AWS_REGION,omitempty"`
	AWSSecretAccessKey                string `json:"AWS_SECRET_ACCESS_KEY,omitempty"`
	GoogleApplicationCredentials      string `json:"GOOGLE_APPLICATION_CREDENTIALS,omitempty"`
	GoDebug                           string `json:"GODEBUG,omitempty"`
	GoMaxProcs                        int    `json:"GOMAXPROCS,omitempty"`
	PgHost                            string `json:"PGHOST,omitempty"`
	PgUser                            string `json:"PGUSER,omitempty"`
	S3LogLevel                        string `json:"S3_LOG_LEVEL,omitempty"`
	TotalBgUploadedLimit              int    `json:"TOTAL_BG_UPLOADED_LIMIT,omitempty"`
	WaleGPGKeyID                      string `json:"WALE_GPG_KEY_ID,omitempty"`
	WalgGSPrefix                      string `json:"WALG_GS_PREFIX,omitempty"`
	WaleS3Prefix                      string `json:"WALE_S3_PREFIX,omitempty"`
	WalgAliveCheckInterval            string `json:"WALG_ALIVE_CHECK_INTERVAL,omitempty"`
	WalgCompressionMethod             string `json:"WALG_COMPRESSION_METHOD,omitempty"`
	WalgDeltaMaxSteps                 int    `json:"WALG_DELTA_MAX_STEPS,omitempty"`
	WalgDiskRateLimit                 int    `json:"WALG_DISK_RATE_LIMIT,omitempty"`
	WalgDownloadConcurrency           int    `json:"WALG_DOWNLOAD_CONCURRENCY,omitempty"`
	WalgDownloadFileRetries           int    `json:"WALG_DOWNLOAD_FILE_RETRIES,omitempty"`
	WalgFailoverStoragesCacheLifetime string `json:"WALG_FAILOVER_STORAGES_CACHE_LIFETIME,omitempty"`
	WalgFailoverStoragesCheck         bool   `json:"WALG_FAILOVER_STORAGES_CHECK,omitempty"`
	WalgFailoverStoragesCheckSize     string `json:"WALG_FAILOVER_STORAGES_CHECK_SIZE,omitempty"`
	WalgLibsodiumKey                  string `json:"WALG_LIBSODIUM_KEY,omitempty"`
	WalgLibsodiumKeyPath              string `json:"WALG_LIBSODIUM_KEY_PATH,omitempty"`
	WalgLibsodiumKeyTransform         string `json:"WALG_LIBSODIUM_KEY_TRANSFORM,omitempty"`
	WalgLogDestination                string `json:"WALG_LOG_DESTINATION,omitempty"`
	WalgNetworkRateLimit              int    `json:"WALG_NETWORK_RATE_LIMIT,omitempty"`
	WalgPgpKeyPath                    string `json:"WALG_PGP_KEY_PATH,omitempty"`
	WalgPrefetchDir                   string `json:"WALG_PREFETCH_DIR,omitempty"`
	WalgPreventWalOverwrite           string `json:"WALG_PREVENT_WAL_OVERWRITE,omitempty"`
	WalgS3CACertFile                  string `json:"WALG_S3_CA_CERT_FILE,omitempty"`
	WalgS3StorageClass                string `json:"WALG_S3_STORAGE_CLASS,omitempty"`
	WalgTarDisableFsync               string `json:"WALG_TAR_DISABLE_FSYNC,omitempty"`
	WalgTarSizeThreshold              int64  `json:"WALG_TAR_SIZE_THRESHOLD,omitempty"`
	WalgUploadConcurrency             int    `json:"WALG_UPLOAD_CONCURRENCY,omitempty"`
	WalgUploadDiskConcurrency         int    `json:"WALG_UPLOAD_DISK_CONCURRENCY,omitempty"`
}

func NewConfigFromBackupConfig

func NewConfigFromBackupConfig(backupConfig *v1beta1.BackupConfigWithSecrets, pgMajorVersion int) *Config

func NewConfigWithDefaults

func NewConfigWithDefaults() Config

func (*Config) Hash

func (c *Config) Hash() string

Hash returns a stable SHA-256 hex digest of the Config's JSON representation. It can be used to compare Config objects to detect whether the configuration has changed and need to rebuild a walg.Client.

func (*Config) ToEnvMap

func (c *Config) ToEnvMap() map[string]string

ToEnvMap returns Map with environment variables acceptable by wal-g

func (*Config) ToFile

func (c *Config) ToFile(targetFilepath string) error

ToFile dumps config to a file in JSON format acceptable by wal-g via --config param

type WALTimelineInfo

type WALTimelineInfo struct {
	ID               int              `json:"id"`
	ParentID         int              `json:"parent_id"`
	SwitchPointLSN   uint64           `json:"switch_point_lsn"`
	StartSegment     string           `json:"start_segment"`
	EndSegment       string           `json:"end_segment"`
	SegmentsCount    int              `json:"segments_count"`
	MissingSegments  []string         `json:"missing_segments"`
	Backups          []BackupMetadata `json:"backups"`
	SegmentRangeSize int              `json:"segment_range_size"`
	Status           string           `json:"status"`
}

WALTimelineInfo represents a single timeline entry returned by `wal-g wal-show --detailed-json`

func (*WALTimelineInfo) HasMissingSegments

func (w *WALTimelineInfo) HasMissingSegments() bool

HasMissingSegments returns true if there are any missing WAL segments in this timeline

func (*WALTimelineInfo) IsOK

func (w *WALTimelineInfo) IsOK() bool

IsOK returns true if the timeline status is "OK"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL