Re: (My) Job pruning seems not to work as intended

Bill Arlofski via Bacula-users <[email protected]>
Newsgroups gmane.comp.bacula.user
Message-ID <[email protected]>
On 10/23/24 10:59 AM, Justin Case wrote:
> I used this in an admin job, but no verify/admin jobs older than 6mo got deleted:
> 
>    Runscript {
>      RunsWhen = "Before"
>      RunsOnClient = no
>      Console = "delete from job where (type in ('V', 'D') or (type = 'B' and jobbytes = 0 and jobfiles = 0)) and starttime < now()-interval '6 months';"
>    }


Hello Justin,

That will not work as it currently is.

The reason is that the `Console =` option is meant to send only bconsole specific commands to the Director.

Also, I always recommend to not use the Console command at all and instead use the `Command =` option and point it to a small 
script for a few reasons:

- Any output from the Console command will be logged as `JobId: 0` and will not be logged to the catalog, and it is confusing 
to see random JobId: 0 log entries intermixed with other job log entries in the bacula log file.

- Using a script, all of its stdout will be logged in the job that called 
it, so you can report progress of a script simply 
by using the `echo` command in a shell script.

- You have full control of what happens in a script and the order of events. `Console =` cannot be guaranteed to run in the 
order specified in a Job (If you have more than one)

So, I would do something in a small script like:
----8<----
#!/bin/bash

# First, SELECT using the same SQL command so you have in your job log what jobs were deleted
echo -e "sql\nSELECT jobid, name from job ....\n\nquit\n" | bconsole

# Next, DELETE using your SQL command but it needs to be passed to bconsole
echo -e "sql\nDELETE from job where ....\n\nquit\n" | bconsole
----8<----

Notice that `echo -e` is used. This allows us to send multiple commands using the `\n` (line feed). We need this because we 
have to first put bconsole into its `sql` mode so we can send the SELECT and DELETE SQL commands.

Also notice there are two `\n` after the SQL commands and before the quit command. This is
 so we "Terminate query mode with a 
blank line." as the bconsole sql command tells us when we enter that mode. :)


Hope this helps,
Bill

-- 
Bill Arlofski
[email protected]

_______________________________________________
Bacula-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bacula-users
signature.asc (application/pgp-signature, 509 B)
-----BEGIN PGP SIGNATURE-----
Version: ProtonMail

wsBzBAEBCAAnBQJnGTAbCRBIDTDab9XDQBYhBMuLnlBaSQiuSUbb6UgNMNpv
1cNAAADX5gf7BQvn3R1VcnfP+8+MGh8BlL6bwa3NFiA47T+0jctHB8J8Z/v7
NxjEN0fEc70IfHM/idWUW+JWqdRNpUD2FR2tyeBteXkeJPhg30TbJz1ngQ8C
h0fHLj2f88BtX+G65a5/Cx6O7xXCC4rQlZNC4G6SbrP4cFlu65TwqA1BjmVP
kg+K81R1F0jxY+ccIVp8C9wHh2Iu5y8egfGNrOGGQJJ4g9LR0w8yj1ziWsmj
nhevAw1cnRYL9el0y5Uzni3s4iCll7k8PESYd9rvIVBncoD1bONWEsQvWlal
1ugdMzZ+WGgG4XeTYiwGq41zgbFLpuWVCEsQfw3gy3CxDHlbvEDt/Q==
=DuiG
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.