1 Index: src/dird/fd_cmds.c
2 ===================================================================
3 --- src/dird/fd_cmds.c (révision 6467)
4 +++ src/dird/fd_cmds.c (copie de travail)
6 static char filesetcmd[] = "fileset%s\n"; /* set full fileset */
7 static char jobcmd[] = "JobId=%s Job=%s SDid=%u SDtime=%u Authorization=%s\n";
8 /* Note, mtime_only is not used here -- implemented as file option */
9 -static char levelcmd[] = "level = %s%s mtime_only=%d\n";
10 +static char levelcmd[] = "level = %s%s%s mtime_only=%d\n";
11 static char runscript[] = "Run OnSuccess=%u OnFailure=%u AbortOnError=%u When=%u Command=%s\n";
12 static char runbeforenow[]= "RunBeforeNow\n";
17 stime = str_to_utime(jcr->stime);
18 - fd->fsend(levelcmd, NT_("since_utime "), edit_uint64(stime, ed1), 0);
19 + fd->fsend(levelcmd, "", NT_("since_utime "), edit_uint64(stime, ed1), 0);
20 while (bget_dirmsg(fd) >= 0) { /* allow him to poll us to sync clocks */
21 Jmsg(jcr, M_INFO, 0, "%s\n", fd->msg);
27 * Send level command to FD.
28 * Used for backup jobs and estimate command.
30 bool send_level_command(JCR *jcr)
32 BSOCK *fd = jcr->file_bsock;
33 + const char *accurate=jcr->job->accurate?"accurate_":"";
34 + const char *not_accurate="";
36 * Send Level command to File daemon
38 switch (jcr->JobLevel) {
40 - fd->fsend(levelcmd, "base", " ", 0);
41 + fd->fsend(levelcmd, not_accurate, "base", " ", 0);
43 /* L_NONE is the console, sending something off to the FD */
46 - fd->fsend(levelcmd, "full", " ", 0);
47 + fd->fsend(levelcmd, not_accurate, "full", " ", 0);
50 - fd->fsend(levelcmd, "differential", " ", 0);
51 + fd->fsend(levelcmd, accurate, "differential", " ", 0);
55 - fd->fsend(levelcmd, "incremental", " ", 0);
56 + fd->fsend(levelcmd, accurate, "incremental", " ", 0);
60 Index: src/dird/backup.c
61 ===================================================================
62 --- src/dird/backup.c (révision 6467)
63 +++ src/dird/backup.c (copie de travail)
68 + * Foreach files in currrent list, send "/path/fname\0LStat" to FD
70 +static int accurate_list_handler(void *ctx, int num_fields, char **row)
72 + JCR *jcr = (JCR *)ctx;
74 + if (job_canceled(jcr)) {
78 + if (row[2] > 0) { /* discard when file_index == 0 */
79 + jcr->file_bsock->fsend("%s%s%c%s", row[0], row[1], 0, row[4]);
85 + * Send current file list to FD
86 + * DIR -> FD : accurate files=xxxx
87 + * DIR -> FD : /path/to/file\0Lstat
88 + * DIR -> FD : /path/to/dir/\0Lstat
92 +bool send_accurate_current_files(JCR *jcr)
96 + if (jcr->accurate==false || job_canceled(jcr) || jcr->JobLevel==L_FULL) {
99 + POOLMEM *jobids = get_pool_memory(PM_FNAME);
100 + db_accurate_get_jobids(jcr, jcr->db, &jcr->jr, jobids);
102 + if (*jobids == 0) {
103 + free_pool_memory(jobids);
104 + Jmsg(jcr, M_FATAL, 0, _("Cannot find previous jobids.\n"));
107 + Jmsg(jcr, M_INFO, 0, _("Sending Accurate informations.\n"));
109 + /* to be able to allocate the right size for htable */
110 + POOLMEM *nb = get_pool_memory(PM_FNAME);
111 + Mmsg(buf, "SELECT sum(JobFiles) FROM Job WHERE JobId IN (%s)",jobids);
112 + db_sql_query(jcr->db, buf.c_str(), db_get_int_handler, nb);
113 + jcr->file_bsock->fsend("accurate files=%s\n", nb);
115 + db_get_file_list(jcr, jcr->db, jobids, accurate_list_handler, (void *)jcr);
117 + free_pool_memory(jobids);
118 + free_pool_memory(nb);
120 + jcr->file_bsock->signal(BNET_EOD);
121 + /* TODO: use response() ? */
127 * Do a backup of the specified FileSet
129 * Returns: false on failure
131 Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
135 + * If backup is in accurate mode, we send the list of
138 + if (!send_accurate_current_files(jcr)) {
142 /* Send backup command */
143 fd->fsend(backupcmd);
144 if (!response(jcr, fd, OKbackup, "backup", DISPLAY_ERROR)) {
146 " Software Compression: %s\n"
150 " Volume name(s): %s\n"
151 " Volume Session Id: %d\n"
152 " Volume Session Time: %d\n"
154 edit_uint64_with_suffix(jcr->SDJobBytes, ec6),
157 - jcr->VSS?"yes":"no",
158 - jcr->Encrypt?"yes":"no",
159 + jcr->VSS?_("yes"):_("no"),
160 + jcr->Encrypt?_("yes"):_("no"),
161 + jcr->accurate?_("yes"):_("no"),
165 Index: src/dird/ua_restore.c
166 ===================================================================
167 --- src/dird/ua_restore.c (révision 6467)
168 +++ src/dird/ua_restore.c (copie de travail)
169 @@ -1005,7 +1005,6 @@
170 * For display purposes, the same JobId, with different volumes may
171 * appear more than once, however, we only insert it once.
175 tree.FileEstimate = 0;
176 if (get_next_jobid_from_list(&p, &JobId) > 0) {
177 @@ -1020,23 +1019,12 @@
178 tree.DeltaCount = rx->JobId/50; /* print 50 ticks */
181 - for (p=rx->JobIds; get_next_jobid_from_list(&p, &JobId) > 0; ) {
184 - if (JobId == last_JobId) {
185 - continue; /* eliminate duplicate JobIds */
187 - last_JobId = JobId;
188 - ua->info_msg(_("\nBuilding directory tree for JobId %s ... "),
189 - edit_int64(JobId, ed1));
192 - * Find files for this JobId and insert them in the tree
194 - Mmsg(rx->query, uar_sel_files, edit_int64(JobId, ed1));
195 - if (!db_sql_query(ua->db, rx->query, insert_tree_handler, (void *)&tree)) {
196 - ua->error_msg("%s", db_strerror(ua->db));
198 + ua->info_msg(_("\nBuilding directory tree for JobId(s) %s ... "),
201 + if (!db_get_file_list(ua->jcr, ua->db, rx->JobIds, insert_tree_handler, (void *)&tree)) {
202 + ua->error_msg("%s", db_strerror(ua->db));
204 if (tree.FileCount == 0) {
205 ua->send_msg(_("\nThere were no files inserted into the tree, so file selection\n"
206 @@ -1055,26 +1043,13 @@
212 - ua->info_msg(_("\n1 Job, %s files inserted into the tree and marked for extraction.\n"),
213 - edit_uint64_with_commas(tree.FileCount, ec1));
216 - ua->info_msg(_("\n1 Job, %s files inserted into the tree.\n"),
217 - edit_uint64_with_commas(tree.FileCount, ec1));
220 + ua->info_msg(_("\n%s files inserted into the tree and marked for extraction.\n"),
221 + edit_uint64_with_commas(tree.FileCount, ec1));
223 + ua->info_msg(_("\n%s files inserted into the tree.\n"),
224 + edit_uint64_with_commas(tree.FileCount, ec1));
228 - ua->info_msg(_("\n%d Jobs, %s files inserted into the tree and marked for extraction.\n"),
229 - items, edit_uint64_with_commas(tree.FileCount, ec1));
232 - ua->info_msg(_("\n%d Jobs, %s files inserted into the tree.\n"),
233 - items, edit_uint64_with_commas(tree.FileCount, ec1));
237 if (find_arg(ua, NT_("done")) < 0) {
238 /* Let the user interact in selecting which files to restore */
239 Index: src/filed/backup.c
240 ===================================================================
241 --- src/filed/backup.c (révision 6467)
242 +++ src/filed/backup.c (copie de travail)
247 +#include "lib/htable.h"
249 /* Forward referenced functions */
250 int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level);
252 static bool crypto_session_start(JCR *jcr);
253 static void crypto_session_end(JCR *jcr);
254 static bool crypto_session_send(JCR *jcr, BSOCK *sd);
255 +static bool encode_and_send_deleted_file(JCR *jcr, char *fname);
257 +typedef struct CurFile {
264 + * This function is called for each file seen in fileset.
265 + * We check in file_list hash if fname have been backuped
266 + * the last time. After we can compare Lstat field. When
267 + * a file have been seen, we put '\0' in LStat field.
270 +/* TODO: tweak verify code to use the same function ?? */
271 +bool accurate_check_file(JCR *jcr, FF_PKT *ff_pkt)
275 + struct stat statc; /* catalog stat */
276 + char *Opts_Digest = ff_pkt->VerifyOpts;
277 + char *fname = ff_pkt->fname;
282 + if (jcr->accurate == false || jcr->JobLevel == L_FULL) {
286 + if (S_ISDIR(ff_pkt->statp.st_mode)) {
287 + fname = ff_pkt->link;
290 + elt = (CurFile *) jcr->file_list->lookup(fname);
293 + Dmsg1(500, "accurate %s = yes (not found)\n", fname);
297 + if (*elt->lstat == '\0') {
298 + Dmsg1(500, "accurate %s = no (already seen)\n", fname);
302 + decode_stat(elt->lstat, &statc, &LinkFIc); /* decode catalog stat */
303 +// *do_Digest = CRYPTO_DIGEST_NONE;
305 + for (p=Opts_Digest; *p; p++) {
306 + char ed1[30], ed2[30];
308 + case 'i': /* compare INODEs */
309 + if (statc.st_ino != ff_pkt->statp.st_ino) {
310 + Jmsg(jcr, M_SAVED, 0, _("%s st_ino differ. Cat: %s File: %s\n"), fname,
311 + edit_uint64((uint64_t)statc.st_ino, ed1),
312 + edit_uint64((uint64_t)ff_pkt->statp.st_ino, ed2));
316 + case 'p': /* permissions bits */
317 + if (statc.st_mode != ff_pkt->statp.st_mode) {
318 + Jmsg(jcr, M_SAVED, 0, _("%s st_mode differ. Cat: %x File: %x\n"), fname,
319 + (uint32_t)statc.st_mode, (uint32_t)ff_pkt->statp.st_mode);
323 +// case 'n': /* number of links */
324 +// if (statc.st_nlink != ff_pkt->statp.st_nlink) {
325 +// Jmsg(jcr, M_SAVED, 0, _("%s st_nlink differ. Cat: %d File: %d\n"), fname,
326 +// (uint32_t)statc.st_nlink, (uint32_t)ff_pkt->statp.st_nlink);
330 + case 'u': /* user id */
331 + if (statc.st_uid != ff_pkt->statp.st_uid) {
332 + Jmsg(jcr, M_SAVED, 0, _("%s st_uid differ. Cat: %u File: %u\n"), fname,
333 + (uint32_t)statc.st_uid, (uint32_t)ff_pkt->statp.st_uid);
337 + case 'g': /* group id */
338 + if (statc.st_gid != ff_pkt->statp.st_gid) {
339 + Jmsg(jcr, M_SAVED, 0, _("%s st_gid differ. Cat: %u File: %u\n"), fname,
340 + (uint32_t)statc.st_gid, (uint32_t)ff_pkt->statp.st_gid);
344 + case 's': /* size */
345 + if (statc.st_size != ff_pkt->statp.st_size) {
346 + Jmsg(jcr, M_SAVED, 0, _("%s st_size differ. Cat: %s File: %s\n"), fname,
347 + edit_uint64((uint64_t)statc.st_size, ed1),
348 + edit_uint64((uint64_t)ff_pkt->statp.st_size, ed2));
352 +// case 'a': /* access time */
353 +// if (statc.st_atime != ff_pkt->statp.st_atime) {
354 +// Jmsg(jcr, M_SAVED, 0, _("%s st_atime differs\n"), fname);
359 + if (statc.st_mtime != ff_pkt->statp.st_mtime) {
360 + Jmsg(jcr, M_SAVED, 0, _("%s st_mtime differs\n"), fname);
364 + case 'c': /* ctime */
365 + if (statc.st_ctime != ff_pkt->statp.st_ctime) {
366 + Jmsg(jcr, M_SAVED, 0, _("%s st_ctime differs\n"), fname);
370 + case 'd': /* file size decrease */
371 + if (statc.st_size > ff_pkt->statp.st_size) {
372 + Jmsg(jcr, M_SAVED, 0, _("%s st_size decrease. Cat: %s File: %s\n"), fname,
373 + edit_uint64((uint64_t)statc.st_size, ed1),
374 + edit_uint64((uint64_t)ff_pkt->statp.st_size, ed2));
378 + case '5': /* compare MD5 */
379 + Dmsg1(500, "set Do_MD5 for %s\n", ff_pkt->fname);
380 +// *do_Digest = CRYPTO_DIGEST_MD5;
382 + case '1': /* compare SHA1 */
383 +// *do_Digest = CRYPTO_DIGEST_SHA1;
391 + *elt->lstat = '\0'; /* mark it as seen */
392 + Dmsg2(500, "accurate %s = %i\n", fname, stat);
397 + * This function doesn't work very well with smartalloc
398 + * TODO: use bigbuffer from htable
400 +int accurate_cmd(JCR *jcr)
402 + BSOCK *dir = jcr->dir_bsock;
407 + if (jcr->accurate==false || job_canceled(jcr) || jcr->JobLevel==L_FULL) {
411 + if (sscanf(dir->msg, "accurate files=%ld", &nb) != 1) {
412 + dir->fsend(_("2991 Bad accurate command\n"));
416 + jcr->file_list = (htable *)malloc(sizeof(htable));
417 + jcr->file_list->init(elt, &elt->link, nb);
420 + * buffer = sizeof(CurFile) + dirmsg
421 + * dirmsg = fname + lstat
423 + /* get current files */
424 + while (dir->recv() >= 0) {
425 + len = strlen(dir->msg);
426 + if ((len+1) < dir->msglen) {
427 +// elt = (CurFile *)malloc(sizeof(CurFile));
428 +// elt->fname = (char *) malloc(dir->msglen+1);
430 + /* we store CurFile, fname and lstat in the same chunk */
431 + elt = (CurFile *)malloc(sizeof(CurFile)+dir->msglen+1);
432 + elt->fname = (char *) elt+sizeof(CurFile);
433 + memcpy(elt->fname, dir->msg, dir->msglen);
434 + elt->fname[dir->msglen]='\0';
435 + elt->lstat = elt->fname + len + 1;
436 + jcr->file_list->insert(elt->fname, elt);
437 + Dmsg2(500, "add fname=%s lstat=%s\n", elt->fname, elt->lstat);
441 +// jcr->file_list->stats();
442 + /* TODO: send a EOM ?
443 + dir->fsend("2000 OK accurate\n");
448 +bool accurate_send_deleted_list(JCR *jcr)
450 + if (jcr->accurate == false || jcr->JobLevel == L_FULL) {
454 + if (jcr->file_list == NULL) {
459 + foreach_htable (elt, jcr->file_list) {
460 + if (*elt->lstat != '\0') { /* already seen */
461 + Dmsg2(500, "deleted fname=%s lstat=%s\n", elt->fname, elt->lstat);
462 + encode_and_send_deleted_file(jcr, elt->fname);
464 +// free(elt->fname);
466 + jcr->file_list->destroy(); /* TODO: clean htable when this function is not reached ? */
467 + free(jcr->file_list);
468 + jcr->file_list = NULL;
473 * Find all the requested files and send them
474 * to the Storage daemon.
478 jcr->compress_buf_size = jcr->buf_size + ((jcr->buf_size+999) / 1000) + 30;
479 jcr->compress_buf = get_memory(jcr->compress_buf_size);
483 z_stream *pZlibStream = (z_stream*)malloc(sizeof(z_stream));
485 @@ -121,10 +338,13 @@
489 - Dmsg1(300, "set_find_options ff=%p\n", jcr->ff);
490 set_find_options((FF_PKT *)jcr->ff, jcr->incremental, jcr->mtime);
491 - Dmsg0(300, "start find files\n");
493 + /* in accurate mode, we overwrite the find_one check function */
494 + if (jcr->accurate) {
495 + set_find_changed_function((FF_PKT *)jcr->ff, accurate_check_file);
498 start_heartbeat_monitor(jcr);
500 jcr->acl_text = get_pool_memory(PM_MESSAGE);
502 set_jcr_job_status(jcr, JS_ErrorTerminated);
505 + accurate_send_deleted_list(jcr); /* send deleted list to SD */
507 free_pool_memory(jcr->acl_text);
509 stop_heartbeat_monitor(jcr);
510 @@ -1128,6 +1350,58 @@
514 +static bool encode_and_send_deleted_file(JCR *jcr, char *fname)
516 + BSOCK *sd = jcr->store_bsock;
520 +#ifdef FD_NO_SEND_TEST
528 + * Send Attributes header to Storage daemon
529 + * <file-index> <stream> <info>
531 + if (!sd->fsend("%ld %d 0", 0, STREAM_UNIX_ATTRIBUTES)) {
532 + Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
536 + Dmsg1(300, ">stored: attrhdr %s\n", sd->msg);
539 + * Send file attributes to Storage daemon
542 + * Filename (full path)
543 + * Encoded attributes
544 + * Link name (if type==FT_LNK or FT_LNKSAVED)
545 + * Encoded extended-attributes (for Win32)
547 + * For a directory, link is the same as fname, but with trailing
548 + * slash. For a linked file, link is the link.
550 + stat = sd->fsend("%ld %d %s%c%s%c%s%c%s%c",
552 + FT_NOSTAT /* FileType */,
553 + fname /* FileName */,
554 + 0, attribs, 0, 0, 0, attribsEx, 0);
556 + Dmsg2(300, ">stored: attr len=%d: %s\n", sd->msglen, sd->msg);
558 + Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
562 + sd->signal(BNET_EOD); /* indicate end of attributes data */
567 * Do in place strip of path
569 Index: src/filed/job.c
570 ===================================================================
571 --- src/filed/job.c (révision 6467)
572 +++ src/filed/job.c (copie de travail)
574 /* Imported functions */
575 extern int status_cmd(JCR *jcr);
576 extern int qstatus_cmd(JCR *jcr);
577 +extern int accurate_cmd(JCR *jcr);
579 /* Forward referenced functions */
580 static int backup_cmd(JCR *jcr);
582 {"RunBeforeJob", runbefore_cmd, 0},
583 {"RunAfterJob", runafter_cmd, 0},
584 {"Run", runscript_cmd, 0},
585 + {"accurate", accurate_cmd, 0},
586 {NULL, NULL} /* list terminator */
589 @@ -1195,6 +1197,9 @@
591 level = get_memory(dir->msglen+1);
592 Dmsg1(110, "level_cmd: %s", dir->msg);
593 + if (strstr(dir->msg, "accurate")) {
594 + jcr->accurate = true;
596 if (sscanf(dir->msg, "level = %s ", level) != 1) {
599 @@ -1204,14 +1209,14 @@
600 /* Full backup requested? */
601 } else if (strcmp(level, "full") == 0) {
602 jcr->JobLevel = L_FULL;
603 - } else if (strcmp(level, "differential") == 0) {
604 + } else if (strstr(level, "differential")) {
605 jcr->JobLevel = L_DIFFERENTIAL;
608 - } else if (strcmp(level, "incremental") == 0) {
609 + } else if (strstr(level, "incremental")) {
610 jcr->JobLevel = L_INCREMENTAL;
615 * We get his UTC since time, then sync the clocks and correct it
616 * to agree with our clock.
617 Index: src/filed/restore.c
618 ===================================================================
619 --- src/filed/restore.c (révision 6467)
620 +++ src/filed/restore.c (copie de travail)
625 + /* TODO: manage deleted files */
626 + if (file_index == 0) { /* deleted file */
631 * Unpack attributes and do sanity check them
633 Index: src/cats/protos.h
634 ===================================================================
635 --- src/cats/protos.h (révision 6467)
636 +++ src/cats/protos.h (copie de travail)
638 int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cdbr);
639 int db_get_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr);
640 bool db_get_query_dbids(JCR *jcr, B_DB *mdb, POOL_MEM &query, dbid_list &ids);
641 +bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, DB_RESULT_HANDLER *result_handler, void *ctx);
642 +bool db_accurate_get_jobids(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM *jobids);
643 +int db_get_int_handler(void *ctx, int num_fields, char **row);
647 Index: src/cats/sql_get.c
648 ===================================================================
649 --- src/cats/sql_get.c (révision 6467)
650 +++ src/cats/sql_get.c (copie de travail)
659 * Returns: false: on failure
660 @@ -1018,5 +1016,126 @@
664 +bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids,
665 + DB_RESULT_HANDLER *result_handler, void *ctx)
667 + if (*jobids == 0) {
669 + Mmsg(mdb->errmsg, _("ERR=JobIds are empty\n"));
674 + POOL_MEM buf (PM_MESSAGE);
677 + "SELECT Path.Path, Filename.Name, File.FileIndex, File.JobId, File.LStat "
679 + "SELECT max(FileId) as FileId, PathId, FilenameId "
680 + "FROM (SELECT FileId, PathId, FilenameId FROM File WHERE JobId IN (%s)) AS F "
681 + "GROUP BY PathId, FilenameId "
683 + "JOIN Filename ON (Filename.FilenameId = Temp.FilenameId) "
684 + "JOIN Path ON (Path.PathId = Temp.PathId) "
685 + "JOIN File ON (File.FileId = Temp.FileId) "
686 + "WHERE File.FileIndex > 0 ",
689 + return db_sql_query(mdb, buf.c_str(), result_handler, ctx);
693 +/* Full : do nothing
694 + * Differential : get the last full id
695 + * Incremental : get the last full + last diff + last incr(s) ids
697 + * TODO: look and merge from ua_restore.c
699 +bool db_accurate_get_jobids(JCR *jcr, B_DB *mdb,
700 + JOB_DBR *jr, POOLMEM *jobids)
702 + char clientid[50], jobid[50], filesetid[50];
703 + char date[MAX_TIME_LENGTH];
705 + POOL_MEM query (PM_FNAME);
706 + bstrutime(date, sizeof(date), time(NULL) + 1);
710 +"CREATE TEMPORARY TABLE btemp3%s AS "
711 + "SELECT JobId, StartTime, EndTime, JobTDate, PurgedFiles "
712 + "FROM Job JOIN FileSet USING (FileSetId) "
713 + "WHERE ClientId = %s "
714 + "AND Level='F' AND JobStatus='T' AND Type='B' "
715 + "AND StartTime<'%s' "
716 + "AND FileSet.FileSet=(SELECT FileSet FROM FileSet WHERE FileSetId = %s) "
717 + "ORDER BY Job.JobTDate DESC LIMIT 1",
718 + edit_uint64(jcr->JobId, jobid),
719 + edit_uint64(jr->ClientId, clientid),
721 + edit_uint64(jr->FileSetId, filesetid));
723 + if (!db_sql_query(mdb, query.c_str(), NULL, NULL)) {
727 + if (jr->JobLevel == L_INCREMENTAL) {
730 +"INSERT INTO btemp3%s (JobId, StartTime, EndTime, JobTDate, PurgedFiles) "
731 + "SELECT JobId, StartTime, EndTime, JobTDate, PurgedFiles "
732 + "FROM Job JOIN FileSet USING (FileSetId) "
733 + "WHERE ClientId = %s "
734 + "AND Level='D' AND JobStatus='T' AND Type='B' "
735 + "AND StartTime > (SELECT EndTime FROM btemp3%s ORDER BY EndTime DESC LIMIT 1) "
736 + "AND FileSet.FileSet= (SELECT FileSet FROM FileSet WHERE FileSetId = %s) "
737 + "ORDER BY Job.JobTDate DESC LIMIT 1 ",
743 + db_sql_query(mdb, query.c_str(), NULL, NULL);
746 +"INSERT INTO btemp3%s (JobId, StartTime, EndTime, JobTDate, PurgedFiles) "
747 + "SELECT JobId, StartTime, EndTime, JobTDate, PurgedFiles "
748 + "FROM Job JOIN FileSet USING (FileSetId) "
749 + "WHERE ClientId = %s "
750 + "AND Level='I' AND JobStatus='T' AND Type='B' "
751 + "AND StartTime > (SELECT EndTime FROM btemp3%s ORDER BY EndTime DESC LIMIT 1) "
752 + "AND FileSet.FileSet= (SELECT FileSet FROM FileSet WHERE FileSetId = %s) "
753 + "ORDER BY Job.JobTDate DESC ",
758 + db_sql_query(mdb, query.c_str(), NULL, NULL);
761 + Mmsg(query, "SELECT JobId FROM btemp3%s", jobid);
762 + db_sql_query(mdb, query.c_str(), db_get_int_handler, jobids);
763 + Dmsg1(1, "db_accurate_get_jobids=%s\n", jobids);
765 + Mmsg(query, "DROP TABLE btemp3%s", jobid);
766 + db_sql_query(mdb, query.c_str(), NULL, NULL);
772 + * Use to build a string of int list from a query. "10,20,30"
774 +int db_get_int_handler(void *ctx, int num_fields, char **row)
776 + POOLMEM *ret = (POOLMEM *)ctx;
777 + if (num_fields == 1) {
779 + pm_strcat(ret, ",");
781 + pm_strcat(ret, row[0]);
786 #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL || HAVE_DBI */
787 Index: src/stored/bextract.c
788 ===================================================================
789 --- src/stored/bextract.c (révision 6467)
790 +++ src/stored/bextract.c (copie de travail)
792 Emsg0(M_ERROR_TERM, 0, _("Cannot continue.\n"));
795 + /* handle deleted file
797 + if (rec->FileIndex == 0) {
798 + /* if file is included, remove it ? */
799 + Jmsg(jcr, M_INFO, 0, _("fname=%s is marked as deleted.\n"), attr->fname);
803 if (attr->file_index != rec->FileIndex) {
804 Emsg2(M_ERROR_TERM, 0, _("Record header file index %ld not equal record index %ld\n"),
805 rec->FileIndex, attr->file_index);
806 Index: src/stored/bscan.c
807 ===================================================================
808 --- src/stored/bscan.c (révision 6467)
809 +++ src/stored/bscan.c (copie de travail)
811 case STREAM_UNIX_ATTRIBUTES:
812 case STREAM_UNIX_ATTRIBUTES_EX:
814 + /* handle deleted file
816 + if (rec->FileIndex == 0) {
817 + create_file_attributes_record(db, mjcr, attr->fname, attr->lname,
818 + FT_NOSTAT, "", rec);
823 if (!unpack_attributes_record(bjcr, rec->Stream, rec->data, attr)) {
824 Emsg0(M_ERROR_TERM, 0, _("Cannot continue.\n"));
826 Index: src/stored/append.c
827 ===================================================================
828 --- src/stored/append.c (révision 6467)
829 +++ src/stored/append.c (copie de travail)
832 /* Read Stream header from the File daemon.
833 * The stream header consists of the following:
834 - * file_index (sequential Bacula file index, base 1)
835 + * file_index (sequential Bacula file index, base 1, 0 for deleted files)
836 * stream (Bacula number to distinguish parts of data)
837 * info (Info for Storage daemon -- compressed, encryped, ...)
838 * info is not currently used, so is read, but ignored!
839 @@ -185,16 +185,18 @@
841 Dmsg2(890, "<filed: Header FilInx=%d stream=%d\n", file_index, stream);
843 - if (!(file_index > 0 && (file_index == last_file_index ||
844 - file_index == last_file_index + 1))) {
845 - Jmsg0(jcr, M_FATAL, 0, _("File index from FD not positive or sequential\n"));
848 + if (file_index != 0) { /* TODO: handle file_index == 0 */
849 + if (!(file_index > 0 && (file_index == last_file_index ||
850 + file_index == last_file_index + 1))) {
851 + Jmsg0(jcr, M_FATAL, 0, _("File index from FD not positive or sequential\n"));
855 + if (file_index != last_file_index) {
856 + jcr->JobFiles = file_index;
857 + last_file_index = file_index;
860 - if (file_index != last_file_index) {
861 - jcr->JobFiles = file_index;
862 - last_file_index = file_index;
865 /* Read data stream from the File daemon.
866 * The data stream is just raw bytes
867 @@ -214,22 +216,23 @@
869 while (!write_record_to_block(dcr->block, &rec)) {
870 Dmsg2(850, "!write_record_to_block data_len=%d rem=%d\n", rec.data_len,
873 if (!write_block_to_device(dcr)) {
874 Dmsg2(90, "Got write_block_to_dev error on device %s. %s\n",
875 - dev->print_name(), dev->bstrerror());
876 + dev->print_name(), dev->bstrerror());
882 + Dmsg0(400, "Not OK\n");
885 + jcr->JobBytes += rec.data_len; /* increment bytes this job */
886 + Dmsg4(850, "write_record FI=%s SessId=%d Strm=%s len=%d\n",
887 + FI_to_ascii(buf1, rec.FileIndex), rec.VolSessionId,
888 + stream_to_ascii(buf2, rec.Stream, rec.FileIndex), rec.data_len);
891 - Dmsg0(400, "Not OK\n");
894 - jcr->JobBytes += rec.data_len; /* increment bytes this job */
895 - Dmsg4(850, "write_record FI=%s SessId=%d Strm=%s len=%d\n",
896 - FI_to_ascii(buf1, rec.FileIndex), rec.VolSessionId,
897 - stream_to_ascii(buf2, rec.Stream, rec.FileIndex), rec.data_len);
899 /* Send attributes and digest to Director for Catalog */
900 if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_UNIX_ATTRIBUTES_EX ||
902 ===================================================================
903 --- src/jcr.h (révision 6467)
904 +++ src/jcr.h (copie de travail)
907 /* Forward referenced structures */
914 CRYPTO_CTX crypto; /* Crypto ctx */
915 DIRRES* director; /* Director resource */
916 bool VSS; /* VSS used by FD */
917 + htable *file_list; /* Previous file list (accurate mode) */
918 #endif /* FILE_DAEMON */
921 Index: src/lib/Makefile.in
922 ===================================================================
923 --- src/lib/Makefile.in (révision 6467)
924 +++ src/lib/Makefile.in (copie de travail)
926 res.c rwlock.c scan.c serial.c sha1.c \
927 signal.c smartall.c rblist.c tls.c tree.c \
928 util.c var.c watchdog.c workq.c btimers.c \
929 - address_conf.c pythonlib.c breg.c
930 + address_conf.c pythonlib.c breg.c htable.c
933 LIBOBJS = attr.o base64.o berrno.o bsys.o bget_msg.o \
935 res.o rwlock.o scan.o serial.o sha1.o \
936 signal.o smartall.o rblist.o tls.o tree.o \
937 util.o var.o watchdog.o workq.o btimers.o \
938 - address_conf.o pythonlib.o breg.o
939 + address_conf.o pythonlib.o breg.o htable.o
942 EXTRAOBJS = @OBJLIST@
943 Index: src/findlib/find.c
944 ===================================================================
945 --- src/findlib/find.c (révision 6467)
946 +++ src/findlib/find.c (copie de travail)
948 Dmsg0(100, "Leave set_find_options()\n");
952 +set_find_changed_function(FF_PKT *ff, bool check_fct(JCR *jcr, FF_PKT *ff))
954 + Dmsg0(100, "Enter set_find_changed_function()\n");
955 + ff->check_fct = check_fct;
959 * For VSS we need to know which windows drives
960 * are used, because we create a snapshot of all used
961 Index: src/findlib/find_one.c
962 ===================================================================
963 --- src/findlib/find_one.c (révision 6467)
964 +++ src/findlib/find_one.c (copie de travail)
969 + * In incremental/diffential or accurate backup, we
970 + * say if the current file has changed.
972 +static bool check_changes(JCR *jcr, FF_PKT *ff_pkt)
974 + /* in special mode (like accurate backup), user can
975 + * choose his comparison function.
977 + if (ff_pkt->check_fct) {
978 + return ff_pkt->check_fct(jcr, ff_pkt);
981 + /* in normal modes (incr/diff), we use this default
984 + if (ff_pkt->incremental &&
985 + (ff_pkt->statp.st_mtime < ff_pkt->save_time &&
986 + ((ff_pkt->flags & FO_MTIMEONLY) ||
987 + ff_pkt->statp.st_ctime < ff_pkt->save_time)))
996 * Find a single file.
997 * handle_file is the callback for handling the file.
999 @@ -333,16 +360,13 @@
1000 * since our last "save_time", presumably the last Full save
1003 - if (ff_pkt->incremental && !S_ISDIR(ff_pkt->statp.st_mode)) {
1004 + if ( ff_pkt->incremental
1005 + && !S_ISDIR(ff_pkt->statp.st_mode)
1006 + && !check_changes(jcr, ff_pkt))
1008 Dmsg1(300, "Non-directory incremental: %s\n", ff_pkt->fname);
1009 - /* Not a directory */
1010 - if (ff_pkt->statp.st_mtime < ff_pkt->save_time
1011 - && ((ff_pkt->flags & FO_MTIMEONLY) ||
1012 - ff_pkt->statp.st_ctime < ff_pkt->save_time)) {
1013 - /* Incremental option, file not changed */
1014 - ff_pkt->type = FT_NOCHG;
1015 - return handle_file(jcr, ff_pkt, top_level);
1017 + ff_pkt->type = FT_NOCHG;
1018 + return handle_file(jcr, ff_pkt, top_level);
1021 #ifdef HAVE_DARWIN_OS
1022 @@ -502,15 +526,13 @@
1025 ff_pkt->link = link;
1026 - if (ff_pkt->incremental &&
1027 - (ff_pkt->statp.st_mtime < ff_pkt->save_time &&
1028 - ((ff_pkt->flags & FO_MTIMEONLY) ||
1029 - ff_pkt->statp.st_ctime < ff_pkt->save_time))) {
1030 + if (ff_pkt->incremental && !check_changes(jcr, ff_pkt)) {
1031 /* Incremental option, directory entry not changed */
1032 ff_pkt->type = FT_DIRNOCHG;
1034 ff_pkt->type = FT_DIRBEGIN;
1037 /* We have set st_rdev to 1 if it is a reparse point, otherwise 0 */
1038 if (have_win32_api() && ff_pkt->statp.st_rdev) {
1039 ff_pkt->type = FT_REPARSE;
1040 Index: src/findlib/find.h
1041 ===================================================================
1042 --- src/findlib/find.h (révision 6467)
1043 +++ src/findlib/find.h (copie de travail)
1045 findFILESET *fileset;
1046 int (*file_save)(JCR *, FF_PKT *, bool); /* User's callback */
1047 int (*plugin_save)(JCR *, FF_PKT *, bool); /* User's callback */
1048 + bool (*check_fct)(JCR *, FF_PKT *); /* optionnal user fct to check file changes */
1050 /* Values set by accept_file while processing Options */
1051 uint32_t flags; /* backup options */
1052 Index: src/findlib/protos.h
1053 ===================================================================
1054 --- src/findlib/protos.h (révision 6467)
1055 +++ src/findlib/protos.h (copie de travail)
1058 FF_PKT *init_find_files();
1059 void set_find_options(FF_PKT *ff, int incremental, time_t mtime);
1060 +void set_find_changed_function(FF_PKT *ff, bool check_fct(JCR *jcr, FF_PKT *ff));
1061 int find_files(JCR *jcr, FF_PKT *ff, int file_sub(JCR *, FF_PKT *ff_pkt, bool),
1062 int plugin_sub(JCR *, FF_PKT *ff_pkt, bool));
1063 int match_files(JCR *jcr, FF_PKT *ff, int sub(JCR *, FF_PKT *ff_pkt, bool));