From 5a81aa0355ef9cf3ddbf2d4bbfec97a4670645c8 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Wed, 29 Jul 2009 21:17:03 +0200 Subject: [PATCH] update --- bacula/src/cats/protos.h | 3 ++- bacula/src/cats/sql_create.c | 27 ++++++++++--------- bacula/src/cats/sql_get.c | 12 +++++++++ bacula/src/dird/backup.c | 51 +++++++++++++++++++++--------------- 4 files changed, 58 insertions(+), 35 deletions(-) diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index cd5943647b..9801674f6d 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -143,11 +143,12 @@ int db_update_stats(JCR *jcr, B_DB *mdb, utime_t age); -bool db_init_base_file(JCR *jcr, B_DB *mdb); 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); #endif /* __SQL_PROTOS_H */ diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index 47b9cba4c2..91e8e376f1 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -1117,7 +1117,8 @@ const char *create_temp_basefile[4] = { "Name BLOB NOT NULL)", /* Postgresql */ - "CREATE TEMPORARY TABLE basefile%lld (" +// "CREATE TEMPORARY TABLE basefile%lld (" + "CREATE TABLE basefile%lld (" "Path TEXT," "Name TEXT)", @@ -1132,13 +1133,6 @@ const char *create_temp_basefile[4] = { "Name TEXT)" }; -bool db_init_base_file(JCR *jcr, B_DB *mdb) -{ - POOL_MEM q(PM_MESSAGE); - Mmsg(q, create_temp_basefile[db_type], (uint64_t) jcr->JobId); - return db_sql_query(mdb, q.c_str(), NULL, NULL); -} - /* * Create Base File record in B_DB * @@ -1205,10 +1199,10 @@ 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); +// 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); +// db_sql_query(mdb, buf.c_str(), NULL, NULL); } /* @@ -1220,16 +1214,23 @@ void db_cleanup_base_file(JCR *jcr, B_DB *mdb) */ bool db_create_base_file_list(JCR *jcr, B_DB *mdb, char *jobids) { + POOL_MEM buf(PM_MESSAGE); + if (!*jobids) { db_lock(mdb); Mmsg(mdb->errmsg, _("ERR=JobIds are empty\n")); db_unlock(mdb); return false; } - POOL_MEM buf(PM_MESSAGE); - + + Mmsg(buf, create_temp_basefile[db_type], (uint64_t) jcr->JobId); + if (!db_sql_query(mdb, buf.c_str(), NULL, NULL)) { + return false; + } + Mmsg(buf, - "CREATE TEMPORARY TABLE new_basefile%lld AS ( " +// "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 ( " diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index 0509a8fd6b..6ebda1b80b 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -1195,6 +1195,18 @@ bail_out: return ret; } +bool db_get_base_file_list(JCR *jcr, B_DB *mdb, + DB_RESULT_HANDLER *result_handler, void *ctx) +{ + POOL_MEM buf(PM_MESSAGE); + + Mmsg(buf, + "SELECT Path, Name, FileIndex, JobId, LStat " + "FROM new_basefile%lld ORDER BY JobId, FileIndex ASC", + (uint64_t) jcr->JobId); + + return db_sql_query(mdb, buf.c_str(), result_handler, ctx); +} bool db_get_base_jobid(JCR *jcr, B_DB *mdb, JOB_DBR *jr, JobId_t *jobid) { char date[MAX_TIME_LENGTH]; diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 3d92fd3840..cbb003f452 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -106,7 +106,7 @@ bool do_backup_init(JCR *jcr) /* Take all base jobs from job resource and find the * last L_BASE jobid. */ -static void get_base_jobids(JCR *jcr, POOLMEM *jobids) +static bool get_base_jobids(JCR *jcr, POOLMEM *jobids) { JOB_DBR jr; JOB *job; @@ -114,7 +114,7 @@ static void get_base_jobids(JCR *jcr, POOLMEM *jobids) char str_jobid[50]; if (!jcr->job->base) { - return; + return false; /* no base job, stop accurate */ } memset(&jr, 0, sizeof(JOB_DBR)); @@ -131,6 +131,8 @@ static void get_base_jobids(JCR *jcr, POOLMEM *jobids) pm_strcat(jobids, edit_uint64(id, str_jobid)); } } + + return *jobids != '\0'; } /* @@ -175,21 +177,18 @@ bool send_accurate_current_files(JCR *jcr) POOLMEM *jobids = get_pool_memory(PM_FNAME); nb[0] = jobids[0] = '\0'; - get_base_jobids(jcr, jobids); - - /* On Full mode, if no previous base job, no accurate things */ - if (jcr->get_JobLevel() == L_FULL && *jobids == 0) { - goto bail_out; - } - - if (jcr->get_JobLevel() == L_FULL && *jobids != 0) { - db_init_base_file(jcr, jcr->db); - } + if (jcr->get_JobLevel() == L_FULL) { + /* On Full mode, if no previous base job, no accurate things */ + if (!get_base_jobids(jcr, jobids)) { + goto bail_out; + } + db_create_base_file_list(jcr, jcr->db, jobids); - /* For Incr/Diff level, we search for older jobs */ - if (jcr->get_JobLevel() != L_FULL) { + } else { + /* For Incr/Diff level, we search for older jobs */ db_accurate_get_jobids(jcr, jcr->db, &jcr->jr, jobids); + /* We are in Incr/Diff, but no Full to build the accurate list... */ if (*jobids == 0) { ret=false; Jmsg(jcr, M_FATAL, 0, _("Cannot find previous jobids.\n")); @@ -206,14 +205,18 @@ bool send_accurate_current_files(JCR *jcr) db_sql_query(jcr->db, buf.c_str(), db_get_int_handler, nb); Dmsg2(200, "jobids=%s nb=%s\n", jobids, nb); jcr->file_bsock->fsend("accurate files=%s\n", nb); + + if (jcr->get_JobLevel() == L_FULL) { + db_get_base_file_list(jcr, jcr->db, accurate_list_handler, (void *)jcr); - if (!db_open_batch_connexion(jcr, jcr->db)) { - ret = false; - Jmsg0(jcr, M_FATAL, 0, "Can't get dedicate sql connexion"); - goto bail_out; - } - - db_get_file_list(jcr, jcr->db_batch, jobids, accurate_list_handler, (void *)jcr); + } else { + if (!db_open_batch_connexion(jcr, jcr->db)) { + ret = false; + Jmsg0(jcr, M_FATAL, 0, "Can't get dedicate sql connexion"); + goto bail_out; + } + db_get_file_list(jcr, jcr->db_batch, jobids, accurate_list_handler, (void *)jcr); + } /* TODO: close the batch connexion ? (can be used very soon) */ @@ -375,6 +378,12 @@ bool do_backup(JCR *jcr) /* Pickup Job termination data */ stat = wait_for_job_termination(jcr); db_write_batch_file_records(jcr); /* used by bulk batch file insert */ + + if (jcr->get_JobLevel() == L_FULL && jcr->job->base) { + db_commit_base_file_attributes_record(jcr, jcr->db); + db_cleanup_base_file(jcr, jcr->db); + } + if (stat == JS_Terminated) { backup_cleanup(jcr, stat); return true; -- 2.39.5