From aad63dce7ca2a635ff478552a10e3464219cf1b3 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Thu, 3 Apr 2008 19:36:09 +0000 Subject: [PATCH] ebl Add statistics prunning code git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6736 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/protos.h | 1 + bacula/src/dird/ua_prune.c | 32 +++++++++++++++++++++++++++++++- bacula/technotes-2.3 | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index e1c94b39c6..6bcf5d1f5e 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -269,6 +269,7 @@ int insert_tree_handler(void *ctx, int num_fields, char **row); /* ua_prune.c */ int prune_files(UAContext *ua, CLIENT *client); int prune_jobs(UAContext *ua, CLIENT *client, int JobType); +int prune_stats(UAContext *ua, utime_t retention); bool prune_volume(UAContext *ua, MEDIA_DBR *mr); int job_delete_handler(void *ctx, int num_fields, char **row); int del_count_handler(void *ctx, int num_fields, char **row); diff --git a/bacula/src/dird/ua_prune.c b/bacula/src/dird/ua_prune.c index 641117f690..7299155d16 100644 --- a/bacula/src/dird/ua_prune.c +++ b/bacula/src/dird/ua_prune.c @@ -111,9 +111,11 @@ int file_delete_handler(void *ctx, int num_fields, char **row) */ int prunecmd(UAContext *ua, const char *cmd) { + DIRRES *dir; CLIENT *client; POOL_DBR pr; MEDIA_DBR mr; + utime_t retention; int kw; static const char *keywords[] = { @@ -165,7 +167,15 @@ int prunecmd(UAContext *ua, const char *cmd) prune_volume(ua, &mr); return true; case 3: /* prune stats */ - /* TODO: prune JobStat table */ + dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL); + if (!dir->stats_retention) { + return false; + } + retention = dir->stats_retention; + if (!confirm_retention(ua, &retention, "Statistics")) { + return false; + } + prune_stats(ua, retention); return true; default: break; @@ -174,6 +184,26 @@ int prunecmd(UAContext *ua, const char *cmd) return true; } +/* Prune Job stat records from the database. + * + */ +int prune_stats(UAContext *ua, utime_t retention) +{ + char ed1[50]; + POOL_MEM query(PM_MESSAGE); + utime_t now = (utime_t)time(NULL); + + db_lock(ua->db); + Mmsg(query, "DELETE FROM JobStat WHERE JobTDate < %s", + edit_uint64(now - retention, ed1)); + db_sql_query(ua->db, query.c_str(), NULL, NULL); + db_unlock(ua->db); + + ua->info_msg(_("Pruned Jobs from JobStat catalog.\n")); + + return true; +} + /* * Prune File records from the database. For any Job which * is older than the retention period, we unconditionally delete diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 630b24a323..fbb40d2fe2 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -25,6 +25,7 @@ Add long term statistics job table General: 03Apr08 +ebl Add statistics prunning with option and menu kes Separate unload_dev() from unload_other_device() in autochanger.c 02Apr08 kes Apply patch from bug #1069 that corrects spurious error messages -- 2.39.5