Heading

Subheading/topic:
    
    Topic text
    

Subheading/topic:
    
    Topic text
    
Bacula Cheat Sheet
Bacula is a nifty backup software that is network-capable and stores data in the database for faster retrieval in case you need a certain file back. As a big fan of cheat sheets I created this cheat sheet.

What’s up?
Which files shall be backed up? show filesets I=Included, E=Excluded
What’s the server doing?    status dir
What’s the status of a certain job? status jobid=xx
What’s the client doing?    status client
What’s the streamer doing?  status storage
Anything new?   messages

Backing up:
Start a backup  run   …and choose the backup job
Label a new tape    label …and run mount afterwards

Restoring:
The common way (a user accidentally removed a file and wants the newest version back from the tapes:

Use the restore command.
Choose option 5 (Select the most recent backup for a client).
Commands:
    cd
    ls
    dir
    mark
    markdir
    unmark
    unmarkdir
    lsmark
    estimate
    pwd
    count
    find can use find * to show the files.
    done

Jobs
Last jobs   list jobs  …or list jobid=xx for a specific job

Statistics about last jobs  list jobtotal

Which files were backed up? list files jobid=xx

Job status
Status  means…
    T  Terminated normally
    C  Created but not yet running
    R  Running
    B  Blocked
    E  Terminated in Error
    e  Non-fatal error
    f  Fatal error
    D  Verify Differences
    A  Canceled by the user
    F  Waiting on the File daemon
    S  Waiting on the Storage daemon
    m  Waiting for a new Volume to be mounted
    M  Waiting for a Mount
    s  Waiting for Storage resource
    j  Waiting for Job resource
    c  Waiting for Client resource
    d  Wating for Maximum jobs
    t  Waiting for Start Time
    p  Waiting for higher priority job to finish
    W  Terminated with warnings

Tapes (bconsole commands)
  add - Assign a tape to a certain pool.
  delete media - Remove a tape.
  list files jobid=nn - List the files that were saved for JobId nn.
  list jobid=rn - Lists JobId nn from the Catalog.
  list jobmedia - List the media information for each Job run.
  list jobs - Lists all jobs in the Catalog that have run.
  list jobtotals - Lists totals for all jobs in the Catalog.
  list media - Lists all the media defined in the Catalog.
  list pools - List the pools defined in the Catalog (normally only
  Default is used).
  list volumes - Shows the volumes that bconsole knows about.
  messages - Prints any messages that have been directed to the
  console.
  mount storage=storage-name - Causes the drive associated with
  the storage device to be mounted again. When Bacula reaches the end of a volume and requests you to
  mount a new volume, you must issue this command after you have placed the new volume in the drive.
  In effect, it is the signal needed by Bacula to know to start reading or writing the new volume.
  quit - Exit or quit the console program.
  status dir - Print a status of all running jobs and jobs scheduled
  in the next 24 hours.
  status jobid=rn - Print a status of JobId nn if it is running.
  The Storage daemon is contacted and requested to print a current status of the job as well.
  status - The console program will prompt you to select a daemon
  type, then will request the daemon's status.
  unmount storage=storage-name - Unmounts the drive associated
  with the storage device with the name storage-name if the drive is not currently being used. This
  command is used if you wish Bacula to free the drive so that you can use it to label a tape.
  update volume - Change parameters of a tape.
Most of the commands given above, with the exception of list, will prompt you for the necessary
arguments if you simply enter the command name.

Terminology
Catalog
It is data in a SQL database running on the server. The catalog stores information about all assets
like jobs, clients and media. Without the catalog Bacula had no idea which files were backed up and
cannot restore them. In case of a disastrous loss of the catalog you need to take the latest bootstrap
and start restoring the catalog first using that information. So the catalog itself is also backed up
because without it the system is useless.

Volumes
Volumes (also called “media”) are either files on disk or physical tapes. When backups run they save
their data to volumes. Bacula keeps track in the catalog which data can be found on each volume.
Usually multiple backups run in parallel leading to a multiplexed stream of data written to volumes.
A volume always belongs to exactly one pool. Volumes have names/labels – tapes have the name that
is printed on the barcode sticker if the library have a barcode scanner.

Pool
A set of volumes. The pool can define a maximum number of volumes, the type of volumes (e.g. disk
or tape) and the retention period. For example you can have short-lived disk pools for small frequent
backups. On the other hand you may have long-lived tape pools that store data for several weeks or
months.

Job
A specific action like a backup, restore or copy (e.g. from disk to tape). Jobs are usually started
automatically by the director following a pre-defined schedule. Multiple jobs can run in parallel
and share their resources. The catalog keeps track of which jobs have run in the past in order to
know which volumes would be required to restore data from them.

In the bconsole you can see the running, past and scheduled jobs by running “stat dir”.

Job definition (aka jobdef)
The definition of a job. It is not stored in the catalog but in text files in /etc/bacula.

Client
A server to be backed up. Usually a file-daemon runs on the client. The director will talk to the
client to run jobs.

Fileset
Defines which files or directories to backup from a certain server. A job defines which fileset to
use for a backup.

Bootstrap
A small text file usually sent out via email frequently. It is required in case of a catalog loss to
find the volume that contains the last backup of the catalog.

The upstream documents reads: “The bootstrap file contains ASCII information that permits precise
specification of what files should be restored, what volume they are on, and where they are on the
volume. It is a relatively compact form of specifying the information, is human readable, and can be
edited with any text editor.”

The bootstrap data is not confidential and should be forwarded to an external location in case of a
disaster.

Message
Bacula can send messages to the console or via email. Results of jobs are sent via email.

Schedule
A definition of how often and at what time a job can be run.

Storage
Defines a way to write volumes. It is used by the storage daemon. A storage can be a path on the
local disks or the name of the tape device. Autochangers (aka “tape libraries”) are also supported.

Retention
A volume is locked after being written to. The retention period defines when the volume can be
overwritten again.

Scratch
This applies to tape volumes only. New tapes can be introduced into the “Scratch” pool. If a pool
is out of volumes to use then Bacula will take a volume from the Scratch pool and take it into its
own pool.

Levels
Backups can happen in three different levels: Full, Differential and Incremental. Only Full backups
are required. The other levels can be used to save space on volumes.

Full: every single file defined in assigned fileset is saved to the volume
Differential: only new files that were not contained in the last Full backup are backed up
Incremental: only new files that were not contained in the last Differential or Incremental backup
are backed up
Using only Full backups is secure because if you lose a full backup then you take the full backup
before it. However you are stubbornly backing up the same files time and again thus wasting space
on the volumes. Complete restores are fastest though because only the last full backup has to be
considered.

Using Full and Differential backups saves some space. During restores the last Full and last
Differential backup are considered. However multiple Differential backups may store files
redundantly thus wasting a little space.

Using Full and Incremental backups saves most space. However for a restore all Incremental backups
since the last Full backup need to be working. If one Incremental backup is broken in the chain
then only the last Full backup can be restored.

Using Full + Differential + Incremental backups saves most space while still keeping the risk of
losing data low. A restore requires the Incremental backups back up to the last Differential
backup + the last Full backup. This could look like:

Full
Differential
Incremental
Incremental
Incremental
Incremental
Differential
Incremental
Incremental
Incremental <–
Incremental
Full
…
To restore the highlighted Incremental backup you would need the previous Differential and Full
backups printed in bold letters.

Which mode to use depends on the type of data to backup. Database directories usually change in
its entirety so a Full backup is the best solution. File servers with millions of files gain some
advantage from using Full, Differential and Incremental backups.

Dangerous configurations:

Using a rare Full backup and rely on many intermediate Incremental backups. If any of the many
Incremental backups were faulty you would lose all data back to that time.
Losing the Full backup and only keeping Incremental backups. This may occur if the retention
periods are not adequately configured for Full backups.

Eject the tape.
        mt -f /dev/st0 eject

        For bacula: use bconsole to unmount the tape drive then exit the program and eject the tape
        using the command above.
        username@servername:/home/username
        $ sudo bconsole
                *unmount
                Automatically selected Catalog: MyCatalog
                Using Catalog "MyCatalog"
                The defined Storage resources are:
                     1: File1
                     2: File2
                     3: LTO-4
                     4: LTO-4_SD
                Select Storage resource (1-4): 4
                3001 Device ""LTO-4" (/dev/st0)" unmounted.
                *quit
        username@servername:/home/username
                $ mt -f /dev/st0 eject
        username@servername:/home/username
        $ sudo bconsole
                *mount
                Automatically selected Catalog: MyCatalog
                Using Catalog "MyCatalog"
                The defined Storage resources are:
                     1: File1
                     2: File2
                     3: LTO-4
                     4: LTO-4_SD
                Select Storage resource (1-4): 4
                3001 Device ""LTO-4" (/dev/st0)" is mounted with Volume "Tape-0004"
                You have messages.



Troubleshooting
Erase a label on the tape   <span style="color: #3366ff;">mt rewind && mt weof && mt rewind</span>

Tape drive full and could not be written to:
Solution was to use bconsole to unmount, then eject the tape from the commandline, then insert
Tape-0004 and mount from bconsole.
27-May 08:00 bacula-sd JobId 219: Warning: Director wanted Volume "Tape-0004".
    Current Volume "Tape-0003" not acceptable because:
    1998 Volume "Tape-0003" catalog status is Error, but should be Append, Purged or Recycle.

    I think the command "mount storage=LTO-4_SD" would have worked also but I am not sure
    how I would have ejected the full tape out.

Source for some of the data here: