        }
 Index: src/dird/dird_conf.h
 ===================================================================
---- src/dird/dird_conf.h	(rvision 6373)
+--- src/dird/dird_conf.h	(rvision 6374)
 +++ src/dird/dird_conf.h	(copie de travail)
 @@ -400,6 +400,7 @@
     bool write_part_after_job;         /* Set to write part after job in SD */

    db_write_batch_file_records(jcr);    /* used by bulk batch file insert */
Index: src/dird/inc_conf.c
===================================================================
--- src/dird/inc_conf.c	(rvision 6373)
+++ src/dird/inc_conf.c	(copie de travail)
@@ -94,6 +94,7 @@
  * Items that are valid in an Options resource

       default:
          Emsg1(M_ERROR, 0, _("Unknown include/exclude option: %c\n"), *p);
          break;
Index: src/cats/sql_update.c
===================================================================
--- src/cats/sql_update.c	(rvision 6374)
+++ src/cats/sql_update.c	(copie de travail)
@@ -88,6 +88,76 @@
    return stat;
 }
 
+int db_accurate_delete_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, JobId_t BackupId)
+{
+   int stat;
+   char ed1[50], ed2[50];
+   db_lock(mdb);
+   Mmsg(mdb->cmd, "DELETE FROM CurrentFile WHERE FileId=%s AND BackupId=%s",
+	edit_int64(FileId, ed1), edit_int64(BackupId, ed2));
+   stat = QUERY_DB(jcr, mdb, mdb->cmd);
+   db_unlock(mdb);
+   return stat;
+}
+
+int db_accurate_mark_file_for_backup(JCR *jcr, B_DB *mdb, char *fname, JobId_t JobId)
+{
+   int stat;
+   int len=strlen(fname);
+   char ed1[50];
+   db_lock(mdb);
+   /* TODO: mdb->esc_xxx are already ok but it's more smart to recompute it */
+//   mdb->esc_name = check_pool_memory_size(mdb->esc_name, 2*len+2);
+//   mdb->esc_name = db_escape_string(jcr, mdb, mdb->esc_name, fname, len);
+   Mmsg(mdb->cmd, "INSERT INTO ToBackup%s (name) VALUES ('%s%s')", edit_int64(JobId, ed1), mdb->esc_path, mdb->esc_name);
+   stat = INSERT_DB(jcr, mdb, mdb->cmd);
+   db_unlock(mdb);
+   return stat;
+}
+
+int db_accurate_create_backup_table(JCR *jcr, B_DB *mdb, JobId_t JobId)
+{
+   int stat;
+   char ed1[50];
+   db_lock(mdb);
+   Mmsg(mdb->cmd, "CREATE TABLE ToBackup%s (name text)", edit_int64(JobId, ed1));
+//   Mmsg(mdb->cmd, "CREATE TEMPORARY TABLE ToBackup%s (name text)", edit_int64(JobId, ed1));
+   stat = QUERY_DB(jcr, mdb, mdb->cmd);
+   db_unlock(mdb);
+   return stat;
+}
+
+int db_accurate_drop_backup_table(JCR *jcr, B_DB *mdb, JobId_t JobId)
+{
+   int stat;
+   char ed1[50];
+   db_lock(mdb);
+//   Mmsg(mdb->cmd, "DROP TABLE ToBackup%s", edit_int64(JobId, ed1));
+//   stat = QUERY_DB(jcr, mdb, mdb->cmd);
+   db_unlock(mdb);
+   return stat;
+}
+
+
+/* Mark the file record as being visited during database
+ * accurate compare. Stuff JobId into the MarkId field
+ */
+int db_accurate_mark_file_record(JCR *jcr, B_DB *mdb, JobId_t BackupId, FileId_t FileId, JobId_t JobId)
+{
+   int stat;
+   char ed1[50], ed2[50], ed3[50];
+
+   db_lock(mdb);
+   Mmsg(mdb->cmd, "UPDATE CurrentFile SET MarkId=%s WHERE FileId=%s AND BackupId=%s", 
+	edit_int64(JobId, ed1), edit_int64(FileId, ed2), edit_int64(BackupId, ed3));
+   stat = QUERY_DB(jcr, mdb, mdb->cmd);
+   if (!stat || sql_affected_rows(mdb) != 1) {
+      stat = 0;
+   }
+   db_unlock(mdb);
+   return stat;
+}
+
 /*
  * Update the Job record at start of Job
  *
Index: src/cats/make_postgresql_tables.in
===================================================================
--- src/cats/make_postgresql_tables.in	(rvision 6374)
+++ src/cats/make_postgresql_tables.in	(copie de travail)
@@ -43,6 +43,59 @@
 CREATE INDEX file_jobid_idx on file (jobid);
 CREATE INDEX file_fp_idx on file (filenameid, pathid);
 
