Documentation ¶
Index ¶
- Variables
- func CheckType(path string) string
- func Configure() (*TarUploader, *Prefix, error)
- func Connect() (*pgx.Conn, error)
- func CreateUploader(svc s3iface.S3API, partsize, concurrency int) s3manageriface.UploaderAPI
- func DecompressLz4(d io.Writer, s io.Reader) error
- func DecompressLzo(d io.Writer, s io.Reader) error
- func ExtractAll(ti TarInterpreter, files []ReaderMaker) error
- func FormatName(s string) (string, error)
- func HandleTar(bundle TarBundle, path string, info os.FileInfo) error
- func StartBackup(conn *pgx.Conn, backup string) (string, error)
- type Archive
- type Backup
- type BackupTime
- type Bundle
- type Empty
- type EmptyWriteIgnorer
- type ExponentialTicker
- type FileTarInterpreter
- type Lz4CascadeClose
- type Lz4Error
- type LzPipeWriter
- type NoMatchAvailableError
- type Prefix
- type RaskyReader
- type ReaderMaker
- type S3ReaderMaker
- type S3TarBall
- func (s *S3TarBall) BaseDir() string
- func (s *S3TarBall) CloseTar() error
- func (s *S3TarBall) Finish() error
- func (s *S3TarBall) Nop() bool
- func (s *S3TarBall) Number() int
- func (s *S3TarBall) SetSize(i int64)
- func (s *S3TarBall) SetUp(names ...string)
- func (s *S3TarBall) Size() int64
- func (s *S3TarBall) StartUpload(name string) io.WriteCloser
- func (s *S3TarBall) Trim() string
- func (s *S3TarBall) Tw() *tar.Writer
- type S3TarBallMaker
- type Sentinel
- type TarBall
- type TarBallMaker
- type TarBundle
- type TarInterpreter
- type TarUploader
- type TimeSlice
- type UnsetEnvVarError
- type UnsupportedFileTypeError
- type WalFiles
- type ZeroReader
Constants ¶
This section is empty.
Variables ¶
var Compressed uint32
Compressed is used to log compression ratio.
var EXCLUDE = make(map[string]Empty)
EXCLUDE is a list of excluded members from the bundled backup.
var MAXBACKOFF = float64(32)
MAXBACKOFF is the maxmimum backoff time in seconds for upload.
var MAXRETRIES = 7
MAXRETRIES is the maximum number of retries for upload.
var Uncompressed uint32
Uncompressed is used to log compression ratio.
Functions ¶
func Configure ¶
func Configure() (*TarUploader, *Prefix, error)
Configure connects to S3 and creates an uploader. It makes sure that a valid session has started; if invalid, returns AWS error and `<nil>` values.
Requires these environment variables to be set: WALE_S3_PREFIX
Able to configure the upload part size in the S3 uploader.
func Connect ¶
Connect establishes a connection to postgres using a UNIX socket. Must export PGHOST and run with `sudo -E -u postgres`. If PGHOST is not set or if the connection fails, an error is returned and the connection is `<nil>`.
func CreateUploader ¶
func CreateUploader(svc s3iface.S3API, partsize, concurrency int) s3manageriface.UploaderAPI
CreateUploader returns an uploader with customizable concurrency and partsize.
func DecompressLz4 ¶
DecompressLz4 decompresses a .lz4 file. Returns an error upon failure.
func DecompressLzo ¶
DecompressLzo decompresses an .lzo file. Returns the first error encountered.
func ExtractAll ¶
func ExtractAll(ti TarInterpreter, files []ReaderMaker) error
ExtractAll Handles all files passed in. Supports `.lzo`, `.lz4, and `.tar`. File type `.nop` is used for testing purposes. Each file is extracted in its own goroutine and ExtractAll will wait for all goroutines to finish. Returns the first error encountered.
func FormatName ¶
FormatName grabs the name of the WAL file and returns it in the form of `base_...`. If no match is found, returns an empty string and a `NoMatchAvailableError`.
func HandleTar ¶
HandleTar creates underlying tar writer and handles one given file. Does not follow symlinks. If file is in EXCLUDE, will not be included in the final tarball. EXCLUDED directories are created but their contents are not written to local disk.
func StartBackup ¶
StartBackup starts a non-exclusive base backup immediately. When finishing the backup, `backup_label` and `tablespace_map` contents are not immediately written to a file but returned instead. Returns empty string and an error if backup fails.
Types ¶
type Archive ¶
Archive contains information associated with a WAL archive.
func (*Archive) CheckExistence ¶
CheckExistence checks that the specified WAL file exists.
func (*Archive) GetArchive ¶
func (a *Archive) GetArchive() (io.ReadCloser, error)
GetArchive downloads the specified archive from S3.
type Backup ¶
Backup contains information about a valid backup generated and uploaded by WAL-G.
func (*Backup) CheckExistence ¶
CheckExistence checks that the specified backup exists.
type BackupTime ¶
BackupTime is used to sort backups by latest modified time.
type Bundle ¶
type Bundle struct { MinSize int64 Sen *Sentinel Tb TarBall Tbm TarBallMaker }
A Bundle represents the directory to be walked. Contains at least one TarBall if walk has started. Each TarBall will be at least MinSize bytes. The Sentinel is used to ensure complete uploaded backups; in this case, pg_control is used as the sentinel.
func (*Bundle) GetTarBall ¶
func (*Bundle) HandleLabelFiles ¶
HandleLabelFiles creates the `backup_label` and `tablespace_map` files and uploads it to S3 by stopping the backup. Returns error upon failure.
func (*Bundle) HandleSentinel ¶
HandleSentinel uploads the compressed tar file of `pg_control`. Will only be called after the rest of the backup is successfully uploaded to S3. Returns an error upon failure.
func (*Bundle) NewTarBall ¶
func (b *Bundle) NewTarBall()
func (*Bundle) TarWalker ¶
TarWalker walks files provided by the passed in directory and creates compressed tar members labeled as `part_00i.tar.lzo`.
To see which files and directories are skipped, please consult 'structs.go'. Excluded directories will be created but their contents will not be included in the tar bundle.
type EmptyWriteIgnorer ¶
type EmptyWriteIgnorer struct {
io.WriteCloser
}
EmptyWriteIgnorer handles 0 byte write in LZ4 package to stop pipe reader/writer from blocking.
type ExponentialTicker ¶
type ExponentialTicker struct { MaxRetries int MaxWait float64 // contains filtered or unexported fields }
ExponentialTicker is used for exponential backoff for uploading to S3. If the max wait time is reached, retries will occur after max wait time intervals up to max retries.
func NewExpTicker ¶
func NewExpTicker(retries int, wait float64) *ExponentialTicker
NewExpTicker creates a new ExponentialTicker with configurable max number of retries and max wait time.
func (*ExponentialTicker) Update ¶
func (et *ExponentialTicker) Update()
Update increases running count of retries by 1 and exponentially increases the wait time until the max wait time is reached.
type FileTarInterpreter ¶
type FileTarInterpreter struct {
NewDir string
}
FileTarInterpreter extracts input to disk.
type Lz4CascadeClose ¶
type Lz4CascadeClose struct { *lz4.Writer Underlying io.WriteCloser }
Lz4CascadeClose bundles multiple closures into one function. Calling Close() will close the lz4 and underlying writer.
func (*Lz4CascadeClose) Close ¶
func (lcc *Lz4CascadeClose) Close() error
Close returns the first encountered error from closing the lz4 writer or the underlying writer.
type Lz4Error ¶
type Lz4Error struct {
// contains filtered or unexported fields
}
Lz4Error is used to catch specific errors from Lz4PipeWriter when uploading to S3. Will not retry upload if this error occurs.
type LzPipeWriter ¶
LzPipeWriter allows for flexibility of using compressed output. Input is read and compressed to a pipe reader.
func (*LzPipeWriter) Compress ¶
func (p *LzPipeWriter) Compress()
Compress compresses input to a pipe reader. Output must be used or pipe will block.
type NoMatchAvailableError ¶
type NoMatchAvailableError struct {
// contains filtered or unexported fields
}
NoMatchAvailableError is used to signal no match found in string.
func (NoMatchAvailableError) Error ¶
func (e NoMatchAvailableError) Error() string
type RaskyReader ¶
RaskyReader handles cases when the Rasky lzo package crashes. Occurs if byte size is too small (1-5).
type ReaderMaker ¶
type ReaderMaker interface { Reader() (io.ReadCloser, error) Format() string Path() string }
ReaderMaker is the generic interface used by extract. It allows for ease of handling different file formats.
type S3ReaderMaker ¶
S3ReaderMaker handles cases where backups need to be uploaded to S3.
func (*S3ReaderMaker) Format ¶
func (s *S3ReaderMaker) Format() string
func (*S3ReaderMaker) Path ¶
func (s *S3ReaderMaker) Path() string
func (*S3ReaderMaker) Reader ¶
func (s *S3ReaderMaker) Reader() (io.ReadCloser, error)
Reader creates a new S3 reader for each S3 object.
type S3TarBall ¶
type S3TarBall struct {
// contains filtered or unexported fields
}
S3TarBall represents a tar file that is going to be uploaded to S3.
func (*S3TarBall) CloseTar ¶
CloseTar closes the tar writer, flushing any unwritten data to the underlying writer before also closing the underlying writer.
func (*S3TarBall) Finish ¶
Finish writes an empty .json file and uploads it with the the backup name. Finish will wait until all tar file parts have been uploaded. The json file will only be uploaded if all other parts of the backup are present in S3. an alert is given with the corresponding error.
func (*S3TarBall) SetUp ¶
SetUp creates a new tar writer and starts upload to S3. Upload will block until the tar file is finished writing. If a name for the file is not given, default name is of the form `part_....tar.lz4`.
func (*S3TarBall) StartUpload ¶
func (s *S3TarBall) StartUpload(name string) io.WriteCloser
StartUpload creates a lz4 writer and runs upload in the background once a compressed tar member is finished writing.
type S3TarBallMaker ¶
type S3TarBallMaker struct { BaseDir string Trim string BkupName string Tu *TarUploader // contains filtered or unexported fields }
S3TarBallMaker creates tarballs that are uploaded to S3.
func (*S3TarBallMaker) Make ¶
func (s *S3TarBallMaker) Make() TarBall
Make returns a tarball with required S3 fields.
type TarBall ¶
type TarBall interface { SetUp(args ...string) CloseTar() error Finish() error BaseDir() string Trim() string Nop() bool Number() int Size() int64 SetSize(int64) Tw() *tar.Writer }
A TarBall represents one tar file.
type TarBallMaker ¶
type TarBallMaker interface {
Make() TarBall
}
TarBallMaker is used to allow for flexible creation of different TarBalls.
type TarBundle ¶
type TarBundle interface { NewTarBall() GetTarBall() TarBall }
TarBundle represents one completed directory.
type TarInterpreter ¶
TarInterpreter behaves differently for different file types.
type TarUploader ¶
type TarUploader struct { Upl s3manageriface.UploaderAPI MaxRetries int MaxWait float64 Success bool // contains filtered or unexported fields }
TarUploader contains fields associated with uploading tarballs. Multiple tarballs can share one uploader. Must call CreateUploader() in 'upload.go'.
func NewTarUploader ¶
func NewTarUploader(svc s3iface.S3API, bucket, server, region string, r int, w float64) *TarUploader
NewTarUploader creates a new tar uploader without the actual S3 uploader. CreateUploader() is used to configure byte size and concurrency streams for the uploader.
func (*TarUploader) Finish ¶
func (tu *TarUploader) Finish()
Finish waits for all waiting parts to be uploaded. If an error occurs, prints alert to stderr.
type TimeSlice ¶
type TimeSlice []BackupTime
TimeSlice represents a backup and its last modified time.
type UnsetEnvVarError ¶
type UnsetEnvVarError struct {
// contains filtered or unexported fields
}
UnsetEnvVarError is used to indicate required environment variables for WAL-G.
func (UnsetEnvVarError) Error ¶
func (e UnsetEnvVarError) Error() string
type UnsupportedFileTypeError ¶
UnsupportedFileTypeError is used to signal file types that are unsupported by WAL-G.
func (UnsupportedFileTypeError) Error ¶
func (e UnsupportedFileTypeError) Error() string
type ZeroReader ¶
type ZeroReader struct{}
ZeroReader generates a slice of zeroes. Used to pad tar in cases where length of file changes.