Minimal Nim library for working with Windows Volume Shadow Copy Service (VSS). It offers a pragmatic high‑level API to enumerate, create, and delete snapshots, while exposing a thin low‑level FFI when needed.
This library is designed to pair with Nimewf by Nimager to enable VSS‑based EWF imaging on Windows.
src/nimvss.nim: Umbrella module that re‑exports everything forimport nimvss.src/nimvss/snapshot.nim: High‑level API to list/create/delete snapshots. Prefer using this.src/nimvss/winvss.nim: Minimal low‑level bindings for VSS COM interfaces (vssapi.dll).src/nimvss/privs.nim: Helpers to check/enable process token privileges (e.g.,SeBackupPrivilege).
- Windows (VSS is a Windows technology)
- Nim
>= 2.0.0, winim>= 3.9.0(seenimvss.nimble) - Administrator shell is recommended; some actions require privileges
Import the umbrella module to access both the high‑level API and helpers.
import nimvssUse VSS query context (VSS_CTX_ALL) to enumerate system snapshots.
import nimvss
var s = newVssSession(VSS_CTX_ALL)
let snaps = s.listSnapshots()
s.close()
for snap in snaps.values:
echo snap.info # multi‑line detailsimport nimvss
var s = newVssSession(persistent=false) # file‑share backup by default
let snap = s.createSnapshot("C:", openHandle=true)
s.close()
doAssert snap.state.handle != INVALID_HANDLE_VALUE
echo snap.info.devicePath # \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopyXXimport nimvss
var s = newVssSession(VSS_CTX_ALL)
let snaps = s.listSnapshots()
let first = snaps.values.toSeq()[0]
discard s.deleteSnapshot(first.info.id)
s.close()Some operations benefit from SeBackupPrivilege.
import nimvss
# Check/enable privilege
if not privs.havePrivilege("SeBackupPrivilege"):
discard privs.enablePrivilege("SeBackupPrivilege")These examples mirror the usage in tests/t_nimvss.nim.
newVssSession*(persistent=false, withWriters=false): VssSessionnewVssSession*(ctx: VSS_SNAPSHOT_CONTEXT): VssSessionclose*(session)listSnapshots*(session): Table[GUID, Snapshot]createSnapshot*(session; volume: string; openHandle=false): SnapshotdeleteSnapshot*(session; snapshotId: GUID|string; force=true): boolprivs.enablePrivilege*(name, enable=true): boolprivs.havePrivilege*(name): bool
- Stronger error handling and exceptions
- Expose/unexpose snapshots (drive letter or mount path)
- Writer support (gather metadata, prepare/commit, component selection)
- Raw device utilities (open existing device, sector size, length)
- More tests and examples
- As a local dependency: add this repo to your workspace and
import nimvssusingsrclayout. - Or
nimble developfrom the project root to make it available in your Nimble env. - Run example/tests on Windows:
nim c -r tests/t_nimvss.nim
MIT