Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a shadow copy using the "Backup" context in a PowerShell
    primarykey
    data
    text
    <p>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).</p> <p>I found out from another question (<a href="https://stackoverflow.com/questions/14207788/accessing-volume-shadow-copy-vss-snapshots-from-powershell">Accessing Volume Shadow Copy (VSS) Snapshots from powershell</a>) a way to create a shadow copy in general, but the example given there uses "ClientAccessible" as the context parameter, which result in the creation of a persistent Shadow Copy, without writer participation.</p> <p>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:</p> <pre><code>Get-WmiObject win32_shadowcontext | Out-GridView </code></pre> <p>It does 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:</p> <pre><code>$shadow = (Get-WmiObject -list win32_shadowcopy).Create("C:\", "Backup") </code></pre> <p>However, this seem to fail and the content of the <strong>$shadow</strong> variable is set to</p> <pre><code>ReturnValue : 5 ShadowID : {00000000-0000-0000-0000-000000000000} </code></pre> <p>According to the relevant documentation (<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa389391(v=vs.85).aspx" rel="nofollow noreferrer">Create method of the Win32_ShadowCopy class</a>), the return value means "Unsupported shadow copy context."</p> <p>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.</p> <p>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)</p> <p>How can I get this to work?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COI am just wrote the same thing myself (but it was with C# and the library AlphaVSS), here is what I learned: You are going to need to mount the snapshot to get the files to sync it, but to be mountable a snapshot must have the `NoAutoRelease` flag set to `true`. Also to have `NoAutoRelease` set to true you must have `Persistent` set to `true`, so just a fyi so you don't spend too much time trying to get something other than `ClientAccessable` to work (`ClientAccessable` has both variables set to `true`)
      singulars
    2. COShadow copies created with NoAutoRelease set to False are automatically removed once the process requesting them ends ([link](http://msdn.microsoft.com/en-us/library/windows/desktop/aa394427(v=vs.85).aspx)). I was originally suspecting that that was the issue that I was seeing, but the fact that I have the same problem with the AppRollback context suggests it may not be the case. But in general it is possible to mount auto-release shadow copies as described at [link](http://www.goodjobsucking.com/?p=62). However, I would prefer using powershell rather than the solution proposed there.
      singulars
    3. COIf you can't get WMI to work, maybe try loading the [AlphaVSS assembly](http://alphavss.codeplex.com/) in to Powershell. [Here is how to create a snapshot, mount it, and delete it in C#](http://pastebin.com/XhVLyq0m), you should be able to translate that in to powershell.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload