]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/verify.c
85b5d245019247e4eeb56a97931a3ce2c542d0ee
[bacula/bacula] / bacula / src / dird / verify.c
1 /*
2  *
3  *   Bacula Director -- verify.c -- responsible for running file verification
4  *
5  *     Kern Sibbald, October MM
6  *
7  *    This routine is run as a separate thread.  There may be more
8  *    work to be done to make it totally reentrant!!!!
9  * 
10  * Current implementation is Catalog verification only (i.e. no
11  *  verification versus tape).
12  *
13  *  Basic tasks done here:
14  *     Open DB
15  *     Open connection with File daemon and pass him commands
16  *       to do the verify.
17  *     When the File daemon sends the attributes, compare them to
18  *       what is in the DB.
19  *
20  *   Version $Id$
21  */
22
23 /*
24    Copyright (C) 2000-2003 Kern Sibbald and John Walker
25
26    This program is free software; you can redistribute it and/or
27    modify it under the terms of the GNU General Public License as
28    published by the Free Software Foundation; either version 2 of
29    the License, or (at your option) any later version.
30
31    This program is distributed in the hope that it will be useful,
32    but WITHOUT ANY WARRANTY; without even the implied warranty of
33    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34    General Public License for more details.
35
36    You should have received a copy of the GNU General Public
37    License along with this program; if not, write to the Free
38    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
39    MA 02111-1307, USA.
40
41  */
42
43 #include "bacula.h"
44 #include "dird.h"
45 #include "findlib/find.h"
46
47 /* Imported Global Variables */
48 extern int debug_level;
49
50 /* Commands sent to File daemon */
51 static char verifycmd[]    = "verify level=%s\n";
52 static char storaddr[]     = "storage address=%s port=%d ssl=0\n";
53 static char sessioncmd[]   = "session %s %ld %ld %ld %ld %ld %ld\n";  
54
55 /* Responses received from File daemon */
56 static char OKverify[]    = "2000 OK verify\n";
57 static char OKstore[]     = "2000 OK storage\n";
58 static char OKsession[]   = "2000 OK session\n";
59
60 /* Forward referenced functions */
61 static void verify_cleanup(JCR *jcr, int TermCode);
62 static void prt_fname(JCR *jcr);
63 static int missing_handler(void *ctx, int num_fields, char **row);
64
65 /* 
66  * Do a verification of the specified files against the Catlaog
67  *    
68  *  Returns:  0 on failure
69  *            1 on success
70  */
71 int do_verify(JCR *jcr) 
72 {
73    char *level;
74    BSOCK   *fd;
75    JOB_DBR jr;
76    JobId_t JobId = 0;
77
78    if (!get_or_create_client_record(jcr)) {
79       goto bail_out;
80    }
81
82    Dmsg1(9, "bdird: created client %s record\n", jcr->client->hdr.name);
83
84    /* If we are doing a verify from the catalog,
85     * we must look up the time and date of the
86     * last full verify.
87     */
88    if (jcr->JobLevel == L_VERIFY_CATALOG || jcr->JobLevel == L_VERIFY_VOLUME_TO_CATALOG) {
89       memcpy(&jr, &(jcr->jr), sizeof(jr));
90       if (!db_find_last_jobid(jcr, jcr->db, &jr)) {
91          if (jcr->JobLevel == L_VERIFY_CATALOG) {
92             Jmsg(jcr, M_FATAL, 0, _(
93                  "Unable to find JobId of previous InitCatalog Job.\n"
94                  "Please run a Verify with Level=InitCatalog before\n"
95                  "running the current Job.\n"));
96           } else {
97             Jmsg(jcr, M_FATAL, 0, _(
98                  "Unable to find JobId of previous Job for this client.\n"));
99          }   
100          goto bail_out;
101       }
102       JobId = jr.JobId;
103       Dmsg1(20, "Last full id=%d\n", JobId);
104    } 
105
106    jcr->jr.JobId = jcr->JobId;
107    jcr->jr.StartTime = jcr->start_time;
108    jcr->jr.Level = jcr->JobLevel;
109    if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
110       Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
111       goto bail_out;
112    }
113
114    if (!jcr->fname) {
115       jcr->fname = (char *) get_pool_memory(PM_FNAME);
116    }
117
118    jcr->jr.JobId = JobId;      /* save target JobId */
119
120    /* Print Job Start message */
121    Jmsg(jcr, M_INFO, 0, _("Start Verify JobId %d Job=%s\n"),
122       jcr->JobId, jcr->Job);
123
124    if (jcr->JobLevel == L_VERIFY_CATALOG || jcr->JobLevel == L_VERIFY_VOLUME_TO_CATALOG) {
125       memset(&jr, 0, sizeof(jr));
126       jr.JobId = JobId;
127       if (!db_get_job_record(jcr, jcr->db, &jr)) {
128          Jmsg(jcr, M_FATAL, 0, _("Could not get job record for previous Job. ERR=%s"), 
129               db_strerror(jcr->db));
130          goto bail_out;
131       }
132       if (jr.JobStatus != 'T') {
133          Jmsg(jcr, M_FATAL, 0, _("Last Job %d did not terminate normally. JobStatus=%c\n"),
134             JobId, jr.JobStatus);
135          goto bail_out;
136       }
137       Jmsg(jcr, M_INFO, 0, _("Verifying against JobId=%d Job=%s\n"),
138          JobId, jr.Job); 
139    }
140
141    /* 
142     * If we are verifing a Volume, we need the Storage
143     *   daemon, so open a connection, otherwise, just
144     *   create a dummy authorization key (passed to
145     *   File daemon but not used).
146     */
147    if (jcr->JobLevel == L_VERIFY_VOLUME_TO_CATALOG) {
148       /*
149        * Now find the Volumes we will need for the Verify 
150        */
151       jcr->VolumeName[0] = 0;
152       if (!db_get_job_volume_names(jcr, jcr->db, jr.JobId, &jcr->VolumeName) ||
153            jcr->VolumeName[0] == 0) {
154          Jmsg(jcr, M_FATAL, 0, _("Cannot find Volume Name for verify JobId=%u. ERR=%s"), 
155             jr.JobId, db_strerror(jcr->db));
156          goto bail_out;
157       }
158       Dmsg1(20, "Got job Volume Names: %s\n", jcr->VolumeName);
159       /*
160        * Start conversation with Storage daemon  
161        */
162       set_jcr_job_status(jcr, JS_Blocked);
163       if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
164          goto bail_out;
165       }
166       /*
167        * Now start a job with the Storage daemon
168        */
169       if (!start_storage_daemon_job(jcr)) {
170          goto bail_out;
171       }
172       /*
173        * Now start a Storage daemon message thread
174        */
175       if (!start_storage_daemon_message_thread(jcr)) {
176          goto bail_out;
177       }
178       Dmsg0(50, "Storage daemon connection OK\n");
179    } else {
180       jcr->sd_auth_key = bstrdup("dummy");    /* dummy Storage daemon key */
181    }
182    /*
183     * OK, now connect to the File daemon
184     *  and ask him for the files.
185     */
186    set_jcr_job_status(jcr, JS_Blocked);
187    if (!connect_to_file_daemon(jcr, 10, FDConnectTimeout, 1)) {
188       goto bail_out;
189    }
190
191    set_jcr_job_status(jcr, JS_Running);
192    fd = jcr->file_bsock;
193
194    Dmsg0(30, ">filed: Send include list\n");
195    if (!send_include_list(jcr)) {
196       goto bail_out;
197    }
198
199    Dmsg0(30, ">filed: Send exclude list\n");
200    if (!send_exclude_list(jcr)) {
201       goto bail_out;
202    }
203
204    /* 
205     * Send Level command to File daemon, as well
206     *   as the Storage address if appropriate.
207     */
208    switch (jcr->JobLevel) {
209       case L_VERIFY_INIT:
210          level = "init";
211          break;
212       case L_VERIFY_CATALOG:
213          level = "catalog";
214          break;
215       case L_VERIFY_VOLUME_TO_CATALOG:
216          /* 
217           * send Storage daemon address to the File daemon
218           */
219          if (jcr->store->SDDport == 0) {
220             jcr->store->SDDport = jcr->store->SDport;
221          }
222          bnet_fsend(fd, storaddr, jcr->store->address, jcr->store->SDDport);
223          if (!response(fd, OKstore, "Storage", 1)) {
224             goto bail_out;
225          }
226          /*
227           * Pass the VolSessionId, VolSessionTime, Start and
228           * end File and Blocks on the session command.
229           */
230          bnet_fsend(fd, sessioncmd, 
231                    jcr->VolumeName,
232                    jr.VolSessionId, jr.VolSessionTime, 
233                    jr.StartFile, jr.EndFile, jr.StartBlock, 
234                    jr.EndBlock);
235          if (!response(fd, OKsession, "Session", 1)) {
236             goto bail_out;
237          }
238          level = "volume";
239          break;
240       case L_VERIFY_DATA:
241          level = "data";
242          break;
243       default:
244          Jmsg1(jcr, M_FATAL, 0, _("Unimplemented save level %d\n"), jcr->JobLevel);
245          goto bail_out;
246    }
247
248    /* 
249     * Send verify command/level to File daemon
250     */
251    bnet_fsend(fd, verifycmd, level);
252    if (!response(fd, OKverify, "Verify", 1)) {
253       goto bail_out;
254    }
255
256    /*
257     * Now get data back from File daemon and
258     *  compare it to the catalog or store it in the
259     *  catalog depending on the run type.
260     */
261    /* Compare to catalog */
262    switch (jcr->JobLevel) { 
263    case L_VERIFY_CATALOG:
264       Dmsg0(10, "Verify level=catalog\n");
265       get_attributes_and_compare_to_catalog(jcr, JobId);
266       break;
267
268    case L_VERIFY_VOLUME_TO_CATALOG:
269       int stat;
270       Dmsg0(10, "Verify level=volume\n");
271       get_attributes_and_compare_to_catalog(jcr, JobId);
272       stat = jcr->JobStatus;
273       set_jcr_job_status(jcr, JS_WaitSD);
274       wait_for_storage_daemon_termination(jcr);
275       /* If we terminate normally, use SD term code, else, use ours */
276       if (stat == JS_Terminated) {
277          set_jcr_job_status(jcr, jcr->SDJobStatus);
278       } else {
279          set_jcr_job_status(jcr, stat);
280       }
281       break;
282
283    case L_VERIFY_INIT:
284       /* Build catalog */
285       Dmsg0(10, "Verify level=init\n");
286       get_attributes_and_put_in_catalog(jcr);
287       break;
288
289    default:
290       Jmsg1(jcr, M_FATAL, 0, _("Unimplemented verify level %d\n"), jcr->JobLevel);
291       goto bail_out;
292    }
293
294    verify_cleanup(jcr, jcr->JobStatus);
295    return 1;
296
297 bail_out:
298    verify_cleanup(jcr, JS_ErrorTerminated);
299    return 0;
300 }
301
302 /*
303  * Release resources allocated during backup.
304  *
305  */
306 static void verify_cleanup(JCR *jcr, int TermCode)
307 {
308    char sdt[50], edt[50];
309    char ec1[30];
310    char term_code[100];
311    char *term_msg;
312    int msg_type;
313    JobId_t JobId;
314
315    Dmsg0(100, "Enter verify_cleanup()\n");
316
317    JobId = jcr->jr.JobId;
318    set_jcr_job_status(jcr, TermCode);
319
320    update_job_end_record(jcr);
321
322    msg_type = M_INFO;                 /* by default INFO message */
323    switch (TermCode) {
324       case JS_Terminated:
325          term_msg = _("Verify OK");
326          break;
327       case JS_ErrorTerminated:
328          term_msg = _("*** Verify Error ***"); 
329          msg_type = M_ERROR;          /* Generate error message */
330          break;
331       case JS_Canceled:
332          term_msg = _("Verify Canceled");
333          break;
334       case JS_Differences:
335          term_msg = _("Verify Differences");
336          break;
337       default:
338          term_msg = term_code;
339          sprintf(term_code, _("Inappropriate term code: %c\n"), TermCode);
340          break;
341    }
342    bstrftime(sdt, sizeof(sdt), jcr->jr.StartTime);
343    bstrftime(edt, sizeof(edt), jcr->jr.EndTime);
344
345    Jmsg(jcr, msg_type, 0, _("Bacula " VERSION " (" LSMDATE "): %s\n\
346 JobId:                  %d\n\
347 Job:                    %s\n\
348 FileSet:                %s\n\
349 Verify Level:           %s\n\
350 Client:                 %s\n\
351 Start time:             %s\n\
352 End time:               %s\n\
353 Files Examined:         %s\n\
354 Termination:            %s\n\n"),
355         edt,
356         jcr->jr.JobId,
357         jcr->jr.Job,
358         jcr->fileset->hdr.name,
359         level_to_str(jcr->JobLevel),
360         jcr->client->hdr.name,
361         sdt,
362         edt,
363         edit_uint64_with_commas(jcr->JobFiles, ec1),
364         term_msg);
365
366    Dmsg0(100, "Leave verify_cleanup()\n");
367    if (jcr->fname) {
368       free_memory(jcr->fname);
369       jcr->fname = NULL;
370    }
371 }
372
373 /*
374  * This routine is called only during a Verify
375  */
376 int get_attributes_and_compare_to_catalog(JCR *jcr, JobId_t JobId)
377 {
378    BSOCK   *fd;
379    int n, len;
380    FILE_DBR fdbr;
381    struct stat statf;                 /* file stat */
382    struct stat statc;                 /* catalog stat */
383    int stat = JS_Terminated;
384    char buf[MAXSTRING];
385    POOLMEM *fname = get_pool_memory(PM_MESSAGE);
386    int do_SIG = NO_SIG;
387    long file_index = 0;
388
389    memset(&fdbr, 0, sizeof(FILE_DBR));
390    fd = jcr->file_bsock;
391    fdbr.JobId = JobId;
392    jcr->FileIndex = 0;
393    
394    Dmsg0(20, "bdird: waiting to receive file attributes\n");
395    /*
396     * Get Attributes and Signature from File daemon
397     * We expect:
398     *   FileIndex
399     *   Stream
400     *   Options or SIG (MD5/SHA1)
401     *   Filename
402     *   Attributes
403     *   Link name  ???
404     */
405    while ((n=bget_dirmsg(fd)) >= 0 && !job_canceled(jcr)) {
406       int stream;
407       char *attr, *p, *fn;
408       char Opts_SIG[MAXSTRING];        /* Verify Opts or MD5/SHA1 signature */
409
410       fname = check_pool_memory_size(fname, fd->msglen);
411       jcr->fname = check_pool_memory_size(jcr->fname, fd->msglen);
412       Dmsg1(400, "Atts+SIG=%s\n", fd->msg);
413       if ((len = sscanf(fd->msg, "%ld %d %100s", &file_index, &stream, 
414             fname)) != 3) {
415          Jmsg3(jcr, M_FATAL, 0, _("bird<filed: bad attributes, expected 3 fields got %d\n\
416  mslen=%d msg=%s\n"), len, fd->msglen, fd->msg);
417          goto bail_out;
418       }
419       /*
420        * We read the Options or Signature into fname                                
421        *  to prevent overrun, now copy it to proper location.
422        */
423       bstrncpy(Opts_SIG, fname, sizeof(Opts_SIG));
424       p = fd->msg;
425       skip_nonspaces(&p);             /* skip FileIndex */
426       skip_spaces(&p);
427       skip_nonspaces(&p);             /* skip Stream */
428       skip_spaces(&p);
429       skip_nonspaces(&p);             /* skip Opts_SIG */   
430       p++;                            /* skip space */
431       fn = fname;
432       while (*p != 0) {
433          *fn++ = *p++;                /* copy filename */
434       }
435       *fn = *p++;                     /* term filename and point to attribs */
436       attr = p;
437       /*
438        * Got attributes stream, decode it
439        */
440       if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_WIN32_ATTRIBUTES) {
441          uint32_t LinkFIf, LinkFIc;
442          Dmsg2(400, "file_index=%d attr=%s\n", file_index, attr);
443          jcr->JobFiles++;
444          jcr->FileIndex = file_index;    /* remember attribute file_index */
445          decode_stat(attr, &statf, &LinkFIf);  /* decode file stat packet */
446          do_SIG = NO_SIG;
447          jcr->fn_printed = FALSE;
448          strcpy(jcr->fname, fname);  /* move filename into JCR */
449
450          Dmsg2(040, "dird<filed: stream=%d %s\n", stream, jcr->fname);
451          Dmsg1(020, "dird<filed: attr=%s\n", attr);
452
453          /* 
454           * Find equivalent record in the database 
455           */
456          fdbr.FileId = 0;
457          if (!db_get_file_attributes_record(jcr, jcr->db, jcr->fname, &fdbr)) {
458             Jmsg(jcr, M_INFO, 0, _("New file: %s\n"), jcr->fname);
459             Dmsg1(020, _("File not in catalog: %s\n"), jcr->fname);
460             stat = JS_Differences;
461             continue;
462          } else {
463             /* 
464              * mark file record as visited by stuffing the
465              * current JobId, which is unique, into the MarkId field.
466              */
467             db_mark_file_record(jcr, jcr->db, fdbr.FileId, jcr->JobId);
468          }
469
470          Dmsg3(400, "Found %s in catalog. inx=%d Opts=%s\n", jcr->fname, 
471             file_index, Opts_SIG);
472          decode_stat(fdbr.LStat, &statc, &LinkFIc); /* decode catalog stat */
473          /*
474           * Loop over options supplied by user and verify the
475           * fields he requests.
476           */
477          for (p=Opts_SIG; *p; p++) {
478             char ed1[30], ed2[30];
479             switch (*p) {
480             case 'i':                /* compare INODEs */
481                if (statc.st_ino != statf.st_ino) {
482                   prt_fname(jcr);
483                   Jmsg(jcr, M_INFO, 0, _("      st_ino   differ. Cat: %s File: %s\n"), 
484                      edit_uint64((uint64_t)statc.st_ino, ed1),
485                      edit_uint64((uint64_t)statf.st_ino, ed2));
486                   stat = JS_Differences;
487                }
488                break;
489             case 'p':                /* permissions bits */
490                if (statc.st_mode != statf.st_mode) {
491                   prt_fname(jcr);
492                   Jmsg(jcr, M_INFO, 0, _("      st_mode  differ. Cat: %x File: %x\n"), 
493                      (uint32_t)statc.st_mode, (uint32_t)statf.st_mode);
494                   stat = JS_Differences;
495                }
496                break;
497             case 'n':                /* number of links */
498                if (statc.st_nlink != statf.st_nlink) {
499                   prt_fname(jcr);
500                   Jmsg(jcr, M_INFO, 0, _("      st_nlink differ. Cat: %d File: %d\n"), 
501                      (uint32_t)statc.st_nlink, (uint32_t)statf.st_nlink);
502                   stat = JS_Differences;
503                }
504                break;
505             case 'u':                /* user id */
506                if (statc.st_uid != statf.st_uid) {
507                   prt_fname(jcr);
508                   Jmsg(jcr, M_INFO, 0, _("      st_uid   differ. Cat: %u File: %u\n"), 
509                      (uint32_t)statc.st_uid, (uint32_t)statf.st_uid);
510                   stat = JS_Differences;
511                }
512                break;
513             case 'g':                /* group id */
514                if (statc.st_gid != statf.st_gid) {
515                   prt_fname(jcr);
516                   Jmsg(jcr, M_INFO, 0, _("      st_gid   differ. Cat: %u File: %u\n"), 
517                      (uint32_t)statc.st_gid, (uint32_t)statf.st_gid);
518                   stat = JS_Differences;
519                }
520                break;
521             case 's':                /* size */
522                if (statc.st_size != statf.st_size) {
523                   prt_fname(jcr);
524                   Jmsg(jcr, M_INFO, 0, _("      st_size  differ. Cat: %s File: %s\n"), 
525                      edit_uint64((uint64_t)statc.st_size, ed1),
526                      edit_uint64((uint64_t)statf.st_size, ed2));
527                   stat = JS_Differences;
528                }
529                break;
530             case 'a':                /* access time */
531                if (statc.st_atime != statf.st_atime) {
532                   prt_fname(jcr);
533                   Jmsg(jcr, M_INFO, 0, _("      st_atime differs\n"));
534                   stat = JS_Differences;
535                }
536                break;
537             case 'm':
538                if (statc.st_mtime != statf.st_mtime) {
539                   prt_fname(jcr);
540                   Jmsg(jcr, M_INFO, 0, _("      st_mtime differs\n"));
541                   stat = JS_Differences;
542                }
543                break;
544             case 'c':                /* ctime */
545                if (statc.st_ctime != statf.st_ctime) {
546                   prt_fname(jcr);
547                   Jmsg(jcr, M_INFO, 0, _("      st_ctime differs\n"));
548                   stat = JS_Differences;
549                }
550                break;
551             case 'd':                /* file size decrease */
552                if (statc.st_size > statf.st_size) {
553                   prt_fname(jcr);
554                   Jmsg(jcr, M_INFO, 0, _("      st_size  decrease. Cat: %s File: %s\n"), 
555                      edit_uint64((uint64_t)statc.st_size, ed1),
556                      edit_uint64((uint64_t)statf.st_size, ed2));
557                   stat = JS_Differences;
558                }
559                break;
560             case '5':                /* compare MD5 */
561                Dmsg1(500, "set Do_MD5 for %s\n", jcr->fname);
562                do_SIG = MD5_SIG;
563                break;
564             case '1':                 /* compare SHA1 */
565                do_SIG = SHA1_SIG;
566                break;
567             case ':':
568             case 'V':
569             default:
570                break;
571             }
572          }
573       /*
574        * Got SIG Signature from Storage daemon
575        *  It came across in the Opts_SIG field.
576        */
577       } else if (stream == STREAM_MD5_SIGNATURE || stream == STREAM_SHA1_SIGNATURE) {
578          Dmsg2(400, "stream=SIG inx=%d SIG=%s\n", file_index, Opts_SIG);
579          /* 
580           * When ever we get a signature is MUST have been
581           * preceded by an attributes record, which sets attr_file_index
582           */
583          if (jcr->FileIndex != (uint32_t)file_index) {
584             Jmsg2(jcr, M_FATAL, 0, _("MD5/SHA1 index %d not same as attributes %d\n"),
585                file_index, jcr->FileIndex);
586             goto bail_out;
587          } 
588          if (do_SIG) {
589             db_escape_string(buf, Opts_SIG, strlen(Opts_SIG));
590             if (strcmp(buf, fdbr.SIG) != 0) {
591                prt_fname(jcr);
592                if (debug_level >= 10) {
593                   Jmsg(jcr, M_INFO, 0, _("      %s not same. File=%s Cat=%s\n"), 
594                        stream==STREAM_MD5_SIGNATURE?"MD5":"SHA1", buf, fdbr.SIG);
595                } else {
596                   Jmsg(jcr, M_INFO, 0, _("      %s differs.\n"), 
597                        stream==STREAM_MD5_SIGNATURE?"MD5":"SHA1");
598                }
599                stat = JS_Differences;
600             }
601             do_SIG = FALSE;
602          }
603       }
604       jcr->JobFiles = file_index;
605    } 
606    if (is_bnet_error(fd)) {
607       Jmsg2(jcr, M_FATAL, 0, _("bdird<filed: bad attributes from filed n=%d : %s\n"),
608                         n, strerror(errno));
609       goto bail_out;
610    }
611
612    /* Now find all the files that are missing -- i.e. all files in
613     *  the database where the MarkedId != current JobId
614     */
615    jcr->fn_printed = FALSE;
616    sprintf(buf, 
617 "SELECT Path.Path,Filename.Name FROM File,Path,Filename "
618 "WHERE File.JobId=%d "
619 "AND File.MarkedId!=%d AND File.PathId=Path.PathId "
620 "AND File.FilenameId=Filename.FilenameId", 
621       JobId, jcr->JobId);
622    /* missing_handler is called for each file found */
623    db_sql_query(jcr->db, buf, missing_handler, (void *)jcr);
624    if (jcr->fn_printed) {
625       stat = JS_Differences;
626    }
627    free_pool_memory(fname);
628    set_jcr_job_status(jcr, stat);
629    return 1;
630     
631 bail_out:
632    free_pool_memory(fname);
633    set_jcr_job_status(jcr, JS_ErrorTerminated);
634    return 0;
635 }
636
637 /*
638  * We are called here for each record that matches the above
639  *  SQL query -- that is for each file contained in the Catalog
640  *  that was not marked earlier. This means that the file in
641  *  question is a missing file (in the Catalog but on on Disk).
642  */
643 static int missing_handler(void *ctx, int num_fields, char **row)
644 {
645    JCR *jcr = (JCR *)ctx;
646
647    if (!jcr->fn_printed) {
648       Jmsg(jcr, M_INFO, 0, "\n");
649       Jmsg(jcr, M_INFO, 0, _("The following files are missing:\n"));
650       jcr->fn_printed = TRUE;
651    }
652    Jmsg(jcr, M_INFO, 0, "      %s%s\n", row[0]?row[0]:"", row[1]?row[1]:"");
653    return 0;
654 }
655
656
657 /* 
658  * Print filename for verify
659  */
660 static void prt_fname(JCR *jcr)
661 {
662    if (!jcr->fn_printed) {
663       Jmsg(jcr, M_INFO, 0, _("File: %s\n"), jcr->fname);
664       jcr->fn_printed = TRUE;
665    }
666 }