gpbckpconfig

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Layout     = "20060102150405"
	DateFormat = "Mon Jan 02 2006 15:04:05"
	// Backup types.
	BackupTypeFull         = "full"
	BackupTypeIncremental  = "incremental"
	BackupTypeDataOnly     = "data-only"
	BackupTypeMetadataOnly = "metadata-only"
	// Backup statuses.
	BackupStatusSuccess    = "Success"
	BackupStatusFailure    = "Failure"
	BackupStatusInProgress = "In Progress"

	// Date deleted types.
	DateDeletedInProgress   = "In progress"
	DateDeletedPluginFailed = "Plugin Backup Delete Failed"
	DateDeletedLocalFailed  = "Local Delete Failed"
	// BackupS3Plugin S3 plugin names.
	BackupS3Plugin = "gpbackup_s3_plugin"
)

Variables

This section is empty.

Functions

func BackupDirPath added in v0.6.0

func BackupDirPath(backupDir, timestamp string) string

BackupDirPath Returns path to full backup directory.

func CheckBackupCanBeDisplayed added in v0.3.0

func CheckBackupCanBeDisplayed(showD, showF bool, status, dateDeleted string) bool

CheckBackupCanBeDisplayed Returns true if the backup satisfies the parameters. This function is only applicable to processing values obtained from gpbackup history file.

The value is calculated, based on:

  • if showD is true, the function returns true only for backups that active or already deleted;
  • if showF is true, the function returns true only for backups that active or failed;
  • if none of the parameters were passed, the function returns true for backups that have a successful status and have not been deleted;
  • If none of the above conditions are met, the function returns false.

func CheckFullPath

func CheckFullPath(checkPath string, checkFileExists bool) error

CheckFullPath Returns error if path is not an absolute path or file does not exist.

func CheckMasterBackupDir added in v0.6.0

func CheckMasterBackupDir(backupDir string) (string, string, bool, error)

CheckMasterBackupDir checks the backup directory for the master backup. It first tries to find the backup directory in the single-backup-dir format. If the single-backup-dir format is not used, it returns an error. If the single-backup-dir format is used, it returns the backup directory and sets the prefix to an empty string. If the single-backup-dir format is not found, it tries to find the backup directory with segment prefix format. If the backup directory with segment prefix format is not found, it returns an error. If multiple backup directories with segment prefix format are found, it returns an error. Otherwise, it returns the backup directory with segment prefix format, the segment prefix, and useSingleBackupDir flag to false.

func CheckTableFQN added in v0.3.0

func CheckTableFQN(table string) error

CheckTableFQN Returns error if table FQN is not in the format <schema.table>.

func CheckTimestamp

func CheckTimestamp(timestamp string) error

CheckTimestamp Returns error if timestamp is not valid.

func CleanBackupsDB added in v0.2.0

func CleanBackupsDB(list []string, batchSize int, historyDB *sql.DB) error

CleanBackupsDB cleans the backup history database by deleting backups based on the given list of backup names.

func ConvertToHistoryBackupConfig

func ConvertToHistoryBackupConfig(backupConfig BackupConfig) history.BackupConfig

ConvertToHistoryBackupConfig converts a BackupConfig to a history.BackupConfig. It maps the fields from the BackupConfig struct to the history.BackupConfig struct.

func ExecuteQueryLocalClusterConn added in v0.5.0

func ExecuteQueryLocalClusterConn[T any](conn *sqlx.DB, query string) (T, error)

ExecuteQueryLocalClusterConn executes a query on the local cluster connection and returns the result. The function is generic and can handle different types of results based on the type parameter T.

Parameters: - conn: A pointer to the sqlx.DB connection object. - query: A string containing the SQL query to be executed.

Returns: - T: The result of the query, which can be of any type specified by the caller. - error: An error object if the query execution fails or if the type is unsupported.

The function supports the following types for T: - string: The result will be a single string value. - []SegmentConfig: The result will be a slice of SegmentConfig structs.

If the type T is not supported, the function returns an error indicating the unsupported type.

func GetBackupDependencies

func GetBackupDependencies(backupName string, historyDB *sql.DB) ([]string, error)

func GetBackupNamesAfterTimestamp added in v0.7.0

func GetBackupNamesAfterTimestamp(timestamp string, historyDB *sql.DB) ([]string, error)

func GetBackupNamesBeforeTimestamp added in v0.2.0

func GetBackupNamesBeforeTimestamp(timestamp string, historyDB *sql.DB) ([]string, error)

func GetBackupNamesDB

func GetBackupNamesDB(showD, showF bool, historyDB *sql.DB) ([]string, error)

GetBackupNamesDB Returns a list of backup names.

func GetBackupNamesForCleanBeforeTimestamp added in v0.2.0

