Windows: Backup with diskshadow.exe

Hello,

Windows Server 2008 and alter version are shipped with a tool called diskshadow. This program can be used to create snapshots of disks and expose them as Folder or as DriveLetter means files are in a consistent state and you can save openfiles.

Some examples. Starting diskshadow. It accept a  parameter /l  for a logfile. And a Parameter /s for a (diskshadow) script file to execute. diskshadow has the same “look and feel” like diskpart 🙂  and start with a prompt:

C:\Windows\system32>diskshadow
Microsoft DiskShadow version 1.0
Copyright (C) 2013 Microsoft Corporation
On computer:  windev,  12.06.2014 20:28:33
DISKSHADOW>

First set diskshadow in defined state with reset

DISKSHADOW> reset

Write the metadata to a file if you want to transfer the snapshot to another computer

set metadata d:\temp\vssmeta.cab

Set the context in which the snapshot will be used. CLIENTACCESSIBLE. The snapshot would be shown in the Previous version tab of the explore.

DISKSHADOW> set CONTEXT CLIENTACCESSIBLE

set context PERSISTENT. The snapshot is created persistent. You have to deleted the snapshot after backup. Use the PERSISTENT option if you want to expose the snapshot as drive letter or to a folder.

DISKSHADOW> set CONTEXT PERSISTENT

snapshots in context VOLATILE just exists for the current diskshadow session and are deleted at exit. You can not expose such snaps. You have to access them by the harddisk device path i.e. \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy3

If do not need a consistent snapshot of the volumes you can append the NOWRITERS option.

DISKSHADOW> set CONTEXT PERSISTENT NOWRITERS

Start the backup session

DISKSHADOW> begin backup

Add volumes for the backup set either by Driveletter or the MountPoint of disk and define an ALIAS. With  Driveletter

DISKSHADOW> Add volume C: ALIAS DRIVE_C

Or if you have mounted a disk to a folder, the folder as Parameter

DISKSHADOW> Add volume D:\mnt\disk0 ALIAS DRIVE_0

Add with no parameter shows all already included volume with their Aliases

If you have an Application (SQL, Hyper-V, ISS)  running on one of these disks which has installed an VSS Writer in the system you can tell diskshadow to verify that this writer is used for creating the snapshot, to ensure the backup of these application is in an consistent state. This lists all installed writers. As example the output of the Hyper-V VSS writer.

DISKSHADOW> list writers STATUS

        ......
        * WRITER "Microsoft Hyper-V VSS Writer"
                - Status: 1 (VSS_WS_STABLE)
                - Writer failure code: 0x00000000 (S_OK)
                - Writer ID: {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}
                - Writer instance ID: {5f457891-1e46-4065-bd1d-09517d8618ed}
        .......

Use the DETAILED option to see which files are by which writer affected.

DISKSHADOW> list writers DETAILED

If you want to Backup some Hyper-V virtual maschines this makes sence:

DISKSHADOW> writer verify {66841cd4-6ded-4f4b-8f17-fd23f8ddc3de}

Create the snapshot

DISKSHADOW> create

To see a list of all snapshots type

DISKSHADOW> list shadows all

Expose the snapshots. As Driveletter

DISKSHADOW> expose %DRIVE_0% S:

or as mount point. The folder in which the snapshot should be mounted must exists.

DISKSHADOW> expose %DRIVE_C% D:\mnt\snapdriveC

Now you can do some operations against the mount point. For example create a D:\backup.cmd file with a robocopy inside

@echo off
robocopy /S D:\mnt\snapdriveC \\targetcomputer\backupshare

and start it from diskshadow

DISKSHADOW> exec D:\backup.cmd

After backup clean up your workplace. Unmount your snapshots

DISKSHADOW> unexpose D:\mnt\snapdriveC
DISKSHADOW> unexpose S:

or by Alias

DISKSHADOW> unexpose %DRIVE_0%
DISKSHADOW> unexpose %DRIVE_C%

and delete the snapshots

delete shadows VOLUME %DRIVE_C%
delete shadows VOLUME %DRIVE_0%

leave backup session

DISKSHADOW> end backup

And exit diskshadow
DISKSHADOW> exit

Michael

Advertisment to support michlstechblog.info

2 thoughts on “Windows: Backup with diskshadow.exe”

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.