This project is read-only.

ArgumentException when trying to mount VSS volume created with AlphaVSS

Apr 23, 2009 at 3:43 AM
Hello,
I am working on a project that includes both AlphaVSS and AlphaFS to generate a snapshot of a volume, then expose it as a mount point.

Here is an (abreviated example) of the code I am using to generate the snapshot:
            Guid gSnapshot = Guid.Empty, gSet = Guid.Empty;
            
            try
            {
                vssBackupComponent = vssImplementation.CreateVssBackupComponents();
                vssBackupComponent.InitializeForBackup(null);
                vssBackupComponent.SetBackupState(false, true, type, false);

                using (IVssAsync async = vssBackupComponent.GatherWriterMetadata())
                        { async.Wait(); }

                gSet = vssBackupComponent.StartSnapshotSet();
                gSnapshot = vssBackupComponent.AddToSnapshotSet(DriveLetter, Guid.Empty);

                using (IVssAsync async = vssBackupComponent.PrepareForBackup())
                        { async.Wait(); }
                using (IVssAsync async = vssBackupComponent.DoSnapshotSet())
                        { async.Wait(); }
                using (IVssAsync async = vssBackupComponent.BackupComplete())
                        { async.Wait(); }
            } (...)

And the troublesome block:
                        if(gSnapshot != Guid.Empty)
                        {
                            if(!Directory.Exists((String)args[0]))
                                Directory.CreateDirectory((String)args[0]);
    
                            String vol = @"\\?\Volume{" + gSnapshot.ToString() + @"}\";
                            Volume.SetVolumeMountPoint((String)args[0], vol);                     
                        }
args being an ArrayList of arguments (at that point, it contains a string with something like @"C:\Backup\".

Any ideas?
Thanks in advance!
Coordinator
Apr 23, 2009 at 4:09 AM
There are a couple of errors here.
First off, there is no volume with the name you specify for the string 'vol' (unless M$ did something wrong in their GUID implementation ;).
The ID of a snapshot is not available as a volume unless exposed. It is however available as a device, which can be retrieved by calling:

     vssBackupComponent.GetSnapshotProperties(gSnapshot);

This could be used with something like Volume.DefineDosDevice to use the "XP-hack" to expose it as a drive letter.

The better way however, would be calling ExposeSnapshot, i.e. something like:

     vssBackupComponent.ExposeSnapshot(gSnapshot, (String)args[0], VssVolumeSnapshotAttributes.ExposedLocally, dir);

Hope this helps.

Sincerely, Peter.
Coordinator
Apr 23, 2009 at 4:14 AM
Note also that you can use the device name to access the files directly from the snapshot without exposing it as a directory using AlphaFS.

Try for an example:

   Directory.GetFiles(vssBackupComponent.GetSnapshotProperties(gSnapshot).SnapshotDeviceObject);