pgbackrest

package
v0.0.0-...-30d1bac Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultStanzaName is the name of the default pgBackRest stanza
	DefaultStanzaName = "db"

	// CMInstanceKey is the name of the pgBackRest configuration file for a IvorySQL instance
	CMInstanceKey = "pgbackrest_instance.conf"

	// CMRepoKey is the name of the pgBackRest configuration file for a pgBackRest dedicated
	// repository host
	CMRepoKey = "pgbackrest_repo.conf"

	// ConfigHashKey is the name of the file storing the pgBackRest config hash
	ConfigHashKey = "config-hash"
)
View Source
const (
	// IANAPortNumber is the port assigned to pgBackRest at the IANA.
	IANAPortNumber = 8432

	// IANAServiceName is the name of the pgBackRest protocol at the IANA.
	IANAServiceName = "pgbackrest"
)

The protocol used by pgBackRest is registered with the Internet Assigned Numbers Authority (IANA). - https://www.iana.org/assignments/service-names-port-numbers

Variables

This section is empty.

Functions

func AddConfigToInstancePod

func AddConfigToInstancePod(
	cluster *v1beta1.IvoryCluster, pod *corev1.PodSpec,
)

AddConfigToInstancePod adds and mounts the pgBackRest configuration volumes for an instance of cluster to pod. The database container and any pgBackRest containers must already be in pod.

func AddConfigToRepoPod

func AddConfigToRepoPod(
	cluster *v1beta1.IvoryCluster, pod *corev1.PodSpec,
)

AddConfigToRepoPod adds and mounts the pgBackRest configuration volume for the dedicated repository host of cluster to pod. The pgBackRest containers must already be in pod.

func AddConfigToRestorePod

func AddConfigToRestorePod(
	cluster *v1beta1.IvoryCluster, sourceCluster *v1beta1.IvoryCluster, pod *corev1.PodSpec,
)

AddConfigToRestorePod adds and mounts the pgBackRest configuration volume for the restore job of cluster to pod. The pgBackRest containers must already be in pod.

func AddRepoVolumesToPod

func AddRepoVolumesToPod(ivoryCluster *v1beta1.IvoryCluster, template *corev1.PodTemplateSpec,
	repoPVCNames map[string]string, containerNames ...string) error

AddRepoVolumesToPod adds pgBackRest repository volumes to the provided Pod template spec, while also adding associated volume mounts to the containers specified.

func AddServerToInstancePod

func AddServerToInstancePod(
	cluster *v1beta1.IvoryCluster, pod *corev1.PodSpec,
	instanceCertificateSecretName string,
)

AddServerToInstancePod adds the TLS server container and volume to pod for an instance of cluster. Any IvorySQL volumes must already be in pod.

func AddServerToRepoPod

func AddServerToRepoPod(
	cluster *v1beta1.IvoryCluster, pod *corev1.PodSpec,
)

AddServerToRepoPod adds the TLS server container and volume to pod for the dedicated repository host of cluster.

func CalculateConfigHashes

func CalculateConfigHashes(
	ivoryCluster *v1beta1.IvoryCluster) (map[string]string, string, error)

CalculateConfigHashes calculates hashes for any external pgBackRest repository configuration present in the IvoryCluster spec (e.g. configuration for Azure, GCR and/or S3 repositories). Additionally it returns a hash of the hashes for each external repository.

func CreatePGBackRestConfigMapIntent

func CreatePGBackRestConfigMapIntent(ivoryCluster *v1beta1.IvoryCluster,
	repoHostName, configHash, serviceName, serviceNamespace string,
	instanceNames []string) *corev1.ConfigMap

CreatePGBackRestConfigMapIntent creates a configmap struct with pgBackRest pgbackrest.conf settings in the data field. The keys within the data field correspond to the use of that configuration. pgbackrest_job.conf is used by certain jobs, such as stanza create and backup pgbackrest_primary.conf is used by the primary database pod pgbackrest_repo.conf is used by the pgBackRest repository pod

func DedicatedRepoHostEnabled

func DedicatedRepoHostEnabled(ivoryCluster *v1beta1.IvoryCluster) bool

DedicatedRepoHostEnabled determines whether not a pgBackRest dedicated repository host is enabled according to the provided IvoryCluster

