/go-vss

Go interface to the Windows Volume Shadow Copy Service

Primary LanguageGoMIT LicenseMIT

VSS (Volume Shadow Copy Service) API Wrapper

This project provides a Go wrapper for the Windows Volume Shadow Copy Service (VSS) API. It allows you to create, manage, and delete VSS snapshots programmatically.

Features

  • Initialize and manage VSS snapshots.
  • Handle VSS errors with custom error types.
  • Support for various VSS contexts and backup types.
  • Query and manipulate VSS snapshot properties.

Requirements

  • Windows operating system.
  • Go 1.20 or later.

Installation

To use this package, you need to install the required dependencies:

go get github.com/8ugMak1r/go-vss

Usage

Create a VSS Snapshot

To create a VSS snapshot, use the NewVssSnapshot function:

snapshotSet, err := NewVssSnapshot("C:\\", 60, vss.DefaultOption)
if err != nil {
    log.Fatalf("Failed to create VSS snapshot: %v", err)
}

snapshotSet, err := NewVssSnapshots([]string{"C:\\", "D:\\"}, 60, vss.DefaultOption)
if err != nil {
    log.Fatalf("Failed to create VSS snapshot: %v", err)
}

Expose the snapshot to a specified volume

exposeVolume := "Z:"
err = snapshotSet.Snapshots[0].Expose(exposeVolume)
if err != nil {
    log.Fatalf("Failed to expose VSS snapshot: %v", err)
}
log.Printf("Snapshot exposed at: %s", exposedPath)

Delete VSS SnapshotSet

To delete a VSS snapshot, call the Delete method on the VssSnapshot or VssSnapshotSet object:

err := snapshotSet.Delete()
if err != nil {
    log.Fatalf("Failed to delete VSS snapshot: %v", err)
}

Error Handling

The package provides custom error types for handling VSS errors:

  • vssError: Represents an error returned from the VSS API.
  • vssTextError: Represents a textual error message.

Example:

if err != nil {
    if vssErr, ok := err.(*vssError); ok {
        log.Printf("VSS error: %s", vssErr.Error())
    } else {
        log.Printf("Error: %v", err)
    }
}

References

  1. Restic PR #2274 - GitHub
  2. VSS Volume Snapshot Attributes - Microsoft Docs
  3. Volume Shadow Snapshot (VSS) Format - libyal
  4. Volume Shadow Copy BackupComplete and VSS_E_BAD_STATE - Narkive
  5. Difference between VSS Full Backup and VSS Copy - Microsoft Tech Community

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.