Bacula Quick

From Devpit
Jump to: navigation, search

See also, Windows Boot Repair.

Bacula Maintenance

When running bconsole, try these hints:

  • list volumes
  • list jobs
  • status dir
  • status client
  • status client=clientname
  • status storage

For more esoteric adjustments, you may need to connect to PostgreSQL. Here are some suggestions.

  • To find all the full backups on a particular volume:
SELECT media.mediaid, job.jobid, job.level, job.name, job.starttime FROM (SELECT mediaid, jobid FROM jobmedia
  WHERE mediaid=69 GROUP BY mediaid, jobid) AS media, job
  WHERE media.jobid = job.jobid AND job.level = 'F' ORDER BY job.jobid;
  • If a major backup is botched and you need to rerun it, you may need to reuse recent tapes. After purging the tapes to reuse, they'll be available but Bacula will reuse them last because they have the latest lastwritten timestamp. To get Bacula to reuse the available tapes in the numbered order you may find this pattern helpful. It sets the lastwritten timestamp on volumes in Purged or Error status to an increasing series ending with the first volume in Full or Append status.
BEGIN;
UPDATE media SET lastwritten = timestamp '2000-01-01 00:00:00' + interval '1 seconds' * ((media.mediaid - off.off + mx.mx) % mx.mx)
FROM
  (SELECT MAX(mediaid) AS mx FROM media) AS mx,
  (SELECT COALESCE(MIN(mediaid),0) AS off FROM media WHERE mediatype = 'FileMedia0' AND volstatus IN ('Full', 'Append')) AS off
WHERE mediatype = 'FileMedia0' AND volstatus IN ('Purged', 'Recycle', 'Error');
SELECT * FROM media ORDER BY mediaid;
COMMIT; -- or ROLLBACK;
  • To delete all failed jobs:
export PGPASSWORD=xxx
echo "SELECT jobid FROM job WHERE jobstatus IN ('A', 'f', 'E')" | psql -t bacula | egrep '[0-9]' | while read jobid; do echo $jobid; echo "delete jobid=$jobid" | bconsole; done
  • To find volumes with no remaining jobs in catalog (having expired or been deleted, for example):
SELECT media.mediaid, media.volumename, media.volstatus, media.lastwritten
FROM media
LEFT JOIN jobmedia ON
  media.mediaid = jobmedia.mediaid
WHERE
  media.volstatus IN ('Full', 'Used', 'Append')
  AND jobmedia.mediaid IS NULL

Client installations

  • Each installation needs a unique password. Here's a handy alias to make these passwords: alias password='(LC_ALL=C tr -dc A-Za-z0-9 < /dev/urandom | head -c32;echo)'
  • After installing the client as shown below, add Job and Client to bacula-dir.conf.
  • To test a client, run bconsole and run "client dir=clientname".


FreeBSD

  • pkg install bacula-client
  • Create /usr/local/etc/bacula/bacula-fd.conf as follows:
# Bacula File Daemon config.
# Set a unique password for each machine.

FileDaemon {
	Name = TypicalFD
	Maximum Concurrent Jobs = 5
	Pid Directory = /var/run
	WorkingDirectory = /var/db/bacula
}

Director {
	Name = MainDirector
	Password = xxx
}

# Send all messages back to Director.
Messages {
	Name = Standard
	director = MainDirector = all
}
  • In /etc/rc.conf: bacula_fd_enable="YES"
  • service bacula-fd start


OpenBSD

  • pkg_add bacula-client
  • Create /etc/bacula/bacula-fd.conf like above, but refer to .sample for Pid Directory and Working Directory.
  • /etc/rc.d/bacula start


Ubuntu

  • apt-get install bacula-fd
  • Create /etc/bacula/bacula-fd.conf like above, but refer to .sample for Pid Directory and Working Directory.
  • service bacula-fd start


CentOS

  • yum install bacula-client
  • Create /etc/bacula/bacula-fd.conf like above, but refer to .sample for Pid Directory and Working Directory.
  • chkconfig bacula-fd on
  • service bacula-fd start


MacOS

There doesn't appear to be a distribution of a compiled client for Bacula. You can compile it, but that's a chore and hard to maintain. Alternatively, the client for Bareos seems to work fine. (Bareos is a branch of Bacula.)

An easy approach is to use the following config file. Keeping installation instructions in it makes it easy for future maintainers to reference.