func GetBackupNamesForCleanBeforeTimestamp(timestamp string, historyDB *sql.DB) ([]string, error)

func GetSegPrefix added in v0.5.0

func GetSegPrefix(backupDir string) string

GetSegPrefix Returns segment prefix from the master backup directory.

func GetTimestampOlderThen added in v0.2.0

func GetTimestampOlderThen(value uint) string

func IsBackupActive

func IsBackupActive(dateDeleted string) bool

IsBackupActive Returns true if backup is active (not deleted).

func IsPositiveValue added in v0.6.0

func IsPositiveValue(value int) bool

IsPositiveValue Returns true if the value is positive.

func NewClusterLocalClusterConn added in v0.5.0

func NewClusterLocalClusterConn(dbName string) (*sqlx.DB, error)

NewClusterLocalClusterConn creates a new connection to the local postgres database Returns an error if the connection could not be established.

func OpenHistoryDB

func OpenHistoryDB(historyDBPath string) (*sql.DB, error)

OpenHistoryDB Opens the history backup database.

func ReadHistoryFile

func ReadHistoryFile(filename string) ([]byte, error)

ReadHistoryFile Read history file.

func ReportFileName added in v0.5.0

func ReportFileName(timestamp string) string

ReportFileName Returns report file name for specific timestamp. Report file name format: gpbackup_<YYYYMMDDHHMMSS>_report.

func ReportFilePath added in v0.5.0

func ReportFilePath(backupDir, timestamp string) string

ReportFilePath Returns path to report file.

func UpdateDeleteStatus added in v0.2.0

func UpdateDeleteStatus(backupName, dateDeleted string, historyDB *sql.DB) error

UpdateDeleteStatus Updates the date_deleted column in the history database.

Types

type BackupConfig

type BackupConfig struct {
	BackupDir             string             `yaml:"backupdir"`
	BackupVersion         string             `yaml:"backupversion"`
	Compressed            bool               `yaml:"compressed"`
	CompressionType       string             `yaml:"compressiontype"`
	DatabaseName          string             `yaml:"databasename"`
	DatabaseVersion       string             `yaml:"databaseversion"`
	DataOnly              bool               `yaml:"dataonly"`
	DateDeleted           string             `yaml:"datedeleted"`
	ExcludeRelations      []string           `yaml:"excluderelations"`
	ExcludeSchemaFiltered bool               `yaml:"excludeschemafiltered"`
	ExcludeSchemas        []string           `yaml:"excludeschemas"`
	ExcludeTableFiltered  bool               `yaml:"excludetablefiltered"`
	IncludeRelations      []string           `yaml:"includerelations"`
	IncludeSchemaFiltered bool               `yaml:"includeschemafiltered"`
	IncludeSchemas        []string           `yaml:"includeschemas"`
	IncludeTableFiltered  bool               `yaml:"includetablefiltered"`
	Incremental           bool               `yaml:"incremental"`
	LeafPartitionData     bool               `yaml:"leafpartitiondata"`
	MetadataOnly          bool               `yaml:"metadataonly"`
	Plugin                string             `yaml:"plugin"`
	PluginVersion         string             `yaml:"pluginversion"`
	RestorePlan           []RestorePlanEntry `yaml:"restoreplan"`
	SingleDataFile        bool               `yaml:"singledatafile"`
	Timestamp             string             `yaml:"timestamp"`
	EndTime               string             `yaml:"endtime"`
	WithoutGlobals        bool               `yaml:"withoutgoals"`
	WithStatistics        bool               `yaml:"withstatistics"`
	Status                string             `yaml:"status"`
}

func ConvertFromHistoryBackupConfig

func ConvertFromHistoryBackupConfig(hBackupConfig *history.BackupConfig) BackupConfig

ConvertFromHistoryBackupConfig converts a history.BackupConfig to a BackupConfig. It maps the fields from the history.BackupConfig struct to the BackupConfig struct.

func GetBackupDataDB

func GetBackupDataDB(backupName string, hDB *sql.DB) (BackupConfig, error)

GetBackupDataDB Read backup data from history database and return BackupConfig struct.

func (BackupConfig) CheckObjectFilteringExists added in v0.3.0

func (backupConfig BackupConfig) CheckObjectFilteringExists(tableFilter, schemaFilter, objectFilter string, excludeFilter bool) bool

CheckObjectFilteringExists checks if the object filtering exists in the backup.

This function is responsible for determining whether table or schema filtering exists in the backup, and if so, whether the specified filter type is being used. Returns:

  • true - if table or schema filtering exists in the backup or no filters are specified;
  • false - if table or schema filtering does not exists in the backup.

func (BackupConfig) GetBackupDate

