Getting Bacula's Bootstrap (.bsr) Files To A Safe Place Via Email

Here is a very simple script to make sure that your Bacula bootstrap files are emailed to an offsite system. This script may be called manually, or from a cron job, or from a Bacula Catalog backup job's "After" Runscript.

Some key notes:
  • Bacula's bootstrap files are especially important when you need to recover your catalog database, or other files when there is a problem with the catalog, or the catalog database is not available.
  • It is wise to make sure you always have a copy of your most recent bootstrap files copied (or in this case emailed) to a safe location offsite.
  • Bootstrap files should be written for each backup job. Be sure to use the "WriteBootstrap = /path/to/bootstrap_files/%c_%n.bsr" job setting in all of your Job {} resources, or add it to a JobDefs {} resource that all of your jobs reference via the "JobDefs = JobDefsName" option.
  • Bootstrap files should not be written to Bacula's "WorkingDirectory". This directory may be wiped clean during the startup of any of the Bacula daemons (DIR, SD, FD).
  • Bacula appends to an existing bootstrap file for incremental and differential jobs. When a Full job is run, the file is overwritten. In this way, only one bootstrap file is ever needed in the case of an emergency to restore files.
  • Due to the previous item listed above, your bootstrap files should be named for the Client (%c) and the Job's Name (%n) only. If you run multiple jobs using different filesets against a client, you might also consider using the Fileset (%f) variable.
  • It is not wise to use "%i" or any other variable that would create a unique bootstrap file for each and every job that runs. Doing so will make recovery much more difficult because you will need to collect all of the bootstrap files for the Client/Job/Fileset combination, concatenate them in the proper order, and then perform some editing to build a valid bootstrap file.

A Simple Script To email Your Bootstrap Files Offsite:

# waa - 20150704 - Initial Release
#                - A simple script that tars all of the bootstrap files
#                  and uses the "sendEmail" program to email the tar file
#                  to our helpdesk after the catalog backup job.
#                - This script may be called manually, by a cron job, or
#                  in a RunScript (RunsWhen = after) resource in the
#                  Bacula catalog backup job.
# waa - 20160320 - Used ${servername} variable in the ${tgzfile} filename variable
#                - Added support for multiple directories ${dirs}
# -----------------------------------------------------------------------
# By: William A. Arlofski
#     Reverse Polarity, LLC
#     office: 860-824-2433
# Sample RunScript stanza in the Catalog backup job resource
# ----------------------------------------------------------
#       # waa - 20150627 - Email all BSR files to helpdesk, append %i so
#       #                  that the JobId can be listed in the email that
#       #                  is sent to our helpdesk
#       # ---------------------------------------------------------------
#       RunScript {
#         RunsWhen = after
#         RunsOnClient = no
#         RunsOnFailure = yes # May as well email a copy of bootstrap files
#         FailJobOnError = yes # Admin will be notified to check into issue
#         Command = "/etc/bacula/include/scripts/ %i"
#       }
# -------------------------------------------------------------------------
# Copyright (C) 2015 William A. Arlofski - waa-at-revpol-dot-com
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
# or visit
# -------------------------------------------------------------------------

# Do a simple check for a JobId
# -----------------------------
if [ -z $1 ]; then
  echo "Please submit a jobid as the first parameter."
  echo "This is only used in the Subject of the email generated"

# Set some variables
# ------------------
now=$(date +"%Y%m%d-%H%M%S")
tgzlisting=$(tar -cvzf ${tgzfile} ${dirs})

# Send the tar file and listing via sendEmail program
# ---------------------------------------------------
sendEmail -s localhost -f ${from} -t ${to} -u "${servername} - Bootstrap Files JobId=${1}" \
-m "${servername} - Bootstrap files as of ${now}\n\nFrom Directories: \
${dirs}\n\nListing of tgz file \"${tgzfile}\"\n----8<----\n${tgzlisting}\n----8<----\n" \
-a ${tgzfile}


# If there is a problem mailing tgz file exit with error to cause the job to fail
# and leave the tgz file around for an admin to take a look at or to manually copy
# --------------------------------------------------------------------------------
if [ ${err} -ne 0 ]; then
  echo "There was a problem emailing BSR files. sendEmail exit code was '${err}'."
  echo "Leaving ${tgzfile} in place."
    rm ${tgzfile}

echo "--[ $0 script exit code ${err} ]--"
exit ${err}

Sample email Output:

Revpol - Bootstrap files as of 20150704-114657

From Directory: /var/lib/bacula/bootstrap_files

Listing of tgz file "/tmp/ServerName-bacula-bsr_files-jobidxxx-20150704-114657.tgz"

Note: For the Catalog backups, I did not follow my own advice here with regards to the bootstrap naming convention. This will not hurt anything, and I could have just as easily set it to "Catalog.bsr" with no variables because I will have each night's Catalog.bsr file as an email attachment.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

That's what I need.

That's what I need. Only I have not yet got to realize. Apparently I'm too bad understand Linux.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <b> <i> <u> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the code without spaces and pay attention to upper/lower case.