basedirs

package
v5.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultSplits = 1
)

Variables

View Source
var (
	ErrInvalidBasePath  = errors.New("invalid base path")
	ErrNoBaseDirHistory = errors.New("no base dir history found")
)
View Source
var (
	ErrBadTSV = errors.New("bad TSV")
)
View Source
var ErrInvalidOwnersFile = errors.New("invalid owners file format")

Functions

func DateQuotaFull

func DateQuotaFull(history []History) (time.Time, time.Time)

DateQuotaFull returns our estimate of when the quota will fill based on the history of usage over time. Returns date when size full, and date when inodes full.

Returns a zero time value if the estimate is infinite.

func MergeDBs

func MergeDBs(pathA, pathB, outputPath string) (err error)

MergeDBs merges the basedirs.db database at the given A and B paths and creates a new database file at outputPath.

Types

type BaseDirReader

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

BaseDirReader is used to read the information stored in a BaseDir database.

func NewReader

func NewReader(dbPath, ownersPath string) (*BaseDirReader, error)

NewReader returns a BaseDirReader that can return the summary information stored in a BaseDir database. It takes an owners file (gid,name csv) to associate groups with their owners in certain output.

func (*BaseDirReader) Close

func (b *BaseDirReader) Close() error

func (*BaseDirReader) GroupSubDirUsageTable

func (b *BaseDirReader) GroupSubDirUsageTable(gid uint32, basedir string, age summary.DirGUTAge) (string, error)

GroupSubDirUsageTable returns GroupSubDirs() information formatted with the following tab separated columns:

base_directory_path sub_directory num_files size last_modified filetypes

Any error returned is from GroupSubDirs().

func (*BaseDirReader) GroupSubDirs

func (b *BaseDirReader) GroupSubDirs(gid uint32, basedir string, age summary.DirGUTAge) ([]*SubDir, error)

GroupSubDirs returns a slice of SubDir, one for each subdirectory of the given basedir, owned by the given group. If basedir directly contains files, one of the SubDirs will be for ".".

func (*BaseDirReader) GroupUsage

func (b *BaseDirReader) GroupUsage(age summary.DirGUTAge) ([]*Usage, error)

GroupUsage returns the usage for every GID-BaseDir combination in the database.

func (*BaseDirReader) GroupUsageTable

func (b *BaseDirReader) GroupUsageTable(age summary.DirGUTAge) (string, error)

GroupUsageTable returns GroupUsage() information formatted with the following tab separated columns:

group_name owner_name directory_path last_modified (number of days ago) used size (used bytes) quota size (maximum allowed bytes) used inodes (number of files) quota inodes (maximum allowed number of bytes) warning ("OK" or "Not OK" if quota is estimated to have run out in 3 days)

Any error returned is from GroupUsage().

func (*BaseDirReader) History

func (b *BaseDirReader) History(gid uint32, path string) ([]History, error)

History returns a slice of History values for the given gid and path, one value per Date the information was calculated.

func (*BaseDirReader) SetMountPoints

func (b *BaseDirReader) SetMountPoints(mountpoints []string)

SetMountPoints can be used to manually set your mountpoints, if the automatic discovery of mountpoints on your system doesn't work.

func (*BaseDirReader) UserSubDirUsageTable

func (b *BaseDirReader) UserSubDirUsageTable(uid uint32, basedir string, age summary.DirGUTAge) (string, error)

UserSubDirUsageTable returns UserSubDirs() information formatted with the following tab separated columns:

base_directory_path sub_directory num_files size last_modified filetypes

Any error returned is from UserSubDirUsageTable().

func (*BaseDirReader) UserSubDirs

func (b *BaseDirReader) UserSubDirs(uid uint32, basedir string, age summary.DirGUTAge) ([]*SubDir, error)

UserSubDirs returns a slice of SubDir, one for each subdirectory of the given basedir, owned by the given user. If basedir directly contains files, one of the SubDirs will be for ".".

func (*BaseDirReader) UserUsage

func (b *BaseDirReader) UserUsage(age summary.DirGUTAge) ([]*Usage, error)

UserUsage returns the usage for every UID-BaseDir combination in the database.

func (*BaseDirReader) UserUsageTable

func (b *BaseDirReader) UserUsageTable(age summary.DirGUTAge) (string, error)

UserUsageTable returns UserUsage() information formatted with the following tab separated columns:

user_name owner_name (always blank) directory_path last_modified (number of days ago) used size (used bytes) quota size (always 0) used inodes (number of files) quota inodes (always 0) warning (always "OK")

