int db_update_stats(JCR *jcr, B_DB *mdb, utime_t age);
-
+bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, POOLMEM *result);
bool db_create_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
bool db_create_base_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
bool db_commit_base_file_attributes_record(JCR *jcr, B_DB *mdb);
-void db_cleanup_base_file(JCR *jcr, B_DB *mdb);
bool db_create_base_file_list(JCR *jcr, B_DB *mdb, char *jobids);
bool db_get_base_file_list(JCR *jcr, B_DB *mdb, DB_RESULT_HANDLER *result_handler,
void *ctx);
if (jcr && jcr->cached_attribute) {
Dmsg0(400, "Flush last cached attribute.\n");
- if (!db_create_file_attributes_record(jcr, mdb, jcr->ar)) {
+ if (!db_create_attributes_record(jcr, mdb, jcr->ar)) {
Jmsg1(jcr, M_FATAL, 0, _("Attribute create error. %s"), db_strerror(jcr->db));
}
jcr->cached_attribute = false;
*/
bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
{
+ ASSERT(ar->FileType != FT_BASE);
+
Dmsg1(dbglevel, "Fname=%s\n", ar->fname);
Dmsg0(dbglevel, "put_file_into_catalog\n");
/* Postgresql */
"CREATE TEMPORARY TABLE basefile%lld ("
+// "CREATE TABLE basefile%lld ("
"Path TEXT,"
"Name TEXT)",
{
bool ret;
if (ar->FileType == FT_BASE) {
- ret = db_create_base_file_attributes_record(jcr, mdb, ar);
+ ret = db_create_base_file_attributes_record(jcr, jcr->db_batch, ar);
} else {
ret = db_create_file_attributes_record(jcr, mdb, ar);
}
return ret;
}
+
+/*
+ * Cleanup the base file temporary tables
+ */
+static void db_cleanup_base_file(JCR *jcr, B_DB *mdb)
+{
+ POOL_MEM buf(PM_MESSAGE);
+ Mmsg(buf, "DROP TABLE new_basefile%lld", (uint64_t) jcr->JobId);
+ db_sql_query(mdb, buf.c_str(), NULL, NULL);
+
+ Mmsg(buf, "DROP TABLE basefile%lld", (uint64_t) jcr->JobId);
+ db_sql_query(mdb, buf.c_str(), NULL, NULL);
+}
+
/*
* Put all base file seen in the backup to the BaseFile table
+ * and cleanup temporary tables
*/
bool db_commit_base_file_attributes_record(JCR *jcr, B_DB *mdb)
{
+ bool ret;
char ed1[50];
POOL_MEM buf(PM_MESSAGE);
"AND A.Name = B.Name "
"ORDER BY B.FileId)",
edit_uint64(jcr->JobId, ed1), ed1, ed1);
- return db_sql_query(mdb, buf.c_str(), NULL, NULL);
-}
-
-/*
- * Cleanup the base file temporary tables
- */
-void db_cleanup_base_file(JCR *jcr, B_DB *mdb)
-{
- POOL_MEM buf(PM_MESSAGE);
- Mmsg(buf, "DROP TABLE new_basefile%lld", (uint64_t) jcr->JobId);
- db_sql_query(mdb, buf.c_str(), NULL, NULL);
-
- Mmsg(buf, "DROP TABLE basefile%lld", (uint64_t) jcr->JobId);
- db_sql_query(mdb, buf.c_str(), NULL, NULL);
+ ret = db_sql_query(mdb, buf.c_str(), NULL, NULL);
+ db_cleanup_base_file(jcr, mdb);
+ return ret;
}
/*
}
Mmsg(buf,
- "CREATE TEMPORARY TABLE new_basefile%lld AS ( "
- "SELECT Path.Path AS Path, Filename.Name AS Name, File.FileIndex AS FileIndex, "
- "File.JobId AS JobId, File.LStat AS LStat, File.FileId AS FileId "
- "FROM ( "
- "SELECT max(FileId) as FileId, PathId, FilenameId "
- "FROM (SELECT FileId, PathId, FilenameId FROM File WHERE JobId IN (%s)) AS F "
- "GROUP BY PathId, FilenameId "
- ") AS Temp "
- "JOIN Filename ON (Filename.FilenameId = Temp.FilenameId) "
- "JOIN Path ON (Path.PathId = Temp.PathId) "
- "JOIN File ON (File.FileId = Temp.FileId) "
- "WHERE File.FileIndex > 0)",
+"CREATE TEMPORARY TABLE new_basefile%lld AS ( "
+//"CREATE TABLE new_basefile%lld AS ( "
+ "SELECT Path.Path AS Path, Filename.Name AS Name, File.FileIndex AS FileIndex,"
+ "File.JobId AS JobId, File.LStat AS LStat, File.FileId AS FileId "
+ "FROM ( "
+ "SELECT max(FileId) as FileId, PathId, FilenameId "
+ "FROM (SELECT FileId, PathId, FilenameId FROM File WHERE JobId IN (%s)) AS F "
+ "GROUP BY PathId, FilenameId "
+ ") AS Temp "
+ "JOIN Filename ON (Filename.FilenameId = Temp.FilenameId) "
+ "JOIN Path ON (Path.PathId = Temp.PathId) "
+ "JOIN File ON (File.FileId = Temp.FileId) "
+ "WHERE File.FileIndex > 0)",
(uint64_t)jcr->JobId, jobids);
return db_sql_query(mdb, buf.c_str(), NULL, NULL);
}
return db_sql_query(mdb, buf.c_str(), result_handler, ctx);
}
+/*
+ * This procedure gets the base jobid list used by jobids,
+ * You can specify jobids == result to concat base jobids to current jobids
+ */
+bool db_get_used_base_jobids(JCR *jcr, B_DB *mdb, POOLMEM *jobids, POOLMEM *result)
+{
+ POOL_MEM buf;
+ Mmsg(buf,
+ "SELECT DISTINCT BaseJobId "
+ " FROM Job JOIN BaseFiles USING (JobId) "
+ " WHERE Job.HasBase = 1 "
+ " AND JobId IN (%s) ", jobids);
+ return db_sql_query(mdb, buf.c_str(), db_get_int_handler, jobids);
+}
+
/* The decision do change an incr/diff was done before
* Full : do nothing
* Differential : get the last full id
goto bail_out;
}
- if (jcr->get_JobLevel() == L_FULL) {
+ if (jcr->HasBase) {
db_create_base_file_list(jcr, jcr->db_batch, jobids);
db_get_base_file_list(jcr, jcr->db_batch,
accurate_list_handler, (void *)jcr);
stat = wait_for_job_termination(jcr);
db_write_batch_file_records(jcr); /* used by bulk batch file insert */
- if (jcr->HasBase) {
- db_commit_base_file_attributes_record(jcr, jcr->db_batch);
- db_cleanup_base_file(jcr, jcr->db_batch);
+ if (jcr->HasBase &&
+ !db_commit_base_file_attributes_record(jcr, jcr->db_batch))
+ {
+ Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db_batch));
}
if (stat == JS_Terminated) {
if (!db_get_file_list(ua->jcr, ua->db, rx->JobIds, insert_tree_handler, (void *)&tree)) {
ua->error_msg("%s", db_strerror(ua->db));
}
+
+ if (!db_get_used_base_jobids(ua->jcr, ua->db, rx->JobIds, rx->JobIds)) {
+ ua->error_msg("%s", db_strerror(ua->db));
+ }
#else
for (p=rx->JobIds; get_next_jobid_from_list(&p, &JobId) > 0; ) {
char ed1[50];
for (TREE_NODE *node=first_tree_node(tree.root); node; node=next_tree_node(node)) {
Dmsg2(400, "FI=%d node=0x%x\n", node->FileIndex, node);
if (node->extract || node->extract_dir) {
- Dmsg3(0, "JobId=%lld type=%d FI=%d\n", (uint64_t)node->JobId, node->type, node->FileIndex);
+ Dmsg3(400, "JobId=%lld type=%d FI=%d\n", (uint64_t)node->JobId, node->type, node->FileIndex);
add_findex(rx->bsr, node->JobId, node->FileIndex);
if (node->extract && node->type != TN_NEWDIR) {
rx->selected_files++; /* count only saved files */
node = insert_tree_node(row[0], row[1], type, tree->root, NULL);
JobId = str_to_int64(row[3]);
FileIndex = str_to_int64(row[2]);
- Dmsg2(0, "JobId=%s FileIndex=%s\n", row[3], row[2]);
+ Dmsg2(400, "JobId=%s FileIndex=%s\n", row[3], row[2]);
/*
* - The first time we see a file (node->inserted==true), we accept it.
* - In the same JobId, we accept only the first copy of a