 |
|
|
 |
|
|
 |
|
 |
Hello,
Whenever I use this MakeShadowCopy class, it seems like the shadow "expires" or something after the first couple of files it copies.. The copy process returns error codes of 55, 2, and 3, which all relate to a file/path not existing.
Does anyone know if shadow copies expire after a certain amount of time, and if there is anything I can do to keep it alive during this process?
Thanks in advance!
Derek Pecka
|
|
|
|
 |
|
|
 |
|
 |
Hi,
I am also working with VSS but i am unable to do VSS Incremental and Differential Backup process in C++. Could you help me about this metter?
Thanks
hi!!
|
|
|
|
 |
|
 |
I am also facing the same heat for diffrential bkp. Can somebody help plz ?
|
|
|
|
 |
|
 |
void vssTest()
{
VssWMI vss = new VssWMI();
try
{
vss.SetVolume(@"C:\");
}
finally
{
vss.DelVolume();
}
}
public class VssWMI
{
public string DeviceName = string.Empty;
public string Volume = string.Empty;
public string SetVolume(string volume)
{
DelVolume();
shadowId = createShadow(volume);
DeviceName = getShadowDevice(shadowId);
Volume = volume;
return DeviceName;
}
public void DelVolume()
{
if (shadowId != string.Empty)
deleteShadow(shadowId);
shadowId = string.Empty;
DeviceName = string.Empty;
Volume = string.Empty;
}
static string shadowId = string.Empty;
static string shadowNamespace = @"\\localhost\root\cimv2";
static string createShadow(string volume)
{
string res = string.Empty;
ManagementClass mgmtClass = new ManagementClass(shadowNamespace, "Win32_ShadowCopy", null);
ManagementBaseObject inParams = mgmtClass.GetMethodParameters("Create");
inParams.SetPropertyValue("Volume", volume);
inParams.SetPropertyValue("Context", "ClientAccessible");
ManagementBaseObject outParams =
mgmtClass.InvokeMethod("Create", inParams, null);
res = (string)outParams["ShadowID"];
if (res == string.Empty)
throw new Exception("Error creating shadow copy!");
return res;
}
static void deleteShadow(string shadowId)
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(shadowNamespace,
"SELECT * FROM Win32_ShadowCopy where ID = '" + shadowId + "'");
foreach (ManagementObject queryObj in searcher.Get()) {
queryObj.Delete();
break;
}
}
static string getShadowDevice(string shadowId)
{
string res = string.Empty;
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(shadowNamespace,
"SELECT * FROM Win32_ShadowCopy where ID = '" + shadowId + "'");
foreach (ManagementObject queryObj in searcher.Get()) {
res = (string)queryObj["DeviceObject"];
break;
}
return res;
}
}
|
|
|
|
 |
|
 |
I just converted this to VB.NET, am geting an
'Initialization Failure'
in
Dim outParams As ManagementBaseObject = mgmtClass.InvokeMethod("Create", inParams, Nothing)
any one get this working ?
|
|
|
|
 |
|
 |
while (true) {
int hr = 0;
int x = 0;
vssAsync.QueryStatus(out hr, ref x);
if (hr == VSS_S_ASYNC_FINISHED) {
isSnapOpened = true;
break;
}
if (hr == VSS_S_ASYNC_CANCELLED) {
throw new Exception("VSS asynchronous operation was canceled by timeout!");
}
if (asyncSnapCounter >= 60) {
vssAsync.Cancel();
}
asyncSnapCounter++;
Thread.Sleep(500);
}
modified on Wednesday, June 18, 2008 2:21 PM
|
|
|
|
 |
|
 |