func (backupConfig BackupConfig) GetBackupDate() (string, error)

GetBackupDate Get backup date. If an error occurs when parsing the date, the empty string and error are returned.

func (BackupConfig) GetBackupDateDeleted

func (backupConfig BackupConfig) GetBackupDateDeleted() (string, error)

GetBackupDateDeleted Get backup deletion date or backup deletion status. The possible values are:

  • In progress - if the value is set to "In progress";
  • Plugin Backup Delete Failed - if the value is set to "Plugin Backup Delete Failed";
  • Local Delete Failed - if the value is set to "Local Delete Failed";
  • "" - if backup is active;
  • date in format "Mon Jan 02 2006 15:04:05" - if backup is deleted and deletion timestamp is set.

In all other cases, an error is returned.

func (BackupConfig) GetBackupDuration

func (backupConfig BackupConfig) GetBackupDuration() (float64, error)

GetBackupDuration Get backup duration in seconds. If an error occurs when parsing the date, the zero duration and error are returned.

func (BackupConfig) GetBackupType

func (backupConfig BackupConfig) GetBackupType() (string, error)

GetBackupType Get backup type. The value is calculated, based on:

  • full - contains user data, all global and local metadata for the database;
  • incremental – contains user data, all global and local metadata changed since a previous full backup;
  • metadata-only – contains only global and local metadata for the database;
  • data-only – contains only user data from the database.

In all other cases, an error is returned.

func (BackupConfig) GetObjectFilteringInfo

func (backupConfig BackupConfig) GetObjectFilteringInfo() (string, error)

GetObjectFilteringInfo Get object filtering information. The value is calculated, base on whether at least one of the flags was specified:

  • include-schema – at least one "--include-schema" option was specified;
  • exclude-schema – at least one "--exclude-schema" option was specified;
  • include-table – at least one "--include-table" option was specified;
  • exclude-table – at least one "--exclude-table" option was specified;
  • "" - no options was specified.

For gpbackup only one type of filters can be used (see docs). So these options cannot be set at the same time. If not one of these flags is not set, the "" value is returned. In all other cases, an error is returned.

func (BackupConfig) GetReportFilePathPlugin added in v0.2.0

func (backupConfig BackupConfig) GetReportFilePathPlugin(customReportPath string, pluginOptions map[string]string) (string, error)

GetReportFilePathPlugin Return path to report file name for specific plugin. If custom report path is set, it is returned. Otherwise, the path from plugin is returned.

func (BackupConfig) IsInProgress added in v0.6.0

func (backupConfig BackupConfig) IsInProgress() bool

func (BackupConfig) IsLocal

func (backupConfig BackupConfig) IsLocal() bool

IsLocal Check if the backup in local or in plugin storage. Returns:

  • true - if the backup in local storage (plugin field is empty);
  • false - if the backup in plugin storage (plugin field is not empty).

func (BackupConfig) IsSuccess

func (backupConfig BackupConfig) IsSuccess() (bool, error)

IsSuccess Check backup status. Returns:

  • true - if backup is successful,
  • false - false if backup is not successful or in progress.

In all other cases, an error is returned.

type History

type History struct {
	BackupConfigs []BackupConfig `yaml:"backupconfigs"`
}

func ParseResult

func ParseResult(output []byte) (History, error)

ParseResult Parse result to History struct.

func (*History) FindBackupConfig

func (history *History) FindBackupConfig(timestamp string) (int, BackupConfig, error)

func (*History) FindBackupConfigDependencies

func (history *History) FindBackupConfigDependencies(timestamp string, stopPosition int) []string

func (*History) RemoveMultipleFromHistoryFile added in v0.2.0

func (history *History) RemoveMultipleFromHistoryFile(idxs []int)

RemoveMultipleFromHistoryFile Remove multiple backups from history file. Idxs is a list of sorted indexes of backups to be removed. It iterates over the sorted indices and uses the copy function to shift the elements to the left, effectively removing the element at the current index. Finally, it trims the slice to the correct length.

func (*History) UpdateBackupConfigDateDeleted

func (history *History) UpdateBackupConfigDateDeleted(timestamp, dataDeleted string) error

func (*History) UpdateHistoryFile

func (history *History) UpdateHistoryFile(historyFile string) error

func (*History) WriteToFileAndMakeReadOnly

func (history *History) WriteToFileAndMakeReadOnly(filename string) error

type RestorePlanEntry

type RestorePlanEntry struct {
	Timestamp string   `yaml:"timestamp"`
	TableFQNs []string `yaml:"tablefqdn"`
}

type SegmentConfig added in v0.6.0

type SegmentConfig struct {
	ContentID string
	Hostname  string
	DataDir   string
}

Jump to

Keyboard shortcuts

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