# Bareos File Daemon config for MacOS.
# * ftp 'http://download.bareos.org/bareos/release/15.2/MacOS/bareos-filedaemon-15.2.2.git.1448535096.dmg'
# * Mount the dmg and extract bareos-15.2.2.git.1448535096.pkg (ed0afa1dfd28b15e454375a022d40472).
# * Double-click and install it with defaults.
# * Copy this file to /usr/local/etc/bareos/bareos-fd.conf and change the password in it.
# * `launchctl load -w /Library/LaunchDaemons/org.bareos.bareos-fd.plist`
# * Check if it's running. If not, debug with: `/usr/local/sbin/bareos-fd -f -c /usr/local/etc/bareos/bareos-fd.conf`

# Set a unique password for each machine.
# Everything else is configured on the director.

FileDaemon {
	Name = TypicalFD
	Maximum Concurrent Jobs = 5
	Working Directory = /var/run
	compatible = yes  # Tell Bareos to be compatible with Bacula.
}

Director {
	Name = MainDirector
	Password = xxx
}

# Send all messages back to Director.
Messages {
	Name = Standard
	director = MainDirector = all
}

Windows

  • On Windows Server 2008, you may need to allow VSS. Perhaps this has been fixed in later client versions, so try without this first. If the log records a VSS failure, create a key under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\VSS\VssAccessControl named System as dword set to 1.
  • Buy a license, and download bacula-enterprise-win64-x.x.x.exe from http://blog.bacula.org/download-center/
  • Create C:\Program Files\Bacula\bacula-fd.conf as follows:
# Bacula File Daemon config.
# Set a unique password for each machine.

FileDaemon {
	Name = TypicalFD
	Maximum Concurrent Jobs = 5
	Pid Directory = "C:\\Program Files\\Bacula\\working"
	Plugin Directory = "C:\\Program Files\\Bacula\\plugins"
	WorkingDirectory = "C:\\Program Files\\Bacula\\working"
}

Director {
	Name = MainDirector
	Password = xxx
}

# Send all messages back to Director.
Messages {
	Name = Standard
	director = MainDirector = all
}


Server installation on FreeBSD

  • pkg install bacula-server postgresql93-server
  • Install and start PostgreSQL, see PostgreSQL On FreeBSD.
  • Create a user and database for bacula.
    • You can use /usr/local/share/bacula/create_postgresql_database, or I prefer:
CREATE USER bacula WITH PASSWORD 'xxx';
CREATE DATABASE bacula OWNER bacula ENCODING 'SQL_ASCII' LC_COLLATE 'C' LC_CTYPE 'C' TEMPLATE template0;
ALTER DATABASE bacula SET datestyle TO 'ISO, YMD';
    • Create tables for PostgreSQL. Just run /usr/local/share/bacula/make_postgresql_tables -U bacula.
    • If you didn't make the bacula user the owner of the bacula database, use /usr/local/share/bacula/grant_postgresql_privileges .
  • Config goes in /usr/local/etc/bacula. Create bacula-dir.conf and bacula-sd.conf.
  • Add to /etc/rc.conf:
bacula_dir_enable="YES"
bacula_fd_enable="YES"
bacula_sd_enable="YES"
  • service bacula-fd start
  • service bacula-sd start
  • service bacula-dir start

There's more to add here:

  • Suggested particulars of bacula-dir.conf and bacula-sd.conf.
  • Optimizing postgresql.conf.

Restoring

Restoring is generally obvious and easy. To accomplish bare metal restore, you need to somehow boot and run the bacula client, and instruct the director to poke the backup files onto the new disk. Generally, it something like this works:

  • Select another client machine that's running the same OS version.
  • Install the new disk as a nonroot mountpoint.
  • Command the bacula director to restore to the selected client, and to rewrite paths to the proper mountpoint. If you rewrite correctly, the files will not need to be moved after restoring.
  • Reload the boot code on the new disk. On FreeBSD, this is trivial. On Windows, it requires mysterious incantations.

Windows

After restoring the files from the backup of C: to a fresh filesystem, move the replacement disk to the disrupted machine and see Windows Boot Repair.

See Also

[1] http://www.bacula.org/7.4.x-manuals/en/main/Main_Reference.html

[2] http://www.bacula.org/7.4.x-manuals/en/problems/Bacula_Frequently_Asked_Que.html

[3] https://workaround.org/bacula-cheatsheet/

[4] http://serverfault.com/questions/371159/moving-tapes-out-of-a-bacula-pool-after-media-error

[5] https://dan.langille.org/2015/01/10/bacula-on-freebsd-with-zfs/