public struct VSSErrHelper
{
public long ErrorId;
public string ErrorMsg;
public VSSErrHelper(long errorId, string errorMsg)
{
ErrorId = errorId;
ErrorMsg = errorMsg;
}
}
public static VSSErrHelper[] VSSErrors =
{
new VSSErrHelper(VSS_E_BAD_STATE, "A function call was invalid because of the state of either the\nbackup extensions or the coordinator. For example calling AddToSnapshot\nset prior to calling StartSnapshotSet."),
new VSSErrHelper(VSS_E_PROVIDER_ALREADY_REGISTERED, "Calling RegisterProvider"),
new VSSErrHelper(VSS_E_PROVIDER_NOT_REGISTERED, "Calling UnregisterProvider"),
new VSSErrHelper(VSS_E_PROVIDER_VETO, "Calling DoSnapshotSet"),
new VSSErrHelper(VSS_E_PROVIDER_IN_USE, "Calling UnregisterProvider, StartSnapshotSet"),
new VSSErrHelper(VSS_E_OBJECT_NOT_FOUND, "Calling DeleteSnapshots, Query"),
new VSSErrHelper(VSS_S_ASYNC_PENDING, "Calling IVssAsync::QueryStatus"),
new VSSErrHelper(VSS_S_ASYNC_FINISHED, "Calling IVssAsync::QueryStatus"),
new VSSErrHelper(VSS_S_ASYNC_CANCELLED, "Calling IVssAsync::QueryStatus"),
new VSSErrHelper(VSS_E_VOLUME_NOT_SUPPORTED, "Calling AddToSnapshotSet"),
new VSSErrHelper(VSS_E_VOLUME_NOT_SUPPORTED_BY_PROVIDER, "Calling AddToSnapshotSet"),
new VSSErrHelper(VSS_E_OBJECT_ALREADY_EXISTS, "Calling ExposeCurrentState"),
new VSSErrHelper(VSS_E_UNEXPECTED_PROVIDER_ERROR, "Calling several methods supported by the providers."),
new VSSErrHelper(VSS_E_CORRUPT_XML_DOCUMENT, "XML document unexpectedly does not match schema."),
new VSSErrHelper(VSS_E_CORRUPT_XML_DOCUMENT, "An XML document passes as an argument is not valid, i.e., is either\nnot correctly formed XML or does not match the schema"),
new VSSErrHelper(VSS_E_MAXIMUM_NUMBER_OF_VOLUMES_REACHED, "We cannot add any more volumes since we passed the maximum limit."),
new VSSErrHelper(VSS_E_FLUSH_WRITES_TIMEOUT, "VSS couldn't flush I/O writes anymore."),
new VSSErrHelper(VSS_E_HOLD_WRITES_TIMEOUT, "VSS couldn't hold I/O writes anymore."),
new VSSErrHelper(VSS_E_UNEXPECTED_WRITER_ERROR, "VSS encountered problems while sending events to writers"),
new VSSErrHelper(VSS_E_SNAPSHOT_SET_IN_PROGRESS, "StartSnapshotSet was called when another snapshot set in the\nprocess of being created."),
new VSSErrHelper(VSS_E_MAXIMUM_NUMBER_OF_SNAPSHOTS_REACHED, "AddToSnapshotSet was called on a volume that has already reached\nits maxinum number"),
new VSSErrHelper(VSS_E_WRITER_INFRASTRUCTURE, "The Writer infrastructure is not operating properly. Check that the\nEvent Service and the Volume Snapshot Service are started and check for\nerrors associdated with these services in the error log."),
new VSSErrHelper(VSS_E_WRITER_NOT_RESPONDING, "A writer did not respond to a GetWriterStatus call. This means that\nthe process containing the writer died or is hung."),
new VSSErrHelper(VSS_E_WRITER_ALREADY_SUBSCRIBED, "A writer has already sucessfully called the Subscribe function. It cannot call\nsubscribe multiple times."),
new VSSErrHelper(VSS_E_UNSUPPORTED_CONTEXT, "Attempt to use an unsupported context."),
new VSSErrHelper(VSS_E_VOLUME_IN_USE, "Calling ChangeDiffAreaMaximumSize"),
new VSSErrHelper(VSS_E_MAXIMUM_DIFFAREA_ASSOCIATIONS_REACHED, "Calling AddDiffArea"),
new VSSErrHelper(VSS_E_INSUFFICIENT_STORAGE, "Calling EndPrepareSnapshots, ChangeDiffAreaMaximumSize"),
new VSSErrHelper(VSS_E_NO_SNAPSHOTS_IMPORTED, "Calling ImportSnapshots, no volumes were successfully imported"),
new VSSErrHelper(VSS_S_SOME_SNAPSHOTS_NOT_IMPORTED, "Calling ImportSnapshots, some volumes were not successfully imported")
};
private static Exception getVSSErrMsg(Exception e)
{
int indexOfErrorId = -1;
long errorId = 0;
string srcErrMsg = "";
indexOfErrorId = e.Message.IndexOf("HRESULT:");
if (indexOfErrorId >= 0) {
srcErrMsg = e.Message.Substring(indexOfErrorId);
try {
errorId = Convert.ToInt64(e.Message.Substring(indexOfErrorId + 8).Trim(), 16);
} catch { errorId = 0; }
}
if (errorId > 0) {
foreach (VSSErrHelper dscr in VSSErrors) {
if (dscr.ErrorId == errorId)
return new Exception("VSS ERROR: " + dscr.ErrorMsg + " (" +
srcErrMsg + ")", e);
}
}
return e;
}
|
|
|
|
 |
|
 |
Hello,
Nice article, my question is: who created the interop.vss.dll and how?
Please let me know..
Thanks
|
|
|
|
 |
|
 |
Hi Rick, the interop is created from Visual Studio when the project is built. You need to install visual studio on each OS you want to support then the proper interop is created from the com object per located on the operating system when the project is built. Vista doesnt have the VSS com object that xp and 2k3 have so it wont work for that. I have included the interops for XP, XP x64, Windows 2003, and 2003 X64 here. http://www.etw.ca/interops.zip Just make sure you rename the file so it says interop.vss.dll to work properly. For vista & 2008 you need to download the sdk for the operating system and make the appropriate changes to the code.
|
|
|
|
 |
|
 |
Hi Scott,
It would seem you have been talking to Joe....
The question I have for you now, b/c that it seems like you really know your stuff is, what changes do I need to make to the code to get vista & 2008 to work... can u send an example?
Thanks,
Rick
|
|
|
|
 |
|
 |
Hello Rick/Scott,
If you do have a solution for Vista/08, please post to this site - thanks!
T.C.
|
|
|
|
 |
|
 |
I went to the work of contacting the Microsoft VSS team. I was able to create the interop for vista and 2008 however in vista and 08 the vss coordinator class is lacking the ability to create and do snapshots along with a few other things. I was informed that the vss coordinator class is unsupported and was only made for internal use thats why its not documented anywhere on msdn. The only way to do it for 08 and vista is to write something in mc++ and make calls to it. The correct class to use is the IVSS coordinator. http://msdn2.microsoft.com/en-us/library/aa382175(VS.85).aspx[^]
So you will need to create a thin interop. You need to add the headers from the vista sdk. Let me know if you come up with anything.
|
|
|
|
 |
|
 |
Using Volume Shadow Services in Vb.NET thru an Interop (Interop.VSS.Dll for Windows Server 2003) there appears to be random errors occuring.
After creating the snapshot with the code below
Private Function MakeNewSnapshot( _
ByRef vss As VSS.VSSCoordinatorClass, _
ByVal sVolume As String, _
ByRef output_SnapShotSetID As Guid, _
ByRef output_SnapShotID As Guid) As Boolean
Dim bRet As Boolean
Try
vss.StartSnapshotSet(output_SnapShotSetID)
vss.AddToSnapshotSet(sVolume, Guid.Empty, output_SnapShotID)
Dim ovssAsync As VSS.IVssAsync = Nothing
Dim oCallBack As Object = Nothing
vss.DoSnapshotSet(oCallBack, ovssAsync)
Do While (True)
Dim hr As Integer = 0
Dim x As Integer = 0
ovssAsync.QueryStatus(hr, x)
If hr = VSS_S_ASYNC_FINISHED Then
Exit Do
End If
Threading.Thread.Sleep(1000)
Loop
bRet = True
Catch ex As Exception
' clean up any progressing snapshots
vss.AbortAllSnapshotsInProgress()
End Try
Return bRet
End Function
I then attempt to copy a file using hte CopyFile API. On random occasions for some files and all the time for others I get the CopyFile failing with "The system cannot find the file specified.". It doesn't always happen right either, it can get X % thru the copy then fail.
I then try to clean up the VSS Snapshot with
vss.DeleteSnapshots( _
moSnapshotSetID, _
Global.VSS._VSS_OBJECT_TYPE.VSS_OBJECT_SNAPSHOT_SET, _
CInt(True), _
iCountOfDeletedSnapshots, _
oNonDeletedSnapshotID)
bRet = iCountOfDeletedSnapshots = 1
This gives an error message like "0x80042308" (VSS_E_OBJECT_NOT_FOUND) indicating the Snapshot is missing...
What can be going wrong? -- it only seems to happen on Windows 2003... maybe once or twice on XP
|
|
|
|
 |