Any error returned is from UserUsage().

type BaseDirs

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

BaseDirs is used to summarise disk usage information by base directory and group or user.

func NewCreator

func NewCreator(dbPath string, c Config, tree *dguta.Tree, quotas *Quotas) (*BaseDirs, error)

NewCreator returns a BaseDirs that lets you create a database summarising usage information by base directory, taken from the given tree and quotas.

Choose splits and minDirs based on how many directories deep you expect data for different groups/users to appear. Eg. if your file structure is `/mounts/[group name]`, that's 2 directories deep and splits 1, minDirs 2 might work well. If it's 5 directories deep, splits 4, minDirs 4 might work well.

func (*BaseDirs) CreateDatabase

func (b *BaseDirs) CreateDatabase() error

CreateDatabase creates a database containing usage information for each of our groups and users by calculated base directory.

func (*BaseDirs) SetMountPoints

func (b *BaseDirs) SetMountPoints(mountpoints []string)

SetMountPoints can be used to manually set your mountpoints, if the automatic discovery of mountpoints on your system doesn't work.

type Config

type Config []ConfigAttrs

func ParseConfig

func ParseConfig(r io.Reader) (Config, error)

ParseConfig reads basedirs configuration, which is a TSV in the following format:

PREFIX SPLITS MINDIRS.

type ConfigAttrs

type ConfigAttrs struct {
	Prefix  string
	Score   int
	Splits  int
	MinDirs int
}

type DBInfo

type DBInfo struct {
	GroupDirCombos    int
	GroupMountCombos  int
	GroupHistories    int
	GroupSubDirCombos int
	GroupSubDirs      int
	UserDirCombos     int
	UserSubDirCombos  int
	UserSubDirs       int
}

DBInfo holds summary information about the database file produced by NewCreator().CreateDatabase().

func Info

func Info(dbPath string) (*DBInfo, error)

Info returns summary information about the given basedirs database file itself.

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type GroupCache

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

func NewGroupCache

func NewGroupCache() *GroupCache

func (*GroupCache) GroupName

func (g *GroupCache) GroupName(gid uint32) string

type History

type History struct {
	Date        time.Time
	UsageSize   uint64
	QuotaSize   uint64
	UsageInodes uint64
	QuotaInodes uint64
}

History contains actual usage and quota max information for a particular point in time.

type Quotas

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

Quotas stores information about group disk quotas.

func ParseQuotas

func ParseQuotas(path string) (*Quotas, error)

ParseQuotas parses the given quotas csv file (gid,disk,quota) and returns a Quotas struct.

func (*Quotas) Get

func (q *Quotas) Get(gid uint32, path string) (uint64, uint64)

Get returns the quota (in bytes) for the given gid for the given disk location. If path isn't a sub-directory of a disk in the csv file used to create this Quotas, or gid doesn't have a quota on that disk, returns 0.

type SubDir

type SubDir struct {
	SubDir       string
	NumFiles     uint64
	SizeFiles    uint64
	LastModified time.Time
	FileUsage    UsageBreakdownByType
}

SubDir contains information about a sub-directory of a base directory.

type Usage

type Usage struct {
	GID         uint32
	UID         uint32
	GIDs        []uint32
	UIDs        []uint32
	Name        string // the group or user name
	Owner       string
	BaseDir     string
	UsageSize   uint64
	QuotaSize   uint64
	UsageInodes uint64
	QuotaInodes uint64
	Mtime       time.Time
	// DateNoSpace is an estimate of when there will be no space quota left.
	DateNoSpace time.Time
	// DateNoFiles is an estimate of when there will be no inode quota left.
	DateNoFiles time.Time
	Age         summary.DirGUTAge
}

Usage holds information summarising usage by a particular GID/UID-BaseDir.

Only one of GID or UID will be set, and Owner will always be blank when UID is set. If GID is set, then UIDs will be set, showing which users own files in the BaseDir. If UID is set, then GIDs will be set, showing which groups own files in the BaseDir.

type UsageBreakdownByType

type UsageBreakdownByType map[summary.DirGUTAFileType]uint64

UsageBreakdownByType is a map of file type to total size of files in bytes with that type.

func (UsageBreakdownByType) String

func (u UsageBreakdownByType) String() string

type UserCache

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

func NewUserCache

func NewUserCache() *UserCache

func (*UserCache) UserName

func (u *UserCache) UserName(uid uint32) string

Jump to

Keyboard shortcuts

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