vss

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: MPL-2.0 Imports: 14 Imported by: 0

README

vss

Go Reference Report card

Package vss exposes Windows Volume Shadow Copy API.

go get github.com/mxk/go-vss

Documentation

Rendered for windows/amd64

Overview

Package vss exposes Windows Volume Shadow Copy API.

Operations on shadow copies require the process to be running with elevated privileges of a user who is a member of the Administrators group. Returned errors will contain os.ErrPermission in their tree to indicate insufficient privileges.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(vol string) (string, error)

Create creates a new shadow copy of the specified volume and returns its ID. The volume can be specified by its drive letter (e.g. "C:"), mount point, or globally unique identifier (GUID) name (`\\?\Volume{GUID}\`). The returned error will contain os.ErrPermission if the current user does not have Administrators group privileges.

Example
// Create new shadow copy
id, err := Create("C:")
if err != nil {
	panic(err)
}
defer Remove(id)

// Get properties
sc, err := Get(id)
if err != nil {
	panic(err)
}

// Read contents
dir, err := os.ReadDir(sc.DeviceObject)
if err != nil {
	panic(err)
}
fmt.Printf("Contents of shadow copy %s:\n", sc.ID)
for _, e := range dir {
	fmt.Println(e.Type(), e.Name())
}
Output:

func CreateLink(link, vol string) (err error)

CreateLink creates a new shadow copy and symlinks it at the specified path. The shadow copy is removed if symlinking fails.

func IsShadowCopy added in v1.1.0

func IsShadowCopy(name string) (bool, error)

IsShadowCopy returns whether name is a path referring to the contents of a shadow copy.

func Remove

func Remove(name string) error

Remove removes a shadow copy by ID, DeviceObject, or symlink path. If a valid symlink is specified, then it is also removed.

func SplitVolume

func SplitVolume(name string) (vol, rel string, err error)

SplitVolume splits an absolute file path into its volume mount point and the path relative to the mount. For example, "C:\Windows\System32" returns "C:\" and "Windows\System32".

Types

type CreateError added in v1.2.0

type CreateError uint32

CreateError is an error code returned by Win32_ShadowCopy.Create. See: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/vsswmi/create-method-in-class-win32-shadowcopy#return-value

func (CreateError) Error added in v1.2.0

func (e CreateError) Error() string

Error implements the error interface.

func (CreateError) Unwrap added in v1.2.0

func (e CreateError) Unwrap() error

Unwrap implements errors.Unwrap interface.

type ShadowCopy

type ShadowCopy struct {
	ID           string
	InstallDate  time.Time
	DeviceObject string
	VolumeName   string
}

ShadowCopy is an instance of Win32_ShadowCopy class. See: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa394428(v=vs.85)

func Get

func Get(name string) (*ShadowCopy, error)

Get returns a ShadowCopy by ID, DeviceObject, or symlink path.

func List

func List(vol string) ([]*ShadowCopy, error)

List returns existing shadow copies. If vol is non-empty, only shadow copies for the specified volume are turned.

func (sc *ShadowCopy) Link(name string) error

Link creates a directory symlink pointing to the contents of the shadow copy.

func (*ShadowCopy) Remove

func (sc *ShadowCopy) Remove() error

Remove removes the shadow copy.

func (*ShadowCopy) VolumePath

func (sc *ShadowCopy) VolumePath() (string, error)

VolumePath returns the drive letter and/or folder where the shadow copy's original volume is mounted. If the volume is mounted at multiple locations, only the first one is returned.

Jump to

Keyboard shortcuts

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