From da9f0514d42ea9e9774ac191efa6d6f77a6363f5 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 28 Apr 2002 13:21:16 +0000 Subject: [PATCH] Start of prune cmd. See kes28Apr02 git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/bc_types.h | 2 ++ bacula/src/cats/cats.h | 1 + bacula/src/cats/sql_delete.c | 8 ++++---- bacula/src/dird/Makefile.in | 4 ++-- bacula/src/dird/dird_conf.c | 19 +++++++++++-------- bacula/src/dird/dird_conf.h | 15 ++++++++------- bacula/src/dird/job.c | 2 +- bacula/src/dird/ua_cmds.c | 3 ++- bacula/src/dird/ua_server.c | 1 + bacula/src/lib/parse_conf.c | 19 ++++++++++--------- bacula/src/lib/protos.h | 5 +++-- bacula/src/lib/util.c | 14 +++++++++++++- bacula/src/version.h | 4 ++-- 13 files changed, 60 insertions(+), 37 deletions(-) diff --git a/bacula/src/bc_types.h b/bacula/src/bc_types.h index 2ab537fd64..52af67ddc6 100644 --- a/bacula/src/bc_types.h +++ b/bacula/src/bc_types.h @@ -168,6 +168,8 @@ typedef float float32_t; #define uint64_t u_int64_t #define uintmax_t u_intmax_t +#define btime_t uint64_t + #ifdef HAVE_CYGWIN #define socklen_t int #endif diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index d765ccb8a7..6968b0a6a4 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -228,6 +228,7 @@ typedef struct s_db { /* ***FIXME*** FileId_t should be uint64_t */ typedef uint32_t FileId_t; typedef uint32_t DBId_t; /* general DB id type */ +typedef uint32_t JobId_t; /* Job information passed to create job record and update diff --git a/bacula/src/cats/sql_delete.c b/bacula/src/cats/sql_delete.c index d8c7fdfbd7..a022f84901 100644 --- a/bacula/src/cats/sql_delete.c +++ b/bacula/src/cats/sql_delete.c @@ -112,7 +112,7 @@ db_delete_pool_record(B_DB *mdb, POOL_DBR *pr) #define MAX_DEL_LIST_LEN 1000000 struct s_del_ctx { - uint32_t *JobId; + JobId_t *JobId; int num_ids; /* ids stored */ int max_ids; /* size of array */ int num_del; /* number deleted */ @@ -135,10 +135,10 @@ static int delete_handler(void *ctx, int num_fields, char **row) } if (del->num_ids == del->max_ids) { del->max_ids = (del->max_ids * 3) / 2; - del->JobId = (uint32_t *)brealloc(del->JobId, sizeof(uint32_t) * + del->JobId = (JobId_t *)brealloc(del->JobId, sizeof(JobId_t) * del->max_ids); } - del->JobId[del->num_ids++] = (uint32_t)strtod(row[0], NULL); + del->JobId[del->num_ids++] = (JobId_t)strtod(row[0], NULL); return 0; } @@ -165,7 +165,7 @@ static int do_media_purge(B_DB *mdb, MEDIA_DBR *mr) } else if (del.max_ids > MAX_DEL_LIST_LEN) { del.max_ids = MAX_DEL_LIST_LEN; } - del.JobId = (uint32_t *)malloc(sizeof(uint32_t) * del.max_ids); + del.JobId = (JobId_t *)malloc(sizeof(JobId_t) * del.max_ids); db_sql_query(mdb, mdb->cmd, delete_handler, (void *)&del); for (i=0; i < del.num_ids; i++) { diff --git a/bacula/src/dird/Makefile.in b/bacula/src/dird/Makefile.in index 699d0a8e06..fa96686e51 100644 --- a/bacula/src/dird/Makefile.in +++ b/bacula/src/dird/Makefile.in @@ -26,7 +26,7 @@ SVRSRCS = dird.c authenticate.c backup.c catreq.c dird_conf.c \ scheduler.c ua_cmds.c \ ua_dotcmds.c \ ua_db_query.c ua_retention.c \ - ua_input.c ua_output.c ua_run.c \ + ua_input.c ua_output.c ua_prune.c ua_run.c \ ua_select.c ua_server.c \ ua_status.c verify.c SVROBJS = dird.o authenticate.o backup.o catreq.o dird_conf.o \ @@ -35,7 +35,7 @@ SVROBJS = dird.o authenticate.o backup.o catreq.o dird_conf.o \ scheduler.o ua_cmds.o \ ua_dotcmds.o \ ua_db_query.o ua_retention.o \ - ua_input.o ua_output.o ua_run.o \ + ua_input.o ua_output.o ua_prune.o ua_run.o \ ua_select.o ua_server.o \ ua_status.o verify.o diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index 5d3dc5a8b7..fbf4e4e828 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -92,7 +92,6 @@ static struct res_items dir_items[] = { {"password", store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0}, {"fdconnecttimeout", store_time,ITEM(res_dir.FDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30}, {"sdconnecttimeout", store_time,ITEM(res_dir.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30}, - {NULL, NULL, NULL, 0, 0, 0} }; @@ -111,6 +110,7 @@ static struct res_items cli_items[] = { {"catalog", store_res, ITEM(res_client.catalog), R_CATALOG, 0, 0}, {"fileretention", store_time, ITEM(res_client.FileRetention), 0, ITEM_DEFAULT, 60*60*24*30}, {"jobretention", store_time, ITEM(res_client.JobRetention), 0, ITEM_DEFAULT, 60*60*24*365}, + {"autoprune", store_yesno, ITEM(res_client.AutoPrune), 1, ITEM_DEFAULT, 1}, {NULL, NULL, NULL, 0, 0, 0} }; @@ -358,7 +358,7 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ... } switch (type) { case R_DIRECTOR: - sendit(sock, "Director: name=%s maxjobs=%d FDtimeout=%d SDtimeout=%d\n", + sendit(sock, "Director: name=%s maxjobs=%d FDtimeout=%" lld " SDtimeout=%" lld "\n", reshdr->name, res->res_dir.MaxConcurrentJobs, res->res_dir.FDConnectTimeout, res->res_dir.SDConnectTimeout); @@ -373,8 +373,9 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ... case R_CLIENT: sendit(sock, "Client: name=%s address=%s FDport=%d\n", res->res_client.hdr.name, res->res_client.address, res->res_client.FDport); - sendit(sock, "JobRetention=%d FileRetention=%d\n", - res->res_client.JobRetention, res->res_client.FileRetention); + sendit(sock, "JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n", + res->res_client.JobRetention, res->res_client.FileRetention, + res->res_client.AutoPrune); if (res->res_client.catalog) { sendit(sock, " --> "); dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock); @@ -445,11 +446,13 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ... case R_POOL: sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name, res->res_pool.pool_type); - sendit(sock, " use_cat=%d use_once=%d acpt_any=%d\n", + sendit(sock, " use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n", res->res_pool.use_catalog, res->res_pool.use_volume_once, - res->res_pool.accept_any_volume); - sendit(sock, " cat_files=%d max_vols=%d\n", - res->res_pool.catalog_files, res->res_pool.max_volumes); + res->res_pool.accept_any_volume, res->res_pool.catalog_files); + sendit(sock, " max_vols=%d auto_recycle=%d VolumeRetention=%" lld "\n", + res->res_pool.max_volumes, res->res_pool.AutoRecycle, + res->res_pool.VolumeRetention); + sendit(sock, " LabelFormat=%s\n", res->res_pool.label_format? res->res_pool.label_format:"NONE"); break; diff --git a/bacula/src/dird/dird_conf.h b/bacula/src/dird/dird_conf.h index f36c24587f..d8c899cc6e 100644 --- a/bacula/src/dird/dird_conf.h +++ b/bacula/src/dird/dird_conf.h @@ -83,8 +83,8 @@ struct s_res_dir { char *subsys_directory; /* SubsysDirectory */ struct s_res_msgs *messages; int MaxConcurrentJobs; - int FDConnectTimeout; /* timeout for connect in seconds */ - int SDConnectTimeout; /* timeout in seconds */ + btime_t FDConnectTimeout; /* timeout for connect in seconds */ + btime_t SDConnectTimeout; /* timeout in seconds */ }; typedef struct s_res_dir DIRRES; @@ -96,8 +96,9 @@ struct s_res_client { RES hdr; int FDport; /* Where File daemon listens */ - uint32_t FileRetention; /* file retention period in seconds */ - uint32_t JobRetention; /* job retention period in seconds */ + int AutoPrune; /* Do automatic pruning? */ + btime_t FileRetention; /* file retention period in seconds */ + btime_t JobRetention; /* job retention period in seconds */ char *address; char *password; struct s_res_cat *catalog; /* Catalog resource */ @@ -147,8 +148,8 @@ struct s_res_job { int RestoreJobId; /* What -- JobId to restore */ char *RestoreWhere; /* Where on disk to restore -- directory */ int RestoreOptions; /* How (overwrite, ..) */ - int MaxRunTime; /* max run time in seconds */ - int MaxStartDelay; /* max start delay in seconds */ + btime_t MaxRunTime; /* max run time in seconds */ + btime_t MaxStartDelay; /* max start delay in seconds */ struct s_res_msgs *messages; /* How and where to send messages */ struct s_res_sch *schedule; /* When -- Automatic schedule */ @@ -212,7 +213,7 @@ struct s_res_pool { int use_volume_once; /* write on volume only once */ int accept_any_volume; /* accept any volume */ int max_volumes; /* max number of volumes */ - uint32_t VolumeRetention; /* volume retention period in seconds */ + btime_t VolumeRetention; /* volume retention period in seconds */ int AutoRecycle; /* auto recycle */ }; typedef struct s_res_pool POOL; diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 9200ccaddd..0d4cc77285 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -135,7 +135,7 @@ static void job_thread(void *arg) Dmsg0(100, "=====Start Job=========\n"); jcr->start_time = now; /* set the real start time */ if (jcr->job->MaxStartDelay != 0 && jcr->job->MaxStartDelay < - (jcr->start_time - jcr->sched_time)) { + (btime_t)(jcr->start_time - jcr->sched_time)) { Jmsg(jcr, M_FATAL, 0, _("Job cancelled because max delay time exceeded.\n")); free_jcr(jcr); } diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 4ecc17a4bc..63c43b7ec3 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -50,6 +50,7 @@ extern int sqlquerycmd(UAContext *ua, char *cmd); extern int querycmd(UAContext *ua, char *cmd); extern int runcmd(UAContext *ua, char *cmd); extern int retentioncmd(UAContext *ua, char *cmd); +extern int prunecmd(UAContext *ua, char *cmd); /* Forward referenced functions */ static int addcmd(UAContext *ua, char *cmd), createcmd(UAContext *ua, char *cmd), cancelcmd(UAContext *ua, char *cmd); @@ -80,7 +81,7 @@ static struct cmdstruct commands[] = { { N_("list"), listcmd, _("list [pools | jobs | jobtotals | media | files job=]; from catalog")}, { N_("messages"), messagescmd, _("messages")}, { N_("mount"), mountcmd, _("mount ")}, - { N_("retention"), retentioncmd, _("retention")}, + { N_("prune"), prunecmd, _("prune expired records from catalog")}, { N_("run"), runcmd, _("run ")}, { N_("setdebug"), setdebugcmd, _("sets debug level")}, { N_("show"), showcmd, _("show (resource records) [jobs | pools | ... | all]")}, diff --git a/bacula/src/dird/ua_server.c b/bacula/src/dird/ua_server.c index 606ea60ec4..75a09d86c4 100644 --- a/bacula/src/dird/ua_server.c +++ b/bacula/src/dird/ua_server.c @@ -140,6 +140,7 @@ static void handle_UA_client_request(void *arg) } } else if (stat == 0) { if (ua.UA_sock->msglen == BNET_TERMINATE) { + quit = TRUE; break; } bnet_sig(ua.UA_sock, BNET_POLL); diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index 009ab8cd81..4c2fb5d80b 100755 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -151,12 +151,12 @@ void init_resource(int type, struct res_items *items) if (items[i].handler == store_yesno) { *(int *)(items[i].value) |= items[i].code; } else if (items[i].handler == store_pint || - items[i].handler == store_int || - items[i].handler == store_time) { + items[i].handler == store_int) { *(int *)(items[i].value) = items[i].default_value; } else if (items[i].handler == store_int64) { *(int64_t *)(items[i].value) = items[i].default_value; - } else if (items[i].handler == store_size) { + } else if (items[i].handler == store_size || + items[i].handler == store_time) { *(uint64_t *)(items[i].value) = items[i].default_value; } } @@ -586,7 +586,8 @@ void store_size(LEX *lc, struct res_items *item, int index, int pass) /* Store a time period in seconds */ void store_time(LEX *lc, struct res_items *item, int index, int pass) { - int token, i, ch, value; + int token, i, ch; + btime_t value; int mod[] = {'*', 's', 'm', 'h', 'd', 'w', 'o', 'q', 'y', 0}; int mult[] = {1, 60, 60*60, 60*60*24, 60*60*24*7, 60*60*24*30, 60*60*24*91, 60*60*24*365}; @@ -595,11 +596,11 @@ void store_time(LEX *lc, struct res_items *item, int index, int pass) errno = 0; switch (token) { case T_NUMBER: - token = (int)strtod(lc->str, NULL); - if (errno != 0 || token < 0) { + value = (btime_t)strtod(lc->str, NULL); + if (errno != 0 || value < 0) { scan_err1(lc, "expected a time period, got: %s", lc->str); } - *(int *)(item->value) = token; + *(btime_t *)(item->value) = value; break; case T_IDENTIFIER: case T_STRING: @@ -621,11 +622,11 @@ void store_time(LEX *lc, struct res_items *item, int index, int pass) if (mod[i] == 0 || !is_a_number(lc->str)) { scan_err1(lc, "expected a time period, got: %s", lc->str); } - value = (int)strtod(lc->str, NULL); + value = (btime_t)strtod(lc->str, NULL); if (errno != 0 || value < 0) { scan_err1(lc, "expected a time period, got: %s", lc->str); } - *(int *)(item->value) = value * mult[i]; + *(btime_t *)(item->value) = value * mult[i]; break; default: scan_err1(lc, "expected a time period, got: %s", lc->str); diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index 36b1d17149..115cb327f9 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -137,8 +137,9 @@ char * encode_time __PROTO((time_t time, char *buf)); char * encode_mode __PROTO((mode_t mode, char *buf)); char * edit_uint_with_commas __PROTO((uint64_t val, char *buf)); char * add_commas __PROTO((char *val, char *buf)); -int do_shell_expansion(char *name); -int is_a_number(const char *num); +char * edit_uint (uint64_t val, char *buf); +int do_shell_expansion (char *name); +int is_a_number (const char *num); /* diff --git a/bacula/src/lib/util.c b/bacula/src/lib/util.c index 742f373fe7..99b0d42dbb 100644 --- a/bacula/src/lib/util.c +++ b/bacula/src/lib/util.c @@ -53,7 +53,7 @@ int is_a_number(const char *n) } if (digit_seen && (*n == 'e' || *n == 'E') && (ISDIGIT(n[1]) || ((n[1]=='-' || n[1] == '+') && ISDIGIT(n[2])))) { - n += 2; /* skip e- or e+ */ + n += 2; /* skip e- or e+ or e digit */ while (ISDIGIT(*n)) { n++; } } return digit_seen && *n==0; @@ -71,6 +71,18 @@ char *edit_uint_with_commas(uint64_t val, char *buf) return add_commas(buf, buf); } +/* + * Edit an integer number, the supplied buffer + * must be at least 27 bytes long. The incoming number + * is always widened to 64 bits. + */ +char *edit_uint(uint64_t val, char *buf) +{ + sprintf(buf, "%" lld, val); + return buf; +} + + /* * Add commas to a string, which is presumably * a number. diff --git a/bacula/src/version.h b/bacula/src/version.h index 1f1c3dab0d..7021c25103 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #define VERSION "1.19" #define VSTRING "1" -#define DATE "27 April 2002" -#define LSMDATE "27Apr02" +#define DATE "28 April 2002" +#define LSMDATE "28Apr02" /* Debug flags */ #define DEBUG 1 -- 2.39.5