|
 |
My XP experience: For Delete use the vss instance generated in Snapshot.New
Public Class Snapshot
...
Private moSnapshotSetID As New Guid
Private moSnapshotID As New Guid
Private msDeviceName As String
Private vss As New VSS.VSSCoordinatorClass
Public Sub New(ByVal sVolume As String)
' REM Dim vss As New VSS.VSSCoordinatorClass
Abort(vss)
MakeNewSnapshot(vss, sVolume, moSnapshotSetID, moSnapshotID)
msDeviceName = GetSnapshotDeviceName(vss, moSnapshotID)
End Sub
...
Public Sub Delete()
Dim iCountOfDeletedSnapshots As Integer = 0
Dim oNonDeletedSnapshotID As New Guid
' REM Dim vss As New VSS.VSSCoordinatorClass
vss.DeleteSnapshots( _
moSnapshotSetID, _
_VSS_OBJECT_TYPE.VSS_OBJECT_SNAPSHOT_SET, _
True, _
iCountOfDeletedSnapshots, _
oNonDeletedSnapshotID)
End Sub
|
|
|
|
 |
|
 |
One small question: Where can I find the referenced vss.dll on Windows Vista?
modified on Sunday, March 23, 2008 4:38 PM
|
|
|
|
 |
|
 |
I compiled the code on my XP Machine and it works great. However when I run it on Vista I get COM interface error.
It does not seem to be a permission issue because I start the program as Administrator.
Anyone have any ideas or thoughts?
|
|
|
|
 |
|
 |
Hi,
I have the same problem under Vista, and not on XP.
It seems to be a permission issue, not on the application, but on the VSSCoordinate Class in registry (under HKEY_CLASSES_ROOT)
If you compare the admin and system rights on XP, you can see total control permission. It's different under Vista.
Perhaps this is the way to fix the problem, but I can't change permissions in the registry for the class ...
If you have an idea ...
|
|
|
|
 |
|
 |
You can change the ownership permisson in the registry to your active user By clicking on permissions>Advanced>Owner and change the permissions, however after trying this the same result occurred. However you are definetly onto something here i think.
|
|
|
|
 |
|
 |
vss service is different on vista and xp. for VSS; vsssdk 7.2 is used on XP and microsoft sdk is used on vista. may be the sample source code provided in the article is using VSSSDK 7.2. i suggest checking the vss version for correct version. on the other hand i haven't tried to run the code yet.
regards
"Try Not! Do. Or Do Not. There is no Try..." Master Yoda
|
|
|
|
 |
|
 |
Hello - Great sample. I modified the Snapshot class to create a snapshot via a method call. But, I noticed the snapshot is removed when my WinForms app shuts down (even if I do not delete the snapshot/snapshot set). Do you know how I can prevent this from happening?
T.C.
|
|
|
|
 |
|
|
 |
|
 |
Hi Joe,
your article is a very nice one.
Small error:
ElseIf args(i).StartsWith("-T:") Then
sTargetPath = args(i).Substring(3, args(i).Length - 3)
If Not sTargetPath.EndsWith("\") Then sTargetPath = sTargetPath & "\"
If Not Directory.Exists(sSourcePath) Then
bSuccess = False
ShowError(4)
ShowHelp()
Exit Sub
End If
Else
sSourcePath should be sTargetPath
Cheers, Mohamed
|
|
|
|
 |