[Box Backup-commit] #13: Fix file locking on Windows

Box Backup trac at boxbackup.org
Thu Mar 11 16:25:07 GMT 2010


#13: Fix file locking on Windows
------------------------------------------------------------------------+---
 Reporter:  chris                                                       |       Owner:  chris
     Type:  defect                                                      |      Status:  new  
 Priority:  normal                                                      |   Milestone:  0.12 
Component:  bbackupd                                                    |     Version:  0.10 
 Keywords:  windows file locking locked volume shadow copy service vss  |  
------------------------------------------------------------------------+---

Comment(by achim):

 = How is it done on Bacula =

 == in win32/filed/main.cpp ==

 {{{
   /* Start up Volume Shadow Copy (only on FD) */
   VSSInit();
 }}}
 is this really the start of the routine, or simply a helper main.cpp?

 == which calls win32/filed/vss.cpp ==

 {{{
 void VSSInit()
 {
    /* decide which vss class to initialize */
    if (g_MajorVersion == 5) {
       switch (g_MinorVersion) {
       case 1:
          g_pVSSClient = new VSSClientXP();
          atexit(VSSCleanup);
          return;
       case 2:
          g_pVSSClient = new VSSClient2003();
          atexit(VSSCleanup);
          return;
       }
    /* Vista or Longhorn or later */
 //       } else if (g_MajorVersion == 6 && g_MinorVersion == 0) {
    } else if (g_MajorVersion >= 6) {
       g_pVSSClient = new VSSClientVista();
       atexit(VSSCleanup);
       return;
    }
 }
 }}}

 so a global variable g_pVSSClient that contains the object for VSS control

 == now in filed/job.c and ==

 {{{
 #if defined(WIN32_VSS)
 #include "vss.h"

 static pthread_mutex_t vss_mutex = PTHREAD_MUTEX_INITIALIZER;
 static int enable_vss;
 #endif


 #if defined(WIN32_VSS)
    int vss = 0;

    sscanf(dir->msg, "fileset vss=%d", &vss);
    enable_vss = vss;
 #endif



 #if defined(WIN32_VSS)
    // capture state here, if client is backed up by multiple directors
    // and one enables vss and the other does not then enable_vss can
 change
    // between here and where its evaluated after the job completes.
    jcr->VSS = g_pVSSClient && enable_vss;
    if (jcr->VSS) {
       /* Run only one at a time */
       P(vss_mutex);
    }
 #endif


 static int backup_cmd(JCR *jcr)

 #if defined(WIN32_VSS)
    /* START VSS ON WIN32 */
    if (jcr->VSS) {
       if (g_pVSSClient->InitializeForBackup()) {
         /* tell vss which drives to snapshot */
         char szWinDriveLetters[27];
         if (get_win32_driveletters(jcr->ff, szWinDriveLetters)) {
             Jmsg(jcr, M_INFO, 0, _("Generate VSS snapshots. Driver=\"%s\",
 Drive(s)=\"%s\"\n"), g_pVSSClient->GetDriverName(), szWinDriveLetters);
             if (!g_pVSSClient->CreateSnapshots(szWinDriveLetters)) {
                Jmsg(jcr, M_WARNING, 0, _("Generate VSS snapshots
 failed.\n"));
                jcr->JobErrors++;
             } else {
                /* tell user if snapshot creation of a specific drive
 failed */
                int i;
                for (i=0; i < (int)strlen(szWinDriveLetters); i++) {
                   if (islower(szWinDriveLetters[i])) {
                      Jmsg(jcr, M_WARNING, 0, _("Generate VSS snapshot of
 drive \"%c:\\\" failed. VSS support is disabled on this drive.\n"),
 szWinDriveLetters[i]);
                      jcr->JobErrors++;
                   }
                }
                /* inform user about writer states */
                for (i=0; i < (int)g_pVSSClient->GetWriterCount(); i++)
                   if (g_pVSSClient->GetWriterState(i) < 1) {
                      Jmsg(jcr, M_WARNING, 0, _("VSS Writer
 (PrepareForBackup): %s\n"), g_pVSSClient->GetWriterInfo(i));
                      jcr->JobErrors++;
                   }
             }
         } else {
             Jmsg(jcr, M_INFO, 0, _("No drive letters found for generating
 VSS snapshots.\n"));
         }
       } else {
          berrno be;
          Jmsg(jcr, M_WARNING, 0, _("VSS was not initialized properly. VSS
 support is disabled. ERR=%s\n"), be.bstrerror());
       }
       run_scripts(jcr, jcr->RunScripts, "ClientAfterVSS");
    }
 #endif


 #if defined(WIN32_VSS)
    /* STOP VSS ON WIN32 */
    /* tell vss to close the backup session */
    if (jcr->VSS) {
       if (g_pVSSClient->CloseBackup()) {
          /* inform user about writer states */
          for (int i=0; i<(int)g_pVSSClient->GetWriterCount(); i++) {
             int msg_type = M_INFO;
             if (g_pVSSClient->GetWriterState(i) < 1) {
                msg_type = M_WARNING;
                jcr->JobErrors++;
             }
             Jmsg(jcr, msg_type, 0, _("VSS Writer (BackupComplete): %s\n"),
 g_pVSSClient->GetWriterInfo(i));
          }
       }
       V(vss_mutex);
    }
 #endif
 }}}

 == and in filed/status.c ==

 {{{
 #ifdef WIN32_VSS
 #include "vss.h"
 #define VSS " VSS"
 extern VSSClient *g_pVSSClient;
 #else
 #define VSS ""
 #endif

 len = Mmsg(msg, "VSS %s, Priv 0x%x\n", g_pVSSClient?"enabled":"disabled",
 privs);


 #ifdef WIN32_VSS
    if (g_pVSSClient && g_pVSSClient->IsInitialized()) {
       vss = "VSS ";
    }
 #endif
 }}}

-- 
Ticket URL: <https://www.boxbackup.org/trac/ticket/13#comment:8>
Box Backup <http://www.boxbackup.org/>
An open source, completely automatic on-line backup system for UNIX.



More information about the Boxbackup-commit mailing list