fs_snapshot

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package fs_snapshot provides the ability to take filesystem snapshots. For now, only Windows is supported.

Index

Constants

View Source
const (
	StatePending mountPointState = iota
	StateSuccess
	StateFailed
)
View Source
const (
	OutputLevel = iota
	InfoLevel
	DetailsLevel
	TraceLevel
)
View Source
const DefaultIP = "localhost"
View Source
const DefaultPort = 33721

Variables

View Source
var ErrNotSupportedInThisOS = errors.New("snapshots not supported in this OS")
View Source
var ErrSnapshotFailedInPreviousAttempt = errors.New("snapshot failed in a previous attempt")

Functions

func CurrentUserCanCreateSnapshots

func CurrentUserCanCreateSnapshots(infoCb InfoMessageCallback) (bool, error)

CurrentUserCanCreateSnapshots returns information if the current user can create snapshots

func EnableSnapshotsForUser

func EnableSnapshotsForUser(username string, infoCb InfoMessageCallback) error

EnableSnapshotsForUser enables the current user to run snapshots. This generally must be run from a prompt with elevated privileges (root or administrator).

func StartServer

func StartServer(snapshoter Snapshoter, cfg *ServerConfig) error

Types

type BackupConfig

type BackupConfig struct {
	ProviderID string

	Timeout time.Duration

	// Simple - try to do it as simple as possible, but not simpler.
	// In Windows this means do not use VSS Writers.
	Simple bool

	// If set, overrides the info callback from the snapshoter
	InfoCallback InfoMessageCallback
}

type Backuper

type Backuper interface {
	// TryToCreateTemporarySnapshot returns the snapshoted directory volume if a snapshot could be made,
	// or the original directory otherwise.
	// If the directory is not yet available as a snapshot, a snapshot is created.
	// If the directory is inside an existing snapshot, the snapshot is re-used.
	// An error is returned iff some problem occurred while creating the snapshot, but not
	// if the directory does not support snapshots.
	TryToCreateTemporarySnapshot(directory string) (string, *Snapshot, error)

	// Close frees all resources.
	Close()
}

Backuper is a class that allows easy temporary snapshot creation. All snapshots created will be deleted when calling Close.

type ConnectionType

type ConnectionType int
const (
	LocalOrServer ConnectionType = iota
	LocalOnly
	ServerOnly
)

type InfoMessageCallback

type InfoMessageCallback func(level MessageLevel, format string, a ...interface{})

type MessageLevel

type MessageLevel int

type Provider

type Provider struct {
	ID      string
	Name    string
	Version string
	Type    string
}

type ServerConfig

type ServerConfig struct {
	// IP to listen on. Use "0.0.0.0" to listen on all interfaces. Default is "localhost".
	IP string

	// Port to listen on.
	Port int

	// InactivityTime to stop the server, if this is > 0.
	InactivityTime time.Duration

	InfoCallback InfoMessageCallback
}

func (*ServerConfig) Address

func (cfg *ServerConfig) Address() string

type Snapshot

type Snapshot struct {
	ID           string
	OriginalDir  string
	SnapshotDir  string
	CreationTime time.Time
	Set          *SnapshotSet
	Provider     *Provider
	State        string
	Attributes   string
}

type SnapshotSet

type SnapshotSet struct {
	ID                      string
	CreationTime            time.Time
	SnapshotCountOnCreation int
	Snapshots               []*Snapshot
}

type Snapshoter

type Snapshoter interface {
	// ListProviders list all provider available
	// filterID: filter by id if != ""
	ListProviders(filterID string) ([]*Provider, error)

	// ListSets list all snapshot sets available
	// filterID: filter by id if != ""
	ListSets(filterID string) ([]*SnapshotSet, error)

	// ListSnapshots list all snapshots available
	// filterID: filter by id if != ""
	ListSnapshots(filterID string) ([]*Snapshot, error)

	// SimplifyID simplifies the snapshot, set and provider IDs, if possible
	SimplifyID(id string) string

	// DeleteSet deletes one snapshot set and all its snapshots.
	// Returns true if snapshot was found and deleted, false if it was not found and an
	// error if something went wrong.
	DeleteSet(id string, force bool) (bool, error)

	// DeleteSnapshot deletes one snapshot
	// Returns true if snapshot was found and deleted, false if it was not found and an
	// error if something went wrong.
	DeleteSnapshot(id string, force bool) (bool, error)

	// ListMountPoints lists all mount points inside a volume.
	ListMountPoints(volume string) ([]string, error)

	// StartBackup creates a Backuper to allow easy backup creation.
	StartBackup(cfg *BackupConfig) (Backuper, error)

	// Close frees all resources.
	Close()
}

func NewSnapshoter

func NewSnapshoter(cfg *SnapshoterConfig) (Snapshoter, error)

NewSnapshoter creates a new snapshoter. In case of error a null snapshoter is returned, so you can use it without problem.

type SnapshoterConfig

type SnapshoterConfig struct {
	ConnectionType ConnectionType
	ServerIP       string
	ServerPort     int
	InfoCallback   InfoMessageCallback
}

Directories

Path Synopsis
internal
rpc

Jump to

Keyboard shortcuts

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