@@ -218,7 +218,7 @@ func main() {
218218
219219 begin := time .Now ()
220220 if cfg .BackupSourceDir != "" {
221- err = backup (client , newchunk , reusechunk , cfg .PxarOut , cfg .BackupSourceDir )
221+ err = backup (client , newchunk , reusechunk , cfg .PxarOut , cfg .BackupSourceDir , cfg . UseVSS )
222222 } else if cfg .BackupStreamName != "" {
223223 sn := cfg .BackupStreamName
224224 if ! strings .HasSuffix (sn , ".didx" ) {
@@ -359,113 +359,122 @@ func backup_stream(client *pbscommon.PBSClient, newchunk, reusechunk *atomic.Uin
359359 return client .Finish ()
360360}
361361
362- func backup (client * pbscommon.PBSClient , newchunk , reusechunk * atomic.Uint64 , pxarOut string , backupdir string ) error {
362+ func backup_real (client * pbscommon.PBSClient , newchunk , reusechunk * atomic.Uint64 , pxarOut string , backupdir string ) error {
363+ client .Connect (false )
363364 knownChunks := hashmap .New [string , bool ]()
364365
365- fmt .Printf ("Starting backup of %s\n " , backupdir )
366-
367- err := snapshot .CreateVSSSnapshot (([]string {backupdir }), func (snaps map [string ]snapshot.SnapShot ) error {
368- k := maps .Keys (snaps )
369- k2 := slices .Collect (k )
370- SNAP := snaps [k2 [0 ]]
371- backupdir = SNAP .FullPath
372- //Remove VSS snapshot on windows, on linux for now NOP
373-
374- client .Connect (false )
375-
376- archive := & pbscommon.PXARArchive {}
377- archive .ArchiveName = "backup.pxar.didx"
366+ archive := & pbscommon.PXARArchive {}
367+ archive .ArchiveName = "backup.pxar.didx"
378368
379- previousDidx , err := client .DownloadPreviousToBytes (archive .ArchiveName )
380- if err != nil {
381- return err
382- }
369+ previousDidx , err := client .DownloadPreviousToBytes (archive .ArchiveName )
370+ if err != nil {
371+ return err
372+ }
383373
384- fmt .Printf ("Downloaded previous DIDX: %d bytes\n " , len (previousDidx ))
374+ fmt .Printf ("Downloaded previous DIDX: %d bytes\n " , len (previousDidx ))
385375
386- /*f2, _ := os.Create("test.didx")
387- defer f2.Close()
376+ /*f2, _ := os.Create("test.didx")
377+ defer f2.Close()
388378
389- f2.Write(previous_didx)*/
379+ f2.Write(previous_didx)*/
390380
391- /*
392- Here we download the previous dynamic index to figure out which chunks are the same of what
393- we are going to upload to avoid unnecessary traffic and compression cpu usage
394- */
381+ /*
382+ Here we download the previous dynamic index to figure out which chunks are the same of what
383+ we are going to upload to avoid unnecessary traffic and compression cpu usage
384+ */
395385
396- if ! bytes .HasPrefix (previousDidx , didxMagic ) {
397- fmt .Printf ("Previous index has wrong magic (%s)!\n " , previousDidx [:8 ])
386+ if ! bytes .HasPrefix (previousDidx , didxMagic ) {
387+ fmt .Printf ("Previous index has wrong magic (%s)!\n " , previousDidx [:8 ])
398388
399- } else {
400- //Header as per proxmox documentation is fixed size of 4096 bytes,
401- //then offset of type uint64 and sha256 digests follow , so 40 byte each record until EOF
402- previousDidx = previousDidx [4096 :]
403- for i := 0 ; i * 40 < len (previousDidx ); i += 1 {
404- e := DidxEntry {}
405- e .offset = binary .LittleEndian .Uint64 (previousDidx [i * 40 : i * 40 + 8 ])
406- e .digest = previousDidx [i * 40 + 8 : i * 40 + 40 ]
407- shahash := hex .EncodeToString (e .digest )
408- fmt .Printf ("Previous: %s\n " , shahash )
409- knownChunks .Set (shahash , true )
410- }
389+ } else {
390+ //Header as per proxmox documentation is fixed size of 4096 bytes,
391+ //then offset of type uint64 and sha256 digests follow , so 40 byte each record until EOF
392+ previousDidx = previousDidx [4096 :]
393+ for i := 0 ; i * 40 < len (previousDidx ); i += 1 {
394+ e := DidxEntry {}
395+ e .offset = binary .LittleEndian .Uint64 (previousDidx [i * 40 : i * 40 + 8 ])
396+ e .digest = previousDidx [i * 40 + 8 : i * 40 + 40 ]
397+ shahash := hex .EncodeToString (e .digest )
398+ fmt .Printf ("Previous: %s\n " , shahash )
399+ knownChunks .Set (shahash , true )
411400 }
401+ }
412402
413- fmt .Printf ("Known chunks: %d!\n " , knownChunks .Len ())
414- f := & os.File {}
415- if pxarOut != "" {
416- f , err = os .Create (pxarOut )
417- if err != nil {
418- return err
419- }
420- defer f .Close ()
403+ fmt .Printf ("Known chunks: %d!\n " , knownChunks .Len ())
404+ f := & os.File {}
405+ if pxarOut != "" {
406+ f , err = os .Create (pxarOut )
407+ if err != nil {
408+ return err
421409 }
422- /**/
410+ defer f .Close ()
411+ }
412+ /**/
423413
424- pxarChunk := ChunkState {}
425- pxarChunk .Init (newchunk , reusechunk , knownChunks )
414+ pxarChunk := ChunkState {}
415+ pxarChunk .Init (newchunk , reusechunk , knownChunks )
426416
427- pcat1Chunk := ChunkState {}
428- pcat1Chunk .Init (newchunk , reusechunk , knownChunks )
417+ pcat1Chunk := ChunkState {}
418+ pcat1Chunk .Init (newchunk , reusechunk , knownChunks )
429419
430- pxarChunk .wrid , err = client .CreateDynamicIndex (archive .ArchiveName )
431- if err != nil {
432- return err
433- }
434- pcat1Chunk .wrid , err = client .CreateDynamicIndex ("catalog.pcat1.didx" )
435- if err != nil {
436- return err
420+ pxarChunk .wrid , err = client .CreateDynamicIndex (archive .ArchiveName )
421+ if err != nil {
422+ return err
423+ }
424+ pcat1Chunk .wrid , err = client .CreateDynamicIndex ("catalog.pcat1.didx" )
425+ if err != nil {
426+ return err
427+ }
428+
429+ archive .WriteCB = func (b []byte ) {
430+
431+ if pxarOut != "" {
432+ // TODO: error handling inside callback
433+ f .Write (b )
437434 }
438435
439- archive . WriteCB = func ( b [] byte ) {
436+ pxarChunk . HandleData ( b , client )
440437
441- if pxarOut != "" {
442- // TODO: error handling inside callback
443- f .Write (b )
444- }
438+ //
439+ }
445440
446- pxarChunk .HandleData (b , client )
441+ archive .CatalogWriteCB = func (b []byte ) {
442+ pcat1Chunk .HandleData (b , client )
443+ }
447444
448- //
449- }
445+ //This is the entry point of backup job which will start streaming with the PCAT and PXAR write callback
446+ //Data to be hashed and eventuall uploaded
450447
451- archive .CatalogWriteCB = func (b []byte ) {
452- pcat1Chunk .HandleData (b , client )
453- }
448+ archive .WriteDir (backupdir , "" , true )
454449
455- //This is the entry point of backup job which will start streaming with the PCAT and PXAR write callback
456- //Data to be hashed and eventuall uploaded
450+ pxarChunk . Eof ( client )
451+ pcat1Chunk . Eof ( client )
457452
458- archive .WriteDir (backupdir , "" , true )
453+ err = client .UploadManifest ()
454+ if err != nil {
455+ return err
456+ }
457+ return nil
458+ }
459459
460- pxarChunk . Eof (client )
461- pcat1Chunk . Eof ( client )
460+ func backup (client * pbscommon. PBSClient , newchunk , reusechunk * atomic. Uint64 , pxarOut string , backupdir string , usevss bool ) error {
461+
462462
463- err = client .UploadManifest ()
464- if err != nil {
465- return err
466- }
467- return nil
468- })
463+ fmt .Printf ("Starting backup of %s\n " , backupdir )
464+ var err error
465+ if usevss {
466+ err = snapshot .CreateVSSSnapshot (([]string {backupdir }), func (snaps map [string ]snapshot.SnapShot ) error {
467+ k := maps .Keys (snaps )
468+ k2 := slices .Collect (k )
469+ SNAP := snaps [k2 [0 ]]
470+ backupdir = SNAP .FullPath
471+ //Remove VSS snapshot on windows, on linux for now NOP
472+ return backup_real (client , newchunk , reusechunk , pxarOut , backupdir )
473+
474+ })
475+ }else {
476+ err = backup_real (client , newchunk , reusechunk , pxarOut , backupdir )
477+ }
469478
470479 if err != nil {
471480 return err
0 commit comments