config

package
v0.0.0-...-244d010 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: ISC Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBaseConfigDir

func DefaultBaseConfigDir() (out string, err error)

DefaultBaseConfigDir returns the local file system path to find configuration and data files specific to the application. It's based on the XDG base directory spec for the host system.

func EncodeTOML

func EncodeTOML(w io.Writer, in any) error

EncodeTOML formats in to TOML and writes to w.

func Init

func Init(inConfigDir string) (configDir string, err error)

Init ensures that the application configuration directory structure is set up with an expected layout and access modes are restricted. It returns the path to the base configuration directory.

Types

type Datastore

type Datastore struct {
	// Defaults are any configuration values specific to the Datastore.
	// Unspecified fields will be merged in from top-level Defaults.
	Defaults     Defaults               `toml:"defaults"`
	Sources      []Source               `toml:"sources"`
	Destinations map[string]Destination `toml:"destinations"`
	// Name is not specified in the config file, but is implied by the
	// Datastore's place in the config data. The intention is to ease
	// maintenance of the configuration file.
	Name string `toml:"-"`
	// contains filtered or unexported fields
}

Datastore is an abstraction for source paths to backup and the destination restic repositories.

func SelectDatastores

func SelectDatastores(datastores map[string]Datastore, names, destNames []string) (out []Datastore)

SelectDatastores filters for Datastores with an exactly-matching Name in names, or have a Destination exactly matching one in destNames. If names is length 0, then the name of the Datastore is not considered. If destNames is length 0, then the name of the Destination is not considered either.

type Defaults

type Defaults struct {
	PasswordConfig *PasswordConfig `toml:"password-config"`
	Restic         *ResticDefaults `toml:"restic"`
}

Defaults defines configuration values.

type Destination

type Destination struct {
	// Name is not specified in the config file, but is implied by the
	// Destination's place in the config data. The intention is to ease
	// maintenance of the configuration file.
	Name string `toml:"-"`
	// Defaults are any configuration values specific to the Destination.
	// Unspecified fields will be merged in from the Datastore.
	Defaults Defaults `toml:"defaults"`
	// Path is the restic repository path.
	Path string `toml:"path"`
	// contains filtered or unexported fields
}

Destination is a restic repository.

func (*Destination) BuildFlags

func (d *Destination) BuildFlags(configDir string, subcmd string) ([]Flag, error)

BuildFlags merges in default config values and outputs a list of tuples representing the merged config.

func (*Destination) Merge

func (d *Destination) Merge() (out Defaults, err error)

Merge combines the Defaults from the config file's top-level Defaults into the Datastore's Defaults, and then combines that into the Destination's Defaults. Any config values specified for the Destination are not overridden by the same config value specified in the Datastore.

type Flag

type Flag struct{ Key, Val string }

type Params

type Params struct {
	Defaults   Defaults             `toml:"defaults"`
	Datastores map[string]Datastore `toml:"datastores"`
}

Params represents the entire config file after it's parsed.

func Parse

func Parse(r io.Reader) (out Params, err error)

Parse not only constructs Params from configuration file data, it also prepares some internal state necessary for merging data later on.

type PasswordConfig

type PasswordConfig struct {
	// Template is the password-command (a restic flag) to run. It is parsed by
	// package text/template from the golang standard library. Arguments may be
	// interjected into placeholders delimited by "{{" and "}}".
	Template *string `toml:"template"`
	// Args are positional arguments that may be referenced by placeholders in a
	// template string.
	Args []string `toml:"args"`
}

PasswordConfig is a specialized configuration type to manage the password-command flag for restic subcommands.

type ResticBackup

