basedirs

package
v4.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidBasePath  = errors.New("invalid base path")
	ErrNoBaseDirHistory = errors.New("no base dir history found")
)
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 added in v4.5.0

func MergeDBs(pathA, pathB, outputPath string) 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) (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) ([]*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() ([]*Usage, error)

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

func (*BaseDirReader) GroupUsageTable

func (b *BaseDirReader) GroupUsageTable() (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) (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) ([]*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() ([]*Usage, error)

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

func (*BaseDirReader) UserUsageTable

func (b *BaseDirReader) UserUsageTable() (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, tree *dgut.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.

func (*BaseDirs) CalculateForGroup

func (b *BaseDirs) CalculateForGroup(gid uint32) (dgut.DCSs, error)

CalculateForGroup calculates all the base directories for the given group.

func (*BaseDirs) CalculateForUser

func (b *BaseDirs) CalculateForUser(uid uint32) (dgut.DCSs, error)

CalculateForUser calculates all the base directories for the given user.

func (*BaseDirs) CreateDatabase

func (b *BaseDirs) CreateDatabase(historyDate time.Time) error

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

Provide a time that will be used as the date when appending to the historical data.

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 Error

type Error string

func (Error) Error

func (e Error) Error() string

type GroupCache

type GroupCache map[uint32]string

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
}

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.DirGUTFileType]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 map[uint32]string

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