func InstanceCertificates

func InstanceCertificates(ctx context.Context,
	inCluster *v1beta1.IvoryCluster,
	inRoot pki.Certificate,
	inDNS pki.Certificate, inDNSKey pki.PrivateKey,
	outInstanceCertificates *corev1.Secret,
) error

InstanceCertificates populates the shared Secret with certificates needed to run pgBackRest.

func IvorySQL

func IvorySQL(
	inCluster *v1beta1.IvoryCluster,
	outParameters *ivory.Parameters,
)

IvorySQL populates outParameters with any settings needed to run pgBackRest.

func MakePGBackrestLogDir

func MakePGBackrestLogDir(template *corev1.PodTemplateSpec,
	cluster *v1beta1.IvoryCluster)

MakePGBackrestLogDir creates the pgBackRest default log path directory used when a dedicated repo host is configured.

func Permissions

func Permissions(cluster *v1beta1.IvoryCluster) []rbacv1.PolicyRule

Permissions returns the RBAC rules pgBackRest needs for a cluster.

func ReplicaCreateCommand

func ReplicaCreateCommand(
	cluster *v1beta1.IvoryCluster, instance *v1beta1.IvoryInstanceSetSpec,
) []string

ReplicaCreateCommand returns the command that can initialize the IvorySQL data directory on an instance from one of cluster's repositories. It returns nil when no repository is available.

func RepoVolumeMount

func RepoVolumeMount() corev1.VolumeMount

RepoVolumeMount returns the name and mount path of the pgBackRest repo volume.

func RestoreCommand

func RestoreCommand(pgdata string, tablespaceVolumes []*corev1.PersistentVolumeClaim, args ...string) []string

RestoreCommand returns the command for performing a pgBackRest restore. In addition to calling the pgBackRest restore command with any pgBackRest options provided, the script also does the following:

  • Removes the patroni.dynamic.json file if present. This ensures the configuration from the cluster being restored from is not utilized when bootstrapping a new cluster, and the configuration for the new cluster is utilized instead.
  • Starts the database and allows recovery to complete. A temporary ivorysql.conf file with the minimum settings needed to safely start the database is created and utilized.
  • Renames the data directory as needed to bootstrap the cluster using the restored database. This ensures compatibility with the "existing" bootstrap method that is included in the Patroni config when bootstrapping a cluster using an existing data directory.

func RestoreConfig

func RestoreConfig(
	sourceConfigMap, targetConfigMap *corev1.ConfigMap,
	sourceSecret, targetSecret *corev1.Secret,
)

RestoreConfig populates targetConfigMap and targetSecret with values needed to restore a cluster from repositories defined in sourceConfigMap and sourceSecret.

func Secret

func Secret(ctx context.Context,
	inCluster *v1beta1.IvoryCluster,
	inRepoHost *appsv1.StatefulSet,
	inRoot *pki.RootCertificateAuthority,
	inSecret *corev1.Secret,
	outSecret *corev1.Secret,
) error

Secret populates the pgBackRest Secret.

Types

type Executor

type Executor func(
	ctx context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error

Executor calls "pgbackrest" commands

func (Executor) StanzaCreateOrUpgrade

func (exec Executor) StanzaCreateOrUpgrade(ctx context.Context, configHash string,
	upgrade bool) (bool, error)

StanzaCreateOrUpgrade runs either the pgBackRest "stanza-create" or "stanza-upgrade" command depending on the boolean value of the "upgrade" function parameter. This function is invoked by the "reconcileStanzaCreate" function with "upgrade" set to false; if the stanza already exists but the IVY version has changed, pgBackRest will error with the "errMsgBackupDbMismatch" error. If that occurs, we then rerun the command with "upgrade" set to true. - https://github.com/pgbackrest/pgbackrest/blob/release/2.38/src/command/check/common.c#L154-L156 If the bool returned from this function is true, this indicates that a pgBackRest config hash mismatch was identified that prevented the pgBackRest stanza-create or stanza-upgrade command from running (with a config mismatch indicating that the pgBackRest configuration as stored in the cluster's pgBackRest ConfigMap has not yet propagated to the Pod).

Jump to

Keyboard shortcuts

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