type ResticBackup struct {
	DryRun            *bool     `toml:"dry-run"`
	Exclude           *[]string `toml:"exclude"`
	ExcludeCaches     *bool     `toml:"exclude-caches"`
	ExcludeFile       *[]string `toml:"exclude-file"`
	ExcludeIfPresent  *[]string `toml:"exclude-if-present"`
	ExcludeLargerThan *string   `toml:"exclude-larger-than"`
	FilesFrom         *[]string `toml:"files-from"`
	FilesFromRaw      *[]string `toml:"files-from-raw"`
	FilesFromVerbatim *[]string `toml:"files-from-verbatim"`
	Force             *bool     `toml:"force"`
	Host              *string   `toml:"host"`
	Iexclude          *[]string `toml:"iexclude"`
	IexcludeFile      *[]string `toml:"iexclude-file"`
	IgnoreCtime       *bool     `toml:"ignore-ctime"`
	IgnoreInode       *bool     `toml:"ignore-inode"`
	OneFileSystem     *bool     `toml:"one-file-system"`
	Parent            *string   `toml:"parent"`
	Stdin             *bool     `toml:"stdin"`
	StdinFilename     *string   `toml:"stdin-filename"`
	Tag               *[]string `toml:"tag"`
	Time              *string   `toml:"time"` // is type string because "now" is accepted by restic.
	WithAtime         *bool     `toml:"with-atime"`
}

type ResticCheck

type ResticCheck struct {
	ReadData       *bool   `toml:"read-data"`
	ReadDataSubset *string `toml:"read-data-subset"`
	WithCache      *bool   `toml:"with-cache"`
}

type ResticDefaults

type ResticDefaults struct {
	// Global refers to any restic flags that are made available for any restic
	// subcommand. In restic's usage menus, they may appear as "global flags".
	Global    *ResticGlobal    `toml:"global"`
	Backup    *ResticBackup    `toml:"backup"`
	Check     *ResticCheck     `toml:"check"`
	LS        *ResticLS        `toml:"ls"`
	Snapshots *ResticSnapshots `toml:"snapshots"`
	Stats     *ResticStats     `toml:"stats"`
}

ResticDefaults are any default configuration values for restic subcommands. Asides from Global, which is configuration for shared flags, the struct fields here correspond to flags for a restic subcommand.

type ResticGlobal

type ResticGlobal struct {
	CACert          *string              `toml:"cacert"`
	CacheDir        *string              `toml:"cache-dir"`
	CleanupCache    *bool                `toml:"cleanup-cache"`
	Compression     *string              `toml:"compression"`
	InsecureTLS     *bool                `toml:"insecure-tls"`
	JSON            *bool                `toml:"json"`
	KeyHint         *string              `toml:"key-hint"`
	LimitDownload   *int                 `toml:"limit-download"`
	LimitUpload     *int                 `toml:"limit-upload"`
	NoCache         *bool                `toml:"no-cache"`
	NoLock          *bool                `toml:"no-lock"`
	Option          *[]map[string]string `toml:"option"`
	PackSize        *uint                `toml:"pack-size"`
	PasswordCommand *string              `toml:"password-command"`
	PasswordFile    *string              `toml:"password-file"`
	Quiet           *bool                `toml:"quiet"`
	Repo            *string              `toml:"repo"`
	RepositoryFile  *string              `toml:"repository-file"`
	TLSClientCert   *string              `toml:"tls-client-cert"`
	Verbose         *int                 `toml:"verbose"`
}

type ResticLS

type ResticLS struct {
	Host      *[]string `toml:"host"`
	Long      *bool     `toml:"long"`
	Path      *[]string `toml:"path"`
	Recursive *bool     `toml:"recursive"`
	Tag       *[]string `toml:"tag"`
}

type ResticSnapshots

type ResticSnapshots struct {
	Compact *bool     `toml:"compact"`
	GroupBy *[]string `toml:"group-by"`
	Host    *[]string `toml:"host"`
	Latest  *int      `toml:"latest"`
	Path    *[]string `toml:"path"`
	Tag     *[]string `toml:"tag"`
}

type ResticStats

type ResticStats struct {
	Host *[]string `toml:"host"`
	Mode *string   `toml:"mode"`
	Path *[]string `toml:"path"`
	Tag  *[]string `toml:"tag"`
}

type Source

type Source struct {
	// Path should be an absolute path to either a file or directory.
	Path string `toml:"path"`
}

Source is something to backup to a restic repository.

Jump to

Keyboard shortcuts

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