Documentation ¶
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 ¶
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 ¶ added in v1.0.0
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
IsShadowCopy returns whether name is a path referring to the contents of a shadow copy.
func Remove ¶
Remove removes a shadow copy by ID, DeviceObject, or symlink path. If a valid symlink is specified, then it is also removed.
func SplitVolume ¶
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 ¶
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 (*ShadowCopy) Link ¶
func (sc *ShadowCopy) Link(name string) error
Link creates a directory symlink pointing to the contents of 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.