repbak

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

README

Build Status Go Report Card GoDoc codecov

Repbak

Repbak is a simple database backup tool made specifically to backup replicated databases. Repbak will send notifications based on database backup failure. Repbak also optionally support HTTP healthchecks for liveness.

Supported Databases

  • MySQL 5.5 (possibly other MySQL versions but untested)

Supported Notifications

  • Email

HTTP Healthcheck

Repbak can optionally listen for HTTP liveness probes at /healthcheck. It will return a 200 status code if live.

How does it work?

  1. Download the latest release.
  2. Create a YAML configuration file
  3. Run it repbak -conf repbak.yaml

Configuration file

The YAML file defines repbak's operation.

Full config example

log_path: /var/log/repbak.log
log_level: error
http:
  addr: 0.0.0.0
  port: 4060
mysql:
  retention: 30
  output_path: /mnt/backups/mysql.dump
  schedule: "0 0 * * *"
  executable_path: mysqldump
  executable_args: --add-drop-database --all-databases -u user -ppass -h 127.0.0.1
  time_limit: 8h
email:
  host: mail.me.com
  port: 587
  user: me
  pass: pass
  starttls: true
  ssl: false
  subject: Database Replication Failure
  from: me@me.com
  to:
    - you@me.com

Global Options

log_path
File on disk where repbak logs will be stored. Defaults to /var/log/repbak.log.
log_level
Sets the log level. Valid levels are: panic, fatal, trace, debug, warn, info, and error. Defaults to error.

http

addr
The listening address for the HTTP server. Default to 0.0.0.0
port
The listening port for the HTTP server. Default to 4040

mysql

retention
The number of backups to keep before rotating old backups out. Defaults to 7.
output_path
The path where backups will be stored.
schedule
The cron expression that defines when backups are created.
executable_path
The path to the tool used to create the mysql backup. Defaults to mysqldump.
executable_args
The arguments passed to the executable used to create the mysql backup. Defaults to --add-drop-database --all-databases.
time_limit
Optional limit to the time it takes to run the backup.

email

host
The hostname or IP of the SMTP server.
port
The port of the SMTP server.
user
The username used to authenticate.
pass
The password used to authenticate.
start_tls
StartTLS enables TLS security. If both StartTLS and SSL are true then StartTLS will be used.
insecure_skip_verify
When using TLS skip verifying the server's certificate chain and host name.
ssl
SSL enables SSL security. If both StartTLS and SSL are true then StartTLS will be used.
from
The email address the email will be sent from.
to
An array of email addresses for which emails will be sent.

Flags

-conf

Path to the repbak configuration file

-debug

Log to STDOUT

Road Map

  • Docker Image
  • Systemd service file
  • Create rpm
  • Create deb
  • Support for more databases
  • Support for more notifiers

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// LogPath is the oath on disk where repbak log file. Defaults to /var/log/repbak.log.
	LogPath string `yaml:"log_path"`

	// LogLevel sets the level of logging. Valid levels are: panic, fatal, trace, debug, warn, info, and error. Defaults to error
	LogLevel string `yaml:"log_level"`

	HTTP  *HTTP  `yaml:"http"`
	MySQL *MySQL `yaml:"mysql"`
	Email *Email `yaml:"email"`
}

Config is an object representation of the YAML configuration file.

func OpenConfig

func OpenConfig(path string) (*Config, error)

OpenConfig returns a new Config option by reading the YAML file at path. If the file doesn't exist, can't be read, is invalid YAML, or doesn't match the repbak spec then an error is returned.

type Dumper

type Dumper interface {
	// Dump does a backup of the database
	Dump() error

	// Stop stops the database backup if one is running
	Stop()
}

Dumper defines an interface for backing up a database.

type Email

type Email struct {
	// Host is the hostname or IP of the SMTP server.
	Host string `yaml:"host"`

	// Port is the port of the SMTP server.
	Port int `yaml:"port"`

	// User is the username used to authenticate.
	User string `yaml:"user"`

	// Pass is the password used to authenticate.
	Pass string `yaml:"pass"`

	// StartTLS enables TLS security. If both StartTLS and SSL are true then StartTLS will be used.
	StartTLS bool `yaml:"starttls"`

	// Skip verifying the server's certificate chain and host name.
	InsecureSkipVerify bool `yaml:"insecure_skip_verify"`

	// SSL enables SSL security. If both StartTLS and SSL are true then StartTLS will be used.
	SSL bool `yaml:"ssl"`

	// Optional subject field for notification emails
	Subject string `yaml:"subject"`

	// From is the email address the email will be sent from.
	From string `yaml:"from"`

	// To is an array of email addresses for which emails will be sent.
	To []string `yaml:"to"`
}

type EmailNotifier

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

EmailNotifier sends emails based on repliaction failure

func NewEmailNotifier

func NewEmailNotifier(config *Config) *EmailNotifier

NewEmailNotifier creates a EmailNotifier using the config

func (*EmailNotifier) Notify

func (n *EmailNotifier) Notify(err error) error

Notify sends a failure notification

type HTTP

type HTTP struct {
	// The address the http server will listen on.
	Addr string `yaml:"addr"`

	// The port the http server will listen on.
	Port int `yaml:"port"`
}

HTTP defines the configuration for http health checks.

type MySQL

type MySQL struct {
	// Retention is the number of backups to keep before rotating old backups out. Defaults to 7.
	Retention int `yaml:"retention"`

	// OutputPath is the path where backups will be stored.
	OutputPath string `yaml:"output_path"`

	// Schedule is the cron expression that defines when backups are created.
	Schedule string `yaml:"schedule"`

	// ExecutablePath is the path to the tool used to create the mysql backup. Defaults to mysqldump.
	ExecutablePath string `yaml:"executable_path"`

	// ExecutableArgs are the arguments passed to the executable used to create the mysql backup. Defaults to --add-drop-database --all-databases.
	ExecutableArgs string `yaml:"executable_args"`

	// TimeLimit is an optional limit to the time it takes to run the backup.
	TimeLimit string `yaml:"time_limit"`
	// contains filtered or unexported fields
}

MySQL defines how a mysql backup will be created.

type MySQLDumper

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

MySQLDumper dumps a mysql backup to a file.

func NewMySQLDumper

func NewMySQLDumper(config *Config) *MySQLDumper

NewMySQLDumper creates a MySQLDumper.

func (*MySQLDumper) Dump

func (d *MySQLDumper) Dump() error

Dump dumps the mysql data to a file based on the settings in config.

func (*MySQLDumper) Stop

func (d *MySQLDumper) Stop()

Stop stops the current dump if one is running.

type Notifier

type Notifier interface {
	// Notify sends a notification
	Notify(error) error
}

Notifier defines a notification method.

type RepBak

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

RepBak reforms scheduled database backups.

func New

func New(config *Config, dumper Dumper, notifier Notifier) *RepBak

New returns a new RepBak instance.

func (*RepBak) Start

func (r *RepBak) Start() error

Start runs until stopped and does scheduled database backups.

func (*RepBak) Stop

func (r *RepBak) Stop()

Stop stops repmon from running for schedule database backups.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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