]> git.sur5r.net Git - bacula/bacula/commitdiff
code-extenstions for VSS support on Win32 (preliminary, use #define WIN32_VSS for...
authorThorsten Engel <thorsten.engel@matrix-computer.com>
Tue, 17 May 2005 14:37:05 +0000 (14:37 +0000)
committerThorsten Engel <thorsten.engel@matrix-computer.com>
Tue, 17 May 2005 14:37:05 +0000 (14:37 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2055 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/filed/job.c
bacula/src/findlib/find.c
bacula/src/findlib/protos.h

index 6f0d401ba49a16e3268a57aef3bc2a7aa88f05b6..b6c61f34a5d931a13990127fb76e0a8181c7e49f 100644 (file)
 #include "bacula.h"
 #include "filed.h"
 
+#ifdef WIN32_VSS
+#include "vss.h"   
+#endif
+
 extern char my_name[];
 extern CLIENT *me;                    /* our client resource */
 
@@ -1195,9 +1199,25 @@ static int backup_cmd(JCR *jcr)
    if (!response(jcr, sd, OK_data, "Append Data")) {
       goto cleanup;
    }
-
+   
    generate_daemon_event(jcr, "JobStart");
 
+#ifdef WIN32_VSS
+   /* START VSS ON WIN 32 */
+   g_VSSClient.InitializeForBackup();
+   /* tell vss which drives to snapshot */   
+   char szWinDriveLetters[27];   
+   if (get_win32_driveletters((FF_PKT *)jcr->ff, szWinDriveLetters)) {
+      Jmsg(jcr, M_INFO, 0, _("Generate VSS snapshots. Drives=%s\n"), szWinDriveLetters);                 
+      g_VSSClient.CreateSnapshots(szWinDriveLetters);
+
+      for (int i=0; i<=strlen (szWinDriveLetters); i++) {
+         if (islower(szWinDriveLetters[i]))
+            Jmsg(jcr, M_WARNING, 0, _("Generate VSS snapshot of drive %c: failed\n"), szWinDriveLetters[i]);
+      }
+   }
+#endif
+
    /*
     * Send Files to Storage daemon
     */
@@ -1252,11 +1272,17 @@ static int backup_cmd(JCR *jcr)
    }
 
 cleanup:
+#ifdef WIN32_VSS
+   /* tell vss to close the backup session */
+   g_VSSClient.CloseBackup();
+#endif
+
    bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
       edit_uint64(jcr->ReadBytes, ed1),
       edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
    Dmsg1(110, "End FD msg: %s\n", dir->msg);
 
+   /* STOP VSS ON WIN 32 */
    return 0;                          /* return and stop command loop */
 }
 
index 3bb0d755a702ebe69f05c2639480852d615430e1..d38034b4751afcf8da4dc61db6be17d2f8d9f8de 100644 (file)
@@ -94,6 +94,55 @@ set_find_options(FF_PKT *ff, int incremental, time_t save_time)
   Dmsg0(100, "Leave set_find_options()\n");
 }
 
+/*
+ * For VSS we need to know which windows drives
+ * are used, because we create a snapshot of all used
+ * drives before operation
+ *
+ * the function returns the number of used drives and
+ * fills "drives" with up to 26 (A..Z) drive names
+ *
+ */
+int
+get_win32_driveletters(FF_PKT *ff, char* szDrives)
+{
+   /* szDrives must be at least 27 bytes long */
+
+#ifndef WIN32
+   return 0;
+#endif
+
+   szDrives[0] = 0; /* make empty */
+   int nCount = 0;
+    
+   findFILESET *fileset = ff->fileset;
+   if (fileset) {
+      int i, j;
+      
+      for (i=0; i<fileset->include_list.size(); i++) {
+         findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
+         
+         /* look through all files and check */
+         for (j=0; j<incexe->name_list.size(); j++) {
+            char *fname = (char *)incexe->name_list.get(j);
+            /* fname should match x:/ */
+            if (strlen (fname) > 3 && B_ISALPHA (fname[0]) 
+               && fname[1] == ':' && fname[2] == '/') {
+               
+               /* always add in uppercase */
+               char ch = toupper(fname[0]);
+               /* if not found in string, add drive letter */
+               if (!strchr(szDrives,ch)) {
+                  szDrives[nCount] = ch;
+                  szDrives[nCount+1] = 0;
+                  nCount++;
+               }                                
+            }            
+         }
+      }
+   }
+   return nCount;
+}
 
 /*
  * Find all specified files (determined by calls to name_add()
index 58a25498658294f43dc65598585be344b29f8d51..0c2837ecbe8c3ea510735f480eabe52bc797f350 100644 (file)
@@ -39,6 +39,7 @@ void  set_find_options(FF_PKT *ff, int incremental, time_t mtime);
 int   find_files(JCR *jcr, FF_PKT *ff, int sub(FF_PKT *ff_pkt, void *hpkt, bool), void *pkt);
 int   match_files(JCR *jcr, FF_PKT *ff, int sub(FF_PKT *ff_pkt, void *hpkt, bool), void *pkt);
 int   term_find_files(FF_PKT *ff);
+int   get_win32_driveletters(FF_PKT *ff, char* szDrives);
 
 /* From match.c */
 void  init_include_exclude_files(FF_PKT *ff);