1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| 'Le fichier est ouvert -- Utilisation de snapshot
Sub snapshot(ByVal chem_source As String, ByVal chem_dest As String, ByVal date_modif As Date, ByVal date_zip As Date)
Console.WriteLine("je suis dans cette fonction")
Dim vssImplementation As IVssImplementation
Dim vssbackup As IVssBackupComponents
Dim snapshot As Guid
vssImplementation = VssUtils.LoadImplementation()
vssbackup = vssImplementation.CreateVssBackupComponents()
vssbackup.InitializeForBackup(Nothing)
'vssbackup.SetContext()
vssbackup.SetBackupState(False, True, VssBackupType.Copy, False)
Using async As IVssAsync = vssbackup.GatherWriterMetadata()
async.Wait()
End Using
'Console.WriteLine("Test d'écriture")
snapshot = vssbackup.StartSnapshotSet()
Dim IsSadowCopySupported As Boolean = vssbackup.IsVolumeSupported("d:\", Guid.Empty)
'If IsSadowCopySupported = True Then
' Console.WriteLine("Volume supporté par les Shadow Copy")
'End If
Dim SnapShotId As Guid = vssbackup.AddToSnapshotSet("d:\", Guid.Empty)
'Console.WriteLine("Voici l'Id du SnapShot: {0}", SnapShotId)
Using async As IVssAsync = vssbackup.PrepareForBackup
async.Wait()
End Using
Using async As IVssAsync = vssbackup.DoSnapshotSet
async.Wait()
End Using
Dim SnapShotProp As VssSnapshotProperties = vssbackup.GetSnapshotProperties(SnapShotId)
Dim SnapShotDevice As String = SnapShotProp.SnapshotDeviceObject
Console.WriteLine("SnapShotDevice: {0}", SnapShotDevice)
Dim entier As Integer = chem_source.Length()
entier = entier - 2
Dim chem_source2 As String = Right(chem_source, entier)
Dim SourceFile As String = SnapShotDevice & "\" & chem_source2
Console.WriteLine(SourceFile)
entier = chem_dest.Length()
entier = entier - 4
Dim chem_dest2 As String = Left(chem_dest, entier)
Dim TargetFile As String = chem_dest2
Using async As IVssAsync = vssbackup.BackupComplete
async.Wait()
End Using
My.Computer.FileSystem.CopyFile(SourceFile, TargetFile)
Dim pbstrXML As String = vssbackup.SaveAsXml()
Console.WriteLine("pbstrXML: {0}", pbstrXML)
Dim sw As System.IO.StreamWriter = Nothing
sw = New System.IO.StreamWriter("C:\fic.xml")
sw.WriteLine("{0}", pbstrXML)
sw.Close()
End Sub |
Partager