Windows Server

Shadow Copy from the Command Line

I was recently building some scripts to alternate shadow copy storage locations (long story). In so doing, I found that pretty much anything I would normally do in the GUI is exposed at the command prompt using the vssadmin command. The first and one of the most important things that you can do is list settings. This includes the following:

  • providers – lists components that can create and maintain shadow copies
  • shadows – lists shadow copies
  • shadowstorage – lists storage that can be used for shadow copies
  • volumes – lists volumes that have shadow copy enabled
  • writers – lists registered components of applications that store persistent information on a volume with shadow copy enabled

You can create a shadow copy of a volume using the vssadmin command along with the create shadow verb. You would also need to specify which drive you will be creating a shadow copy of using the /for option. For example:
vssadmin create shadow /for=C:

Once you have created a shadow copy you can then add more storage to it using the vssadmin add shadowstorage command. Here, you’d indicate the volume to enable shadow copy /for and then the volume to put the shadow copy storage /on and finally the maximum size with /maxsize, as follows:
vssadmin add shadowstorage /for=c: /on=d: /maxsize=1tb

Once you have storage, you can also resize it. To do so use the resize verb and then mimic what you did previously, when adding shadowstorage but replacing the maxsize variable with a new number. For example:
vssadmin resize shadowstorage /for=c: /on=d: /maxsize=100gb

In addition to being able to resize the storage you can also delete it using the delete verb along with shadowstorage. For example:
vssadmin delete shadowstorage /for=c: /on=d:

And finally you can also delete shadows themselves
vssadmin delete shadows /for=c: /all

Or to just delete the oldest:
vssadmin delete shadows /for=c: /oldest

Or finally, to just delete one from the list of shadows (where the X’s are replaced with your shadow id obtained using the list shadows):
vssadmin delete shadows /for=c: /shadow=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

Still can’t seem to make it work with Samba on Mac OS X, but that’s another story for another day…  🙂