tarsnap

package module
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2022 License: MIT Imports: 15 Imported by: 2

README

tarsnap: A library interface to the tarsnap command-line tool

GoDoc

This repository contains a Go library providing a programmatic interface to the tarsnap command-line tool

Documentation

Overview

Package tarsnap is a library interface to the tarsnap command-line tool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Archive

type Archive struct {
	Name    string    `json:"name"`              // base.tag
	Base    string    `json:"base,omitempty"`    // base alone
	Tag     string    `json:"tag,omitempty"`     // .tag alone
	Created time.Time `json:"created,omitempty"` // in UTC
}

An Archive represents the name and metadata known about an archive.

type Archives

type Archives []Archive

Archives is a sortable slice of Archive values, ordered non-decreasing by creation time with ties broken by name.

func (Archives) Latest

func (a Archives) Latest(base string) (Archive, bool)

Latest returns the most recently-created archive with the given base. It is shorthand for LatestAsOf(base, time.Now()).

func (Archives) LatestAsOf

func (a Archives) LatestAsOf(base string, when time.Time) (Archive, bool)

LatestAsOf returns the most recently-created archive with the given base at or before the specified time.

func (Archives) Len

func (a Archives) Len() int

func (Archives) Less

func (a Archives) Less(i, j int) bool

func (Archives) Swap

func (a Archives) Swap(i, j int)

type Config

type Config struct {
	Tool     string `json:"tool"`
	Keyfile  string `json:"keyFile"`
	WorkDir  string `json:"workDir"`
	CacheDir string `json:"cacheDir"`

	// Optional settings flags to pass to the tarsnap command-line tool.
	Flags []Flag `json:"flags"`

	// If not nil, this function is called with each tarsnap command-line giving
	// the full argument list.
	CmdLog func(cmd string, args []string) `json:"-" yaml:"-"`
}

Config carries configuration settings to a tarsnap execution. A nil *Config is ready for use and provides default settings.

func (*Config) CacheTag added in v0.0.19

func (c *Config) CacheTag() (string, error)

CacheTag loads and returns the current cache sequence tag. If no cache directory is found, it returns "", nil.

func (*Config) Create

func (c *Config) Create(name string, opts CreateOptions) error

Create creates an archive with the specified name and options. It is equivalent in effect to "tarsnap -c -f name opts...".

func (*Config) Delete

func (c *Config) Delete(archives ...string) error

Delete deletes the specified archives.

func (*Config) Entries added in v0.1.1

func (c *Config) Entries(name string, f func(*Entry) error) (err error)

Entries calls f with each entry stored in the specified archive. If f reports an error, scanning stops and that error is returned to the caller of contents.

func (*Config) Extract

func (c *Config) Extract(name string, opts ExtractOptions) error

Extract extracts from an archive with the specified name and options. It is equivalent in effect to "tarsnap -x -f name opts...".

func (*Config) List

func (c *Config) List() (Archives, error)

List returns a list of the known archives. The resulting slice is ordered nondecreasing by creation time and by name.

func (*Config) RC added in v0.0.18

func (c *Config) RC() (RC, error)

RC loads and returns the resource configuration for c. If no configurations are found, an empty RC is returned without error.

func (*Config) Size

func (c *Config) Size(archives ...string) (*SizeInfo, error)

Size reports storage sizes for the specified archives. If no archives are specified only global stats are reported.

type CreateOptions

type CreateOptions struct {
	// Include these files or directories in the archive.
	// N.B. The tarsnap tool does not expand globs in include paths.
	Include []string `json:"include"`

	// Change to this directory before adding entries.
	WorkDir string `json:"workDir,omitempty"`

	// Modify names by these patterns, /old/new/[gps].
	Modify []string `json:"modify,omitempty"`

	// Exclude files or directories matching these glob patterns.
	Exclude []string `json:"exclude,omitempty"`

	// Follow symlinks (as tarsnap -H), storing the target rather than the link.
	FollowSymlinks bool `json:"followSymlinks" yaml:"follow-symlinks"`

	// Store access times (as tarsnap --store-atime). Not advised.
	StoreAccessTime bool `json:"storeAccessTime" yaml:"store-access-time"`

	// Preserve original pathnames (as tarsnap -P).
	PreservePaths bool `json:"preservePaths" yaml:"preserve-paths"`

	// If non-zero, set the creation time of the archive to this time.
	CreationTime time.Time `json:"creationTime,omitempty" yaml:"creation-time"`

	// Simulate creating archives rather than creating them.
	DryRun bool `json:"dryRun,omitempty" yaml:"dry-run"`
}

