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.
- 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.
- Windows operating system.
- Go 1.20 or later.
To use this package, you need to install the required dependencies:
go get github.com/8ugMak1r/go-vssTo 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)
}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)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)
}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)
}
}- Restic PR #2274 - GitHub
- VSS Volume Snapshot Attributes - Microsoft Docs
- Volume Shadow Snapshot (VSS) Format - libyal
- Volume Shadow Copy BackupComplete and VSS_E_BAD_STATE - Narkive
- Difference between VSS Full Backup and VSS Copy - Microsoft Tech Community
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.