On 12/29/22 03:36, Yateen Shaligram Bhagat (Nokia) wrote:
Hi all,

We have  a requirement for renaming a job after its migration.

Our strategy is to migrate  the last full job of the year from a regular pool 
into an archive pool using the Migrate job.

(tried this, it works fine)

However we need that once the job is migrated, rename it to say 
<job_name>_archive_<year>.

Is this possible (in bacula V 9.4.4)

Thanks

Yateen


Hello Yateen,

Not sure why you would really need/want to do this, but this will work using 
bconsole:
----8<----
# echo -e "sql\nUPDATE job SET name='RenamedJobName' WHERE 
jobid='xxx';\n\nquit\n" | bconsole
----8<----


It can also just be done directly with mysql or psql DB clients.


You can even put that in a script, and call that script in a RunScript stanza 
in your Migration job:
----8<----
RunScript {
  RunsWhen = after
  Command = "/opt/bacula/script/rename_migrate_job.sh %I"
}
----8<----

Note:
- %I is the new jobid that a job is being copied or migrated to
- Unfortunately, there is currently no variable for the original Job Name
  so we use some SQL in the script (below) to get it.


/opt/bacula/script/rename_migrate_job.sh
----8<----
#!/bin/bash
#
# Receives %I (new copied/migrated jobid) as $1

year=$(date +%Y)
bcbin="/opt/bacula/bin/bconsole"
bccfg="/opt/bacula/etc/bconsole.conf"

# Need to get the old original backup job's name:
# -----------------------------------------------
old_job_name=$(echo -e "sql\nSELECT jobid,name FROM job WHERE jobid='$1';\n" \
              | ${bcbin} -c ${bccfg} | grep "^| \+[0-9]" | awk '{print $4}')

# The above line will need to be modified if you have spaces in your job
# names, but no one would do something that silly, so it should be OK :)

new_job_name="${old_job_name}_archive_${year}"
echo -e "sql\nUPDATE job SET name=\'${new_job_name}\' WHERE 
jobid=\'$1\';\n\nquit\n" \
     | ${bcbin} -c ${bccfg}
----8<----


Something like this should do what you need, but you may need to play with the quoting, backslash escaping, etc. Writing a sample shell script in my email client is not the easiest thing I have done today. :)


P.S. Upgrade!
     Bacula v9.4.4 is VERY OLD, and most likely will not have the necessary 
"%I" variable.


Hope this helps!

Happy New year!
Bill

--
Bill Arlofski
w...@protonmail.com

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users

Reply via email to