Am I confused? I thought AlphaFS could copy locked files

Apr 5, 2011 at 8:34 PM
Edited Apr 5, 2011 at 8:38 PM

Background:   Win2k8 R2 w/ Vs2k8

'this calls the function.  RememberDeviceObject is the ID of the snapshot that was just created.  "\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy31"

destination dir is a SAN disk thats ISCSI initiated as a "local" drive.

to be specific, the path is "D:\vss_test"

CopyDirectory(RememberDeviceObject, destinationdir)

 

'Here is the function

 

    Private Sub CopyDirectory(ByVal sourceDir As String, ByVal destDir As String)
        Try
            If Not Alphaleonis.Win32.Filesystem.Directory.Exists(destDir) Then
                Alphaleonis.Win32.Filesystem.Directory.CreateDirectory(destDir)
            End If

            For Each strEntry As String In Alphaleonis.Win32.Filesystem.Directory.GetFiles(sourceDir)
                Dim finaldest As String = Path.GetFileName(strEntry)
                finaldest = destDir & "\" & finaldest
                Alphaleonis.Win32.Filesystem.File.Copy(strEntry, finaldest)
            Next
            For Each strEntry As String In Alphaleonis.Win32.Filesystem.Directory.GetDirectories(sourceDir)
                Dim strDest As String = Alphaleonis.Win32.Filesystem.Path.Combine(destDir, System.IO.Path.GetFileName(strEntry))
                CopyDirectory(strEntry, strDest)
            Next
        Catch ex As Exception
            MsgBox(Err.Description)
        End Try
    End Sub

 

It works fine until it gets to the Documents and Settings folder and throws an exception at ntuser.dat cause its in use, and locked.  What am I doing wrong, or is this normal and my perception of AlphaFS was wrong.

Apr 5, 2011 at 8:45 PM

How did you make the snapshot?

Can you check what's using those files?

http://technet.microsoft.com/en-us/sysinternals/bb896655

Apr 5, 2011 at 8:58 PM

i used the AlphaVSS to do it...  i can post the code....

Whats using the files is most likely Windows... NTuser.dat is a registry file.

This takes the snapshot....  which can be mounted as a drive, etc.. so I know its working, at least to some extent.

    Public Sub Snapshot(ByRef VSSGUID As System.Guid, ByRef DeviceObject As String)
        Dim oVSSImpl As IVssImplementation = VssUtils.LoadImplementation()
        Using oVSS As IVssBackupComponents = oVSSImpl.CreateVssBackupComponents()
            oVSS.InitializeForBackup(Nothing)
            oVSS.SetContext(Alphaleonis.Win32.Vss.VssVolumeSnapshotAttributes.Persistent Or VssVolumeSnapshotAttributes.NoAutoRelease)
            oVSS.SetBackupState(False, True, VssBackupType.Full, False)

            Using async As IVssAsync = oVSS.GatherWriterMetadata()
                async.Wait()
            End Using

            Dim gSet As Guid = oVSS.StartSnapshotSet()

            Dim gSnapshot As Guid = oVSS.AddToSnapshotSet("C:\", Guid.Empty)

            Using async As IVssAsync = oVSS.PrepareForBackup()
                async.Wait()
            End Using

            Using async As IVssAsync = oVSS.DoSnapshotSet()
                async.Wait()
            End Using

            'Dim oProps As VssSnapshotProperties = oVSS.GetSnapshotProperties(gSnapshot)
            ' Dim drive As String = oVSS.ExposeSnapshot(gSnapshot, Nothing, VssVolumeSnapshotAttributes.ExposedLocally, "Z:")
            VSSGUID = oVSS.GetSnapshotProperties(gSnapshot).SnapshotId
            DeviceObject = oVSS.GetSnapshotProperties(gSnapshot).SnapshotDeviceObject
        End Using
    End Sub

Apr 5, 2011 at 9:00 PM
Edited Apr 5, 2011 at 9:18 PM

i just re-wrote a little error handling to (at the end) list me all files it couldn't copy and all folders it couldn't access.

 

I thought the whole point of AlphaVSS + AlphaFS was that it could access the HarddiskVolumeShadowCopyXX and that would allow it to grab the ENTIRE disk

 

 

edit:  It skipped 34,054 files, 88 folders, and 668,321,792 bytes....   took  just under 13 minutes to copy 19.2GB  (they are pretty quick machines with isci and sas 6gb/s drives.

Apr 5, 2011 at 9:49 PM

Writing from memory.

1) Try to enable higher privileges for copying process from the code

using (new Alphaleonis.Win32.Security.PrivilegeEnabler(Privilege.Backup, Privilege.Restore) {

// try to open one of the protected files with one of the File.Open overloads, the one that takes special flags like Backup.

// combined with above obtained security token you can open any file.

// unless it has specifically been opened with FIleShare.None, in that case you won't be able to do anything with it before the using process closes it.

 

}

build the project.

2) After you built it, right click on executable and select "Run As Administrator". This particular step is for Vista+ Windowces. Or you can start from Admin Command Line using this advice http://www.howtogeek.com/howto/windows-vista/run-a-command-as-administrator-from-the-windows-vista-run-box/

 


Apr 7, 2011 at 4:35 PM

Same issue as before...