Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a shadow copy using the "Backup" context in a PowerShell

I am in the process of writing a PowerShell script for backing up a Windows computer using rsync. To this end, I am attempting to use WMI from said script to create a non-persistent Shadow copy with writer participation (as is apparently recommended for backups).

I found out from another question (Accessing Volume Shadow Copy (VSS) Snapshots from powershell) a way to create a shadow copy in general, but the example given there uses "ClientAccessible" as the context parameter, which results in the creation of a persistent Shadow Copy, without writer participation.

While searching for a solution, I have found that I could use the following command to obtain a list of contexts, which I assume are understood by WMI:

Get-WmiObject win32_shadowcontext | Out-GridView 

It does the list have a context named "Backup", which is conveniently what I want. I proceeded to attempt creating a non-persistent shadow copy using that context:

$shadow = (Get-WmiObject -list win32_shadowcopy).Create("C:\", "Backup") 

However, this seems to fail and the content of the $shadow variable is set to

ReturnValue      : 5 ShadowID         : {00000000-0000-0000-0000-000000000000} 

According to the relevant documentation (Create method of the Win32_ShadowCopy class), the return value means "Unsupported shadow copy context."

I couldn't find any relevant documentation as to why this context is unsupported or whether it is possible to use it at all. I have also tried the "FileShareBackup" and "AppRollback" contexts without success.

I assume I am either missing something obvious, or that for some reason, WMI really doesn't support anything else than "clientAccessible" when creating shadow copies, or that this is OS-dependent (I am testing this on Windows 7, 64-bit)

How can I get this to work?

like image 725
Julien Picalausa Avatar asked Jul 11 '13 19:07

Julien Picalausa


People also ask

How do I create a shadow copy in powershell?

To do this, right-click on the volume and go to Properties and then click on the Shadow Copies tab. This will bring you to a window where you can then click on Enable to create the first snapshot.

What is shadowing backup?

Shadow Copy (also known as Volume Snapshot Service, Volume Shadow Copy Service or VSS) is a technology included in Microsoft Windows that can create backup copies or snapshots of computer files or volumes, even when they are in use. It is implemented as a Windows service called the Volume Shadow Copy service.

How do I create a shadow copy?

Click Start, right-click My Computer, and then click Manage. Right-click Shared Folders, point to All Tasks, and then click Configure Shadow Copies. In the Select a volume list, click the drive that contains the file share resource that you want to create a shadow copy for. For example, click drive R.

How a Microsoft shadow copy is created?

Like the copy-on-write method, the redirect-on-write method is a quick method for creating a shadow copy, because it copies only changes to the data. The copied blocks in the diff area can be combined with the unchanged data on the original volume to create a complete, up-to-date copy of the data.


1 Answers

Okay, Technoob1984 here with the scoop. See my attached screen shot.

This one is tricky, because you have to use x64 version of Powershell (located under system32 not wow64)

The Shadow Copy Context are the .properties of the object.

Also I used the static method in my screenshots below.

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/vsswmi/create-method-in-class-win32-shadowcopy

# get existing shadow copies $shadow = get-wmiobject win32_shadowcopy "There are {0} shadow copies on this sytem" -f $shadow.count ""  # get static method $class=[WMICLASS]"root\cimv2:win32_shadowcopy"  # create a new shadow copy "Creating a new shadow copy" $class.create("C:\", "ClientAccessible")  # Count again $shadow = get-wmiobject win32_shadowcopy 

so in the example there, you would want to use $class.Properties to see what you can use as a Shadow Context.

See my screen shot: enter image description here

So Shadow Context is 'Caption, Count, Description' and anything else under the 'Name:' value of .Properties. I do not see 'Backup' as one of the options.

  • Enjoy
like image 159
Technoob1984 Avatar answered Sep 22 '22 03:09

Technoob1984