CreateOptions control the creation of archives.

type Entry added in v0.1.0

type Entry struct {
	Mode         os.FileMode
	Owner, Group int
	Size         int64     // in bytes
	ModTime      time.Time // in UTC
	Name         string
}

An Entry describes a single file or directory entry stored in an archive.

func (*Entry) String added in v0.1.0

func (e *Entry) String() string

type ExtractOptions

type ExtractOptions struct {
	// Include files matching these globs in the output.  If this is empty, the
	// whole archive is extracted except for any exclusions. If not, only the
	// files or directories specified are extracted, modulo exclusions.
	Include []string `json:"include"`

	// Exclude files or directories matching these patterns.
	Exclude []string `json:"exclude,omitempty"`

	// Change to this directory before extracting entries.
	WorkDir string `json:"workDir,omitempty"`

	// Restore permissions, owner, flags, and ACL.
	RestorePermissions bool `json:"restorePerms" yaml:"restore-perms"`

	// Ignore owner and group settings from the archive.
	IgnoreOwners bool `json:"ignoreOwners" yaml:"ignore-owners"`

	// Stop reading after the first match for each included path.
	FastRead bool `json:"fastRead" yaml:"fast-read"`

	// Resume an incomplete previous extraction, skipping files that already
	// match by size and timestamp in the destination.
	Resume bool `json:"resume" yaml:"resume"`
}

ExtractOptions control the extraction of archives.

type Flag added in v0.3.0

type Flag struct {
	Match string // if non-empty, only add if this argument is present
	Flag  string // the name of the flag, passed as --name

	// If not nil, the value of a flag must be a string, float64, or bool.
	// A string value will have environment variables ($VAR) expanded.
	//
	// If value is nil or true, the flag has no argument: --name
	// If value is false, the flag is sent as: --no-name
	// Otherwise the flag is sent as: --name value
	Value interface{}
}

A Flag describes a command-line flag for a tarsnap execution.

type RC added in v0.0.18

type RC map[string]string

An RC represents a collection of tarsnap configuration settings.

func LoadRC added in v0.0.18

func LoadRC(paths ...string) (RC, error)

LoadRC reads the contents of the specified RC files, parses and merges them in the order specified. If one of the paths is not found, it is skipped without error. If no paths are specified, an empty RC is returned without error.

func ParseRC added in v0.0.18

func ParseRC(r io.Reader) (RC, error)

ParseRC parses tarsnap configuration settings from r.

func (RC) Merge added in v0.0.18

func (rc RC) Merge(other RC)

Merge updates rc with the keys and values from other.

func (RC) Path added in v0.0.18

func (rc RC) Path(key string) (string, bool)

Path expands the value of the specified config key as a path, and reports whether it was set. Note that this expansion occurs even if the value for that key is not intended to be a path.

type Rule

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

A Rule is a path substitution rule, as defined for the "-s" flag of the tarsnap command-line tool.

See: https://www.tarsnap.com/man-tarsnap.1.html

func ParseRule

func ParseRule(s string) (*Rule, error)

ParseRule parses a substitution rule from a string argument. The input must have the form "/old/new/prg".

func (*Rule) Apply

func (r *Rule) Apply(s string) (string, bool)

Apply reports whether s matches the left-hand side of the rule and, if so, returns the result from applying the rule to the string.

type SizeInfo

type SizeInfo struct {
	All     *Sizes            // sizes for all archives known
	Archive map[string]*Sizes // sizes for individual archives
}

SizeInfo records storage size information for archives.

type Sizes

type Sizes struct {
	// Total bytes of original input
	InputBytes int64 `json:"inputBytes"`
	// Size after input compression
	CompressedBytes int64 `json:"compressedBytes"`
	// Size after deduplication
	UniqueBytes int64 `json:"uniqueBytes"`
	// Size after deduplication and compression
	CompressedUniqueBytes int64 `json:"compressedUniqueBytes"`
}

Sizes represents storage size values.

func (*Sizes) String

func (s *Sizes) String() string

Jump to

Keyboard shortcuts

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