Skip to content

Commit

Permalink
pruning and purging code: log info about jobs being pruned.
Browse files Browse the repository at this point in the history
The pruning code now prints information about what jobids
are pruned during volume pruning. Before, this information
was not visible.
  • Loading branch information
pstorz committed Mar 3, 2020
1 parent 6f094fc commit 24d7700
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 29 deletions.
55 changes: 38 additions & 17 deletions core/src/dird/ua_prune.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2002-2009 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -67,7 +67,7 @@ int DelCountHandler(void* ctx, int num_fields, char** row)
/**
* Called here to make in memory list of JobIds to be
* deleted and the associated PurgedFiles flag.
* The in memory list will then be transversed
* The in memory list will then be traversed
* to issue the SQL DELETE commands. Note, the list
* is allowed to get to MAX_DEL_LIST_LEN to limit the
* maximum malloc'ed memory.
Expand Down Expand Up @@ -839,8 +839,8 @@ bool PruneVolume(UaContext* ua, MediaDbRecord* mr)
{
PoolMem query(PM_MESSAGE);
del_ctx del;
bool ok = false;
int count;
bool VolumeIsNowEmtpy = false;
int NumJobsToBePruned;

if (mr->Enabled == VOL_ARCHIVED) {
return false; /* Cannot prune archived volumes */
Expand All @@ -855,15 +855,28 @@ bool PruneVolume(UaContext* ua, MediaDbRecord* mr)
if (bstrcmp(mr->VolStatus, "Full") || bstrcmp(mr->VolStatus, "Used")) {
Dmsg2(050, "get prune list MediaId=%d Volume %s\n", (int)mr->MediaId,
mr->VolumeName);
count = GetPruneListForVolume(ua, mr, &del);
Dmsg1(050, "Num pruned = %d\n", count);
if (count != 0) { PurgeJobListFromCatalog(ua, del); }
ok = IsVolumePurged(ua, mr);


NumJobsToBePruned = GetPruneListForVolume(ua, mr, &del);
Jmsg(ua->jcr, M_INFO, 0,
_("Pruning volume %s: %d Jobs have expired and can be pruned.\n"),
mr->VolumeName, NumJobsToBePruned);
Dmsg1(050, "Num pruned = %d\n", NumJobsToBePruned);
if (NumJobsToBePruned != 0) { PurgeJobListFromCatalog(ua, del); }
VolumeIsNowEmtpy = IsVolumePurged(ua, mr);

if (!VolumeIsNowEmtpy) {
Jmsg(ua->jcr, M_INFO, 0,
_("Volume \"%s\" still contains jobs after pruning.\n"));
} else {
Jmsg(ua->jcr, M_INFO, 0,
_("Volume \"%s\" contains no jobs after pruning.\n"));
}
}

DbUnlock(ua->db);
if (del.JobId) { free(del.JobId); }
return ok;
return VolumeIsNowEmtpy;
}

/**
Expand All @@ -872,8 +885,8 @@ bool PruneVolume(UaContext* ua, MediaDbRecord* mr)
int GetPruneListForVolume(UaContext* ua, MediaDbRecord* mr, del_ctx* del)
{
PoolMem query(PM_MESSAGE);
int count = 0;
utime_t now, period;
int NumJobsToBePruned = 0;
utime_t now, VolRetention;
char ed1[50], ed2[50];

if (mr->Enabled == VOL_ARCHIVED) {
Expand All @@ -883,32 +896,40 @@ int GetPruneListForVolume(UaContext* ua, MediaDbRecord* mr, del_ctx* del)
/*
* Now add to the list of JobIds for Jobs written to this Volume
*/
period = mr->VolRetention;
VolRetention = mr->VolRetention;
now = (utime_t)time(NULL);
ua->db->FillQuery(query, BareosDb::SQL_QUERY::sel_JobMedia,
edit_int64(mr->MediaId, ed1),
edit_int64(now - period, ed2));
edit_int64(now - VolRetention, ed2));

Dmsg3(250, "Now=%d period=%d now-period=%s\n", (int)now, (int)period, ed2);
Dmsg3(250, "Now=%d VolRetention=%d now-VolRetention=%s\n", (int)now,
(int)VolRetention, ed2);
Dmsg1(050, "Query=%s\n", query.c_str());


if (!ua->db->SqlQuery(query.c_str(), FileDeleteHandler, (void*)del)) {
if (ua->verbose) { ua->ErrorMsg("%s", ua->db->strerror()); }
Dmsg0(050, "Count failed\n");
goto bail_out;
}
count = ExcludeRunningJobsFromList(del);
NumJobsToBePruned = ExcludeRunningJobsFromList(del);

Jmsg(ua->jcr, M_INFO, 0,
_("Volume \"%s\" has Volume Retention of %d sec. and has %d jobs that "
"will "
"be pruned\n"),
mr->VolumeName, VolRetention, NumJobsToBePruned);

bail_out:
return count;
return NumJobsToBePruned;
}

/**
* We have a list of jobs to prune or purge. If any of them is
* currently running, we set its JobId to zero which effectively
* excludes it.
*
* Returns the number of jobs that can be prunned or purged.
* Returns the number of jobs that can be pruned or purged.
*/
int ExcludeRunningJobsFromList(del_ctx* prune_list)
{
Expand Down
4 changes: 3 additions & 1 deletion core/src/dird/ua_purge.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2002-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -374,6 +374,8 @@ void PurgeJobListFromCatalog(UaContext* ua, del_ctx& del)
del.num_del++;
}
Dmsg1(150, "num_ids=%d\n", del.num_ids);
Jmsg(ua->jcr, M_INFO, 0, _("Purging the following JobIds: %s\n"),
jobids.c_str());
PurgeJobsFromCatalog(ua, jobids.c_str());
}
}
Expand Down
24 changes: 13 additions & 11 deletions systemtests/CMakeLists.txt
Expand Up @@ -569,25 +569,27 @@ endforeach()

set(tests_dir ${PROJECT_BINARY_DIR}/tests)
set(SYSTEM_TESTS
backup-bareos-test
backup-bareos-client-initiated-test
backup-bareos-notls
backup-bareos-passive-test
multiplied-device-test
virtualfull
virtualfull-bscan
backup-bareos-test
backup-bscan
bconsole-status-client
copy-bscan
copy-remote-bscan
bconsole-status-client
scheduler-backup-test
messages-resource
multiplied-device-test
reload-works-on-adding-client-resource
reload-works-on-adding-duplicate-job-resource
reload-works-on-unchanged-config
reload-works-on-adding-uncommented-string
reload-works-on-adding-empty-job-resource
reload-works-on-adding-second-director-resource
reload-works-on-adding-client-resource
backup-bareos-client-initiated-test
messages-resource
reload-works-on-adding-uncommented-string
reload-works-on-unchanged-config
scheduler-backup-test
upgrade-database-test
virtualfull
virtualfull-bscan
volume-pruning-test
)

set(SYSTEM_TESTS_DISABLED # initially empty
Expand Down

0 comments on commit 24d7700

Please sign in to comment.