From 00d1c2a4e98ae88a00a7c0a65b966b34fa501b0b Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Wed, 29 Jul 2009 19:51:59 +0200 Subject: [PATCH] compile --- bacula/src/cats/protos.h | 3 +- bacula/src/cats/sql_create.c | 14 ++++--- bacula/src/cats/sql_get.c | 58 +++++++++++++++++++++++++--- bacula/src/dird/backup.c | 74 ++++++++++++++++++++++++++++++------ bacula/src/dird/catreq.c | 2 +- bacula/src/filed/accurate.c | 6 +-- 6 files changed, 129 insertions(+), 28 deletions(-) diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 5434960f32..cd5943647b 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -106,6 +106,7 @@ int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cdbr); int db_get_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr); bool db_get_query_dbids(JCR *jcr, B_DB *mdb, POOL_MEM &query, dbid_list &ids); bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, DB_RESULT_HANDLER *result_handler, void *ctx); +bool db_get_base_jobid(JCR *jcr, B_DB *mdb, JOB_DBR *jr, JobId_t *jobid); bool db_accurate_get_jobids(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM *jobids); int db_get_int_handler(void *ctx, int num_fields, char **row); @@ -142,7 +143,7 @@ int db_update_stats(JCR *jcr, B_DB *mdb, utime_t age); -boot db_init_base_file(JCR *jcr, B_DB *mdb); +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); diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index e7117ceb21..5a11bead73 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -1132,7 +1132,7 @@ const char *create_temp_basefile[4] = { "Name TEXT)" }; -boot db_init_base_file(JCR *jcr, B_DB *mdb) +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); @@ -1145,6 +1145,7 @@ boot 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 ret; Dmsg1(dbglevel, "Fname=%s\n", ar->fname); Dmsg0(dbglevel, "put_file_into_catalog\n"); @@ -1160,7 +1161,7 @@ bool db_create_base_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) } db_lock(mdb); - split_path_and_file(jcr, bdb, ar->fname); + split_path_and_file(jcr, mdb, ar->fname); mdb->esc_name = check_pool_memory_size(mdb->esc_name, mdb->fnl*2+1); db_escape_string(jcr, mdb, mdb->esc_name, mdb->fname, mdb->fnl); @@ -1168,10 +1169,10 @@ bool db_create_base_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) mdb->esc_path = check_pool_memory_size(mdb->esc_path, mdb->pnl*2+1); db_escape_string(jcr, mdb, mdb->esc_path, mdb->path, mdb->pnl); - len = Mmsg(mdb->cmd, "INSERT INTO basefile%lld (Path, Name) VALUES ('%s','%s')", - (uint64_t)jcr->JobId, mdb->esc_path, mdb->esc_name); + Mmsg(mdb->cmd, "INSERT INTO basefile%lld (Path, Name) VALUES ('%s','%s')", + (uint64_t)jcr->JobId, mdb->esc_path, mdb->esc_name); - boot ret = INSERT_DB(jcr, mdb, mdb->cmd); + ret = INSERT_DB(jcr, mdb, mdb->cmd); db_unlock(mdb); return ret; @@ -1192,7 +1193,7 @@ bool db_commit_base_file_attributes_record(JCR *jcr, B_DB *mdb) "WHERE A.Path = B.Path " "AND A.Name = B.Name " "ORDER BY B.FileId)", - edit_uint64(ed1, jcr->JobId), ed1, ed1); + edit_uint64(jcr->JobId, ed1), ed1, ed1); return db_sql_query(mdb, buf.c_str(), NULL, NULL); } @@ -1202,6 +1203,7 @@ bool db_commit_base_file_attributes_record(JCR *jcr, B_DB *mdb) */ 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); diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index d0a885cb44..0509a8fd6b 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -1045,7 +1045,8 @@ bool db_get_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) /* * Find the last "accurate" backup state (that can take deleted files in account) - * 1) Get all files with jobid in list (F subquery) + * 1) Get all files with jobid in list (F subquery) + * Get all files in BaseFiles with jobid in list * 2) Take only the last version of each file (Temp subquery) => accurate list is ok * 3) Join the result to file table to get fileindex, jobid and lstat information * @@ -1069,15 +1070,21 @@ bool db_get_file_list(JCR *jcr, B_DB *mdb, char *jobids, "SELECT Path.Path, Filename.Name, File.FileIndex, File.JobId, File.LStat " "FROM ( " "SELECT max(FileId) as FileId, PathId, FilenameId " - "FROM (SELECT FileId, PathId, FilenameId FROM File WHERE JobId IN (%s)) AS F " + "FROM (SELECT FileId, PathId, FilenameId FROM File WHERE JobId IN (%s) " + "UNION " + "SELECT File.FileId, PathId, FilenameId " + "FROM BaseFiles JOIN File USING (FileId) " + "WHERE BaseFiles.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 ORDER BY JobId, FileIndex ASC", /* Return sorted by JobId, */ - /* FileIndex for restore code */ - jobids); +"WHERE File.FileIndex > 0 ORDER BY JobId, FileIndex ASC",/* Return sorted by JobId, */ + /* FileIndex for restore code */ + jobids, jobids); + Dmsg1(0, "q=%s\n", buf.c_str()); #else /* * I am not sure that this works the same as the code in ua_restore.c @@ -1188,6 +1195,47 @@ bail_out: return ret; } +bool db_get_base_jobid(JCR *jcr, B_DB *mdb, JOB_DBR *jr, JobId_t *jobid) +{ + char date[MAX_TIME_LENGTH]; + int64_t id = *jobid = 0; + POOL_MEM query(PM_FNAME); + +// char clientid[50], filesetid[50]; + + utime_t StartTime = (jr->StartTime)?jr->StartTime:time(NULL); + bstrutime(date, sizeof(date), StartTime + 1); + + /* we can take also client name, fileset, etc... */ + + Mmsg(query, + "SELECT JobId, Job, StartTime, EndTime, JobTDate, PurgedFiles " + "FROM Job " +// "JOIN FileSet USING (FileSetId) JOIN Client USING (ClientId) " + "WHERE Job.Name = '%s' " + "AND Level='B' AND JobStatus IN ('T','W') AND Type='B' " +// "AND FileSet.FileSet= '%s' " +// "AND Client.Name = '%s' " + "AND StartTime<'%s' " + "ORDER BY Job.JobTDate DESC LIMIT 1", + jr->Name, +// edit_uint64(jr->ClientId, clientid), +// edit_uint64(jr->FileSetId, filesetid)); + date); + + Dmsg1(1, "db_get_base_jobid q=%s\n", query.c_str()); + if (!db_sql_query(mdb, query.c_str(), db_int64_handler, &id)) { + goto bail_out; + } + *jobid = (JobId_t) id; + + Dmsg1(1, "db_get_base_jobid=%lld\n", id); + return true; + +bail_out: + return false; +} + /* * Use to build a string of int list from a query. "10,20,30" */ diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 029dfa0c89..bdf6fc92d3 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -103,6 +103,36 @@ bool do_backup_init(JCR *jcr) return true; } +/* Take all base jobs from job resource and find the + * last L_BASE jobid. + */ +static void get_base_jobids(JCR *jcr, POOLMEM *jobids) +{ + JOB_DBR jr; + JOB *job; + JobId_t id; + char str_jobid[50]; + + if (!jcr->job->base) { + return; + } + + memset(&jr, 0, sizeof(JOB_DBR)); + jr.StartTime = jcr->jr.StartTime; + + foreach_alist(job, jcr->job->base) { + bstrncpy(jr.Name, job->name(), sizeof(jr.Name)); + db_get_base_jobid(jcr, jcr->db, &jr, &id); + + if (id) { + if (jobids[0]) { + pm_strcat(jobids, ","); + } + pm_strcat(jobids, edit_uint64(id, str_jobid)); + } + } +} + /* * Foreach files in currrent list, send "/path/fname\0LStat" to FD */ @@ -131,45 +161,65 @@ static int accurate_list_handler(void *ctx, int num_fields, char **row) bool send_accurate_current_files(JCR *jcr) { POOL_MEM buf; + bool ret=true; - if (!jcr->accurate || job_canceled(jcr) || jcr->get_JobLevel()==L_FULL) { + if (!jcr->accurate || job_canceled(jcr)) { return true; } + /* In base level, no previous job is used */ + if (jcr->get_JobLevel() == L_BASE) { + return true; + } + + POOLMEM *nb = get_pool_memory(PM_FNAME); POOLMEM *jobids = get_pool_memory(PM_FNAME); + nb[0] = jobids[0] = '\0'; - db_accurate_get_jobids(jcr, jcr->db, &jcr->jr, jobids); + get_base_jobids(jcr, jobids); - if (*jobids == 0) { - free_pool_memory(jobids); - Jmsg(jcr, M_FATAL, 0, _("Cannot find previous jobids.\n")); - return false; + /* On Full mode, if no previous base job, no accurate things */ + if (jcr->get_JobLevel() == L_FULL && *jobids == 0) { + goto bail_out; } + + /* For Incr/Diff level, we search for older jobs */ + if (jcr->get_JobLevel() != L_FULL) { + db_accurate_get_jobids(jcr, jcr->db, &jcr->jr, jobids); + + if (*jobids == 0) { + ret=false; + Jmsg(jcr, M_FATAL, 0, _("Cannot find previous jobids.\n")); + goto bail_out; + } + } + if (jcr->JobId) { /* display the message only for real jobs */ Jmsg(jcr, M_INFO, 0, _("Sending Accurate information.\n")); } + /* to be able to allocate the right size for htable */ - POOLMEM *nb = get_pool_memory(PM_FNAME); - *nb = 0; /* clear buffer */ Mmsg(buf, "SELECT sum(JobFiles) FROM Job WHERE JobId IN (%s)",jobids); 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 (!db_open_batch_connexion(jcr, jcr->db)) { + ret = false; Jmsg0(jcr, M_FATAL, 0, "Can't get dedicate sql connexion"); - return false; + 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) */ + jcr->file_bsock->signal(BNET_EOD); + +bail_out: free_pool_memory(jobids); free_pool_memory(nb); - jcr->file_bsock->signal(BNET_EOD); - - return true; + return ret; } /* diff --git a/bacula/src/dird/catreq.c b/bacula/src/dird/catreq.c index c317ad4441..e9a180b75d 100644 --- a/bacula/src/dird/catreq.c +++ b/bacula/src/dird/catreq.c @@ -488,7 +488,7 @@ static void update_attribute(JCR *jcr, char *msg, int32_t msglen) /* Update BaseFile table */ if (ar->FileType == FT_BASE) { - if (!db_create_base_file_attributes_record(jcr, jcr->mdb, ar)) { + if (!db_create_base_file_attributes_record(jcr, jcr->db, ar)) { Jmsg1(jcr, M_FATAL, 0, _("Base attribute create error. %s"), db_strerror(jcr->db)); } diff --git a/bacula/src/filed/accurate.c b/bacula/src/filed/accurate.c index c9a69390e6..e7ba84196d 100644 --- a/bacula/src/filed/accurate.c +++ b/bacula/src/filed/accurate.c @@ -98,7 +98,7 @@ static bool accurate_send_base_file_list(JCR *jcr) FF_PKT *ff_pkt; int stream = STREAM_UNIX_ATTRIBUTES; - if (!jcr->accurate || jcr->get_JobLevel != L_FULL) { + if (!jcr->accurate || jcr->get_JobLevel() != L_FULL) { return true; } @@ -163,7 +163,7 @@ static bool accurate_send_deleted_list(JCR *jcr) return true; } -static void accurate_free(JCR *jcr) +void accurate_free(JCR *jcr) { if (jcr->file_list) { jcr->file_list->destroy(); @@ -177,7 +177,7 @@ bool accurate_finish(JCR *jcr) { bool ret=true; if (jcr->accurate) { - if (jcr->get_JobLevel == L_FULL) { + if (jcr->get_JobLevel() == L_FULL) { ret = accurate_send_base_file_list(jcr); } else { ret = accurate_send_deleted_list(jcr); -- 2.39.5