From d9284ae4a589dd2b92f3ccda8a3d1576071dd0a0 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 28 Dec 2003 09:52:58 +0000 Subject: [PATCH] Misc ... git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@960 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/Makefile.in | 2 +- bacula/autoconf/configure.in | 10 ++++++-- bacula/configure | 10 ++++++-- bacula/src/dird/sql_cmds.c | 2 ++ bacula/src/dird/ua_restore.c | 41 ++++++++++++++++++++++++++++----- bacula/src/dird/ua_select.c | 44 ++++++++++++++++++------------------ 6 files changed, 76 insertions(+), 33 deletions(-) diff --git a/bacula/Makefile.in b/bacula/Makefile.in index d2a4c677ad..b268cc01d8 100755 --- a/bacula/Makefile.in +++ b/bacula/Makefile.in @@ -55,10 +55,10 @@ bacula-fd: Makefile #------------------------------------------------------------------------- configure: autoconf/configure.in autoconf/aclocal.m4 autoconf/acconfig.h autoconf/config.h.in cd $(srcdir); + ${RMF} -f config.cache config.log config.out config.status src/config.h autoconf --prepend-include=$(srcdir)/autoconf \ autoconf/configure.in > configure chmod 755 configure - @rm -f config.cache old-configure: autoconf/configure.in autoconf/aclocal.m4 autoconf/acconfig.h cd $(srcdir); diff --git a/bacula/autoconf/configure.in b/bacula/autoconf/configure.in index 3009d882e4..950aa42602 100644 --- a/bacula/autoconf/configure.in +++ b/bacula/autoconf/configure.in @@ -1400,8 +1400,14 @@ openbsd) platforms/openbsd/bacula-dir" ;; redhat) - DISTVER=`cat /etc/redhat-release | grep release |\ - cut -f 5 -d ' '` + if test `cat /etc/redhat-release | grep release |\ + cut -f 3 -d ' '`x = "Enterprise"x ; then + DISTVER="Enterprise "`cat /etc/redhat-release | grep release |\ + cut -f 6 -d ' '` + else + DISTVER=`cat /etc/redhat-release | grep release |\ + cut -f 5 -d ' '` + fi TAPEDRIVE="/dev/nst0" PSCMD="ps -e -o pid,command" PFILES="${PFILES} \ diff --git a/bacula/configure b/bacula/configure index a7086065c4..e92bb4103f 100755 --- a/bacula/configure +++ b/bacula/configure @@ -17907,8 +17907,14 @@ openbsd) platforms/openbsd/bacula-dir" ;; redhat) - DISTVER=`cat /etc/redhat-release | grep release |\ - cut -f 5 -d ' '` + if test `cat /etc/redhat-release | grep release |\ + cut -f 3 -d ' '`x = "Enterprise"x ; then + DISTVER="Enterprise "`cat /etc/redhat-release | grep release |\ + cut -f 6 -d ' '` + else + DISTVER=`cat /etc/redhat-release | grep release |\ + cut -f 5 -d ' '` + fi TAPEDRIVE="/dev/nst0" PSCMD="ps -e -o pid,command" PFILES="${PFILES} \ diff --git a/bacula/src/dird/sql_cmds.c b/bacula/src/dird/sql_cmds.c index 610aa8a9d1..048be2c526 100644 --- a/bacula/src/dird/sql_cmds.c +++ b/bacula/src/dird/sql_cmds.c @@ -231,6 +231,7 @@ char *uar_last_full = "AND JobMedia.MediaId=Media.MediaId " "AND Job.FileSetId=FileSet.FileSetId " "AND FileSet.FileSet='%s' " + "%s" /* dynamically added PoolId selection */ "ORDER BY Job.JobTDate DESC LIMIT 1"; char *uar_full = @@ -253,6 +254,7 @@ char *uar_inc_dec = "AND JobMedia.MediaId=Media.MediaId " "AND Job.Level IN ('I', 'D') AND JobStatus='T' " "AND Job.FileSetId=FileSet.FileSetId " + "%s" /* dynamically added PoolId selection */ "AND FileSet.FileSet='%s' "; char *uar_list_temp = diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index 36733d0ab2..1bbb649af1 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -69,6 +69,7 @@ struct RESTORE_CTX { POOLMEM *JobIds; /* User entered string of JobIds */ STORE *store; JOB *restore_job; + POOL *pool; int restore_jobs; uint32_t selected_files; char *where; @@ -301,6 +302,7 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) "before", /* 2 */ "file", /* 3 */ "select", /* 4 */ + "pool", /* 5 */ NULL }; @@ -361,6 +363,14 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) } done = true; break; + case 5: /* pool specified */ + i = find_arg_with_value(ua, "pool"); + if (i >= 0) { + rx->pool = (POOL *)GetResWithName(R_POOL, ua->argv[i]); + } else { + bsendmsg(ua, _("Error: Pool resource \"%s\" does not exist.\n"), ua->argv[i]); + } + break; default: break; } @@ -503,7 +513,8 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) } jr.JobId = JobId; if (!db_get_job_record(ua->jcr, ua->db, &jr)) { - bsendmsg(ua, _("Unable to get Job record. ERR=%s\n"), db_strerror(ua->db)); + bsendmsg(ua, _("Unable to get Job record for JobId=%u: ERR=%s\n"), + JobId, db_strerror(ua->db)); return 0; } rx->TotalFiles += jr.JobFiles; @@ -511,6 +522,9 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx) return 1; } +/* + * Get date from user + */ static int get_date(UAContext *ua, char *date, int date_len) { bsendmsg(ua, _("The restored files will the most current backup\n" @@ -528,6 +542,9 @@ static int get_date(UAContext *ua, char *date, int date_len) return 1; } +/* + * Insert a single file, or read a list of files from a file + */ static void insert_one_file(UAContext *ua, RESTORE_CTX *rx, char *date) { FILE *ffd; @@ -723,6 +740,7 @@ static int select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *date CLIENT_DBR cr; char fileset_name[MAX_NAME_LENGTH]; char ed1[50]; + char pool_select[MAX_NAME_LENGTH]; int i; @@ -776,9 +794,22 @@ static int select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *date } } + /* If Pool specified, add PoolId specification */ + pool_select[0] = 0; + if (rx->pool) { + POOL_DBR pr; + memset(&pr, 0, sizeof(pr)); + bstrncpy(pr.Name, rx->pool->hdr.name, sizeof(pr.Name)); + if (db_get_pool_record(ua->jcr, ua->db, &pr)) { + bsnprintf(pool_select, sizeof(pool_select), "AND Media.PoolId=%u ", pr.PoolId); + } else { + bsendmsg(ua, _("Pool \"%s\" not found, using any pool.\n"), pr.Name); + } + } /* Find JobId of last Full backup for this client, fileset */ - Mmsg(&rx->query, uar_last_full, cr.ClientId, cr.ClientId, date, fsr.FileSet); + Mmsg(&rx->query, uar_last_full, cr.ClientId, cr.ClientId, date, fsr.FileSet, + pool_select); if (!db_sql_query(ua->db, rx->query, NULL, NULL)) { bsendmsg(ua, "%s\n", db_strerror(ua->db)); goto bail_out; @@ -803,7 +834,7 @@ static int select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *date /* Now find all Incremental/Decremental Jobs after Full save */ Mmsg(&rx->query, uar_inc_dec, edit_uint64(rx->JobTDate, ed1), date, - cr.ClientId, fsr.FileSet); + cr.ClientId, fsr.FileSet, pool_select); if (!db_sql_query(ua->db, rx->query, NULL, NULL)) { bsendmsg(ua, "%s\n", db_strerror(ua->db)); } @@ -892,8 +923,7 @@ static int last_full_handler(void *ctx, int num_fields, char **row) { RESTORE_CTX *rx = (RESTORE_CTX *)ctx; - rx->JobTDate = strtoll(row[1], NULL, 10); - + rx->JobTDate = str_to_int64(row[1]); return 0; } @@ -902,7 +932,6 @@ static int last_full_handler(void *ctx, int num_fields, char **row) */ static int fileset_handler(void *ctx, int num_fields, char **row) { - /* row[0] = FileSet (name) */ if (row[0]) { add_prompt((UAContext *)ctx, row[0]); diff --git a/bacula/src/dird/ua_select.c b/bacula/src/dird/ua_select.c index 531039f8d8..1572bfa341 100644 --- a/bacula/src/dird/ua_select.c +++ b/bacula/src/dird/ua_select.c @@ -144,11 +144,11 @@ int do_keyword_prompt(UAContext *ua, char *msg, char **list) STORE *select_storage_resource(UAContext *ua) { char name[MAX_NAME_LENGTH]; - STORE *store = NULL; + STORE *store; start_prompt(ua, _("The defined Storage resources are:\n")); LockRes(); - while ((store = (STORE *)GetNextRes(R_STORAGE, (RES *)store))) { + foreach_res(store, R_STORAGE) { add_prompt(ua, store->hdr.name); } UnlockRes(); @@ -163,11 +163,11 @@ STORE *select_storage_resource(UAContext *ua) FILESET *select_fileset_resource(UAContext *ua) { char name[MAX_NAME_LENGTH]; - FILESET *fs = NULL; + FILESET *fs; start_prompt(ua, _("The defined FileSet resources are:\n")); LockRes(); - while ((fs = (FILESET *)GetNextRes(R_FILESET, (RES *)fs))) { + foreach_res(fs, R_FILESET) { add_prompt(ua, fs->hdr.name); } UnlockRes(); @@ -195,7 +195,7 @@ CAT *get_catalog_resource(UAContext *ua) if (!catalog) { start_prompt(ua, _("The defined Catalog resources are:\n")); LockRes(); - while ((catalog = (CAT *)GetNextRes(R_CATALOG, (RES *)catalog))) { + foreach_res(catalog, R_CATALOG) { add_prompt(ua, catalog->hdr.name); } UnlockRes(); @@ -212,11 +212,11 @@ CAT *get_catalog_resource(UAContext *ua) JOB *select_job_resource(UAContext *ua) { char name[MAX_NAME_LENGTH]; - JOB *job = NULL; + JOB *job; start_prompt(ua, _("The defined Job resources are:\n")); LockRes(); - while ( (job = (JOB *)GetNextRes(R_JOB, (RES *)job)) ) { + foreach_res(job, R_JOB) { add_prompt(ua, job->hdr.name); } UnlockRes(); @@ -231,11 +231,11 @@ JOB *select_job_resource(UAContext *ua) JOB *select_restore_job_resource(UAContext *ua) { char name[MAX_NAME_LENGTH]; - JOB *job = NULL; + JOB *job; start_prompt(ua, _("The defined Restore Job resources are:\n")); LockRes(); - while ( (job = (JOB *)GetNextRes(R_JOB, (RES *)job)) ) { + foreach_res(job, R_JOB) { if (job->JobType == JT_RESTORE) { add_prompt(ua, job->hdr.name); } @@ -254,11 +254,11 @@ JOB *select_restore_job_resource(UAContext *ua) CLIENT *select_client_resource(UAContext *ua) { char name[MAX_NAME_LENGTH]; - CLIENT *client = NULL; + CLIENT *client; start_prompt(ua, _("The defined Client resources are:\n")); LockRes(); - while ( (client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client)) ) { + foreach_res(client, R_CLIENT) { add_prompt(ua, client->hdr.name); } UnlockRes(); @@ -316,7 +316,7 @@ int get_client_dbr(UAContext *ua, CLIENT_DBR *cr) strcasecmp(ua->argk[i], _("fd")) == 0) && ua->argv[i]) { bstrncpy(cr->Name, ua->argv[i], sizeof(cr->Name)); if (!db_get_client_record(ua->jcr, ua->db, cr)) { - bsendmsg(ua, _("Could not find Client %s: ERR=%s"), ua->argv[i], + bsendmsg(ua, _("Could not find Client \"%s\": ERR=%s"), ua->argv[i], db_strerror(ua->db)); cr->ClientId = 0; break; @@ -369,7 +369,7 @@ int select_client_dbr(UAContext *ua, CLIENT_DBR *cr) bstrncpy(ocr.Name, name, sizeof(ocr.Name)); if (!db_get_client_record(ua->jcr, ua->db, &ocr)) { - bsendmsg(ua, _("Could not find Client %s: ERR=%s"), name, db_strerror(ua->db)); + bsendmsg(ua, _("Could not find Client \"%s\": ERR=%s"), name, db_strerror(ua->db)); return 0; } memcpy(cr, &ocr, sizeof(ocr)); @@ -394,7 +394,7 @@ int get_pool_dbr(UAContext *ua, POOL_DBR *pr) if (db_get_pool_record(ua->jcr, ua->db, pr)) { return pr->PoolId; } - bsendmsg(ua, _("Could not find Pool %s: ERR=%s"), pr->Name, db_strerror(ua->db)); + bsendmsg(ua, _("Could not find Pool \"%s\": ERR=%s"), pr->Name, db_strerror(ua->db)); } if (!select_pool_dbr(ua, pr)) { /* try once more */ return 0; @@ -416,7 +416,7 @@ int select_pool_dbr(UAContext *ua, POOL_DBR *pr) if (strcasecmp(ua->argk[i], _("pool")) == 0 && ua->argv[i]) { bstrncpy(pr->Name, ua->argv[i], sizeof(pr->Name)); if (!db_get_pool_record(ua->jcr, ua->db, pr)) { - bsendmsg(ua, _("Could not find Pool %s: ERR=%s"), ua->argv[i], + bsendmsg(ua, _("Could not find Pool \"%s\": ERR=%s"), ua->argv[i], db_strerror(ua->db)); pr->PoolId = 0; break; @@ -451,7 +451,7 @@ int select_pool_dbr(UAContext *ua, POOL_DBR *pr) bstrncpy(opr.Name, name, sizeof(opr.Name)); if (!db_get_pool_record(ua->jcr, ua->db, &opr)) { - bsendmsg(ua, _("Could not find Pool %s: ERR=%s"), name, db_strerror(ua->db)); + bsendmsg(ua, _("Could not find Pool \"%s\": ERR=%s"), name, db_strerror(ua->db)); return 0; } memcpy(pr, &opr, sizeof(opr)); @@ -520,11 +520,11 @@ int select_media_dbr(UAContext *ua, MEDIA_DBR *mr) POOL *select_pool_resource(UAContext *ua) { char name[MAX_NAME_LENGTH]; - POOL *pool = NULL; + POOL *pool; start_prompt(ua, _("The defined Pool resources are:\n")); LockRes(); - while ((pool = (POOL *)GetNextRes(R_POOL, (RES *)pool))) { + foreach_res(pool, R_POOL) { add_prompt(ua, pool->hdr.name); } UnlockRes(); @@ -550,7 +550,7 @@ POOL *get_pool_resource(UAContext *ua) if (pool) { return pool; } - bsendmsg(ua, _("Error: Pool resource %s does not exist.\n"), ua->argv[i]); + bsendmsg(ua, _("Error: Pool resource \"%s\" does not exist.\n"), ua->argv[i]); } return select_pool_resource(ua); } @@ -598,7 +598,7 @@ int get_job_dbr(UAContext *ua, JOB_DBR *jr) continue; } if (!db_get_job_record(ua->jcr, ua->db, jr)) { - bsendmsg(ua, _("Could not find Job %s: ERR=%s"), ua->argv[i], + bsendmsg(ua, _("Could not find Job \"%s\": ERR=%s"), ua->argv[i], db_strerror(ua->db)); jr->JobId = 0; break; @@ -775,7 +775,7 @@ STORE *get_storage_resource(UAContext *ua, int use_default) } else if (strcasecmp(ua->argk[i], _("job")) == 0) { if (!(jcr=get_jcr_by_partial_name(ua->argv[i]))) { - bsendmsg(ua, _("Job %s is not running.\n"), ua->argv[i]); + bsendmsg(ua, _("Job \"%s\" is not running.\n"), ua->argv[i]); return NULL; } store = jcr->store; @@ -788,7 +788,7 @@ STORE *get_storage_resource(UAContext *ua, int use_default) if (!store && store_name) { store = (STORE *)GetResWithName(R_STORAGE, store_name); if (!store) { - bsendmsg(ua, "Storage resource %s: not found\n", store_name); + bsendmsg(ua, "Storage resource \"%s\": not found\n", store_name); } } /* No keywords found, so present a selection list */ -- 2.39.5