From: Eric Bollengier Date: Fri, 24 Apr 2020 16:04:14 +0000 (+0200) Subject: BEE Backport bacula/src/dird/ua_purge.c X-Git-Tag: Release-11.3.2~1738 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e11d87329a7bdbace3f3c5bf67cbdb7dffa4007;p=thirdparty%2Fbacula.git BEE Backport bacula/src/dird/ua_purge.c This commit is the result of the squash of the following main commits: Author: Eric Bollengier Date: Fri Oct 4 09:20:43 2019 +0200 Do not purge running jobs in purge_job_list_from_catalog() Author: Eric Bollengier Date: Fri Jul 13 14:00:14 2018 +0200 Fix GCC 8 compiler warnings with memset() on objects Author: Eric Bollengier Date: Tue May 17 11:16:02 2016 +0200 Add BEEF marks for FileMedia feature Author: Eric Bollengier Date: Tue Apr 5 18:55:10 2016 +0200 Implement FileMedia feature and FO_OFFSETS for plugin - Allow plugins to use the FO_OFFSETS option - Add SQL support in cats - Add bvfs commands - Add FileMedia handling in the Storage Daemon - Add use FO_OFFSETS option in test plugin - Add new sql scripts to configure.in - Update catalog version to 1018 Author: Kern Sibbald Date: Fri Apr 17 18:33:35 2015 +0200 Refactor DB engine to be class based Author: Eric Bollengier Date: Thu Jun 27 11:51:35 2013 +0200 Fix #7777 about a warning message when using purge action=truncate command --- diff --git a/bacula/src/dird/ua_purge.c b/bacula/src/dird/ua_purge.c index 9484f2df45..6fbe232cb1 100644 --- a/bacula/src/dird/ua_purge.c +++ b/bacula/src/dird/ua_purge.c @@ -292,6 +292,10 @@ void purge_files_from_jobs(UAContext *ua, char *jobs) db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL); Dmsg1(050, "Delete File sql=%s\n", query.c_str()); + Mmsg(query, "DELETE FROM FileMedia WHERE JobId IN (%s)", jobs); + db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL); + Dmsg1(050, "Delete FileMedia sql=%s\n", query.c_str()); + Mmsg(query, "DELETE FROM BaseFiles WHERE JobId IN (%s)", jobs); db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL); Dmsg1(050, "Delete BaseFiles sql=%s\n", query.c_str()); @@ -320,6 +324,8 @@ void purge_job_list_from_catalog(UAContext *ua, del_ctx &del) POOL_MEM jobids(PM_MESSAGE); char ed1[50]; + exclude_running_jobs_from_list(&del); + for (int i=0; del.num_ids; ) { Dmsg1(150, "num_ids=%d\n", del.num_ids); pm_strcat(jobids, ""); @@ -427,6 +433,10 @@ void purge_jobs_from_catalog(UAContext *ua, char *jobs) db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL); Dmsg1(050, "Delete JobMedia sql=%s\n", query.c_str()); + Mmsg(query, "DELETE FROM FileMedia WHERE JobId IN (%s)", jobs); + db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL); + Dmsg1(050, "Delete JobMedia sql=%s\n", query.c_str()); + Mmsg(query, "DELETE FROM Log WHERE JobId IN (%s)", jobs); db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL); Dmsg1(050, "Delete Log sql=%s\n", query.c_str()); @@ -442,7 +452,6 @@ void purge_jobs_from_catalog(UAContext *ua, char *jobs) db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL); upgrade_copies(ua, jobs); - /* Now remove the Job record itself */ Mmsg(query, "DELETE FROM Job WHERE JobId IN (%s)", jobs); db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL); @@ -684,8 +693,8 @@ int truncate_cmd(UAContext *ua, const char *cmd) if (find_arg(ua, "cache") > 0) { return cloud_volumes_cmd(ua, cmd, "truncate cache"); } - - memset(&pr, 0, sizeof(pr)); + + bmemset(&pr, 0, sizeof(pr)); /* * Look for all Purged volumes that can be recycled, are enabled and @@ -773,8 +782,8 @@ bool mark_media_purged(UAContext *ua, MEDIA_DBR *mr) */ if (mr->RecyclePoolId && mr->RecyclePoolId != mr->PoolId) { POOL_DBR oldpr, newpr; - memset(&oldpr, 0, sizeof(POOL_DBR)); - memset(&newpr, 0, sizeof(POOL_DBR)); + bmemset(&oldpr, 0, sizeof(POOL_DBR)); + bmemset(&newpr, 0, sizeof(POOL_DBR)); newpr.PoolId = mr->RecyclePoolId; oldpr.PoolId = mr->PoolId; if ( db_get_pool_numvols(jcr, ua->db, &oldpr)