How to restore a single file in Bacula

I wanted to restore a single file from Bacula. I’m writing this tutorial partically to remind myself how to do this but perhaps it will help someone in the future.

You will need to do this from bconsole on your Bacula server.

1 – You need to find the filename of the file. For example: myfile.xml

2 – You then need to find the last time that this file was backed up. You can do this using the restore command:

select option 2 - list jobs of command seperated JobIDs to select
select the client - 1 
Enter file name (no path): myfile.xml

This produces a list of JobId’s and the complete path to possible files.

| JobId | Name | StartTime | JobType | JobStatus | JobFiles | JobBytes |
| 8862 | /mnt/pd/Documentation/X015/myfile.xlm | 2014-05-14 20:39:00 | B | T | 10 | 3837733 |
| 8844 | /mnt/pd/Documentation/X015/myfile.xlm | 2014-05-13 20:42:16 | B | T | 7 | 88229 |

3 – If the file appears then you can to restore from one of the selective JobId like so:

select 3 -Enter list of comma seperated JobIds to select
select the files you require by browsing around - cd / ls / add filename then done

You might need to modify the ‘where’ part of the generated job like so:

select 9
enter the full path to a restore path

Then the files or directories you have selected should be restored.

Bacula Error shell command: run AfterJob “/etc/bacula/scripts/delete_catalog_backup” Ubuntu 14.40

I have just upgraded from Ubuntu 12.04 to Ubuntu 14.04 on our Bacula backup server. Everything is backing up okay however it’s failing to delete the catalogue backup job after it has run. The error message is:

24-Apr 23:31 bacula-dir JobId 7388: shell command: run AfterJob "/etc/bacula/scripts/delete_catalog_backup"

It turns out that Ubuntu 14.04 updated the backup script /etc/bacula/scripts/delete_catalog_backup but didn’t make is excutable. I could see this by running:

ls -la /etc/bacula/scripts/

and saw:

-rw------- 1 root root   104 Apr 24 20:30 delete_catalog_backup
-rwxr-xr-x 1 root root   112 Sep  8  2012 delete_catalog_backup.ucf-old

To fix this you just need to run the following command:

sudo chmod 755 /etc/bacula/scripts/delete_catalog_backup

This should fix the issue but you can test this my:

sudo bconsole
run job=BackupCatalog"

Let me know if this works for you.

bacula-dir mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table

Our Bacula server has started failing when backing up its own database.  This is a standard job called BackupCatalog. It showed an error like so:

27-Feb 23:29 bacula-dir JobId 6545: shell command: run BeforeJob "/etc/bacula/scripts/<a href="" target="_blank">make_<wbr /></a> MyCatalog"
27-Feb 23:35 bacula-dir JobId 6545: BeforeJob: mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table `File` at row: 2164125
27-Feb 23:35 bacula-dir JobId 6545: BeforeJob: mysqldump: Couldn't execute 'show table status like 'FileSet'': MySQL server has gone away (2006)

Reading the error, it would appear to be a mysqldump problem, rather than a Bacula configuration problem. The mysqldump process was running out of resources. This was because the mysql server wasn’t configured correctly and the server didn’t have enough memory or cpu. I run Bacula on a virtual server and it was therefore quite easy to give an extra two gigs of memory and some more CPU time.

However, to fix the mysql server configuration, I adjusted the following settings in MySQL. I did this by creating a file in the /etc/mysql/conf.d/ directory called bacula.cnf with the following settings and then restarted the server.

wait_timeout = 86400

sudo service mysql restart

Install mysqltuner
You might have different mysql configuration issues and therefore have different configurations to change.  I would highly recommend mysqltuner to help you diagnose problem.  It is designed to analysis your MySQL server and recommend  options which could be changed based on your server usages.

Note: Your server needs to be running for over 24 hours before it’s recommendations are useful.  So, if you have just restarted the server, it probably won’t be very useful.

apt-get install mysqltuner

Then run:


And you get a lovely report like so. Note:  The reports shown below is for server that has only been up for 15 minutes and the recommendations can’t really be trusted.

 >>  MySQLTuner 1.0.1 - Major Hayden <>
 >>  Bug reports, feature requests, and downloads at
 >>  Run with '--help' for additional options and output filtering

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.5.35-0ubuntu0.12.04.2
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster 
[--] Data in InnoDB tables: 413M (Tables: 25)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[!!] Total fragmented tables: 25

-------- Performance Metrics -------------------------------------------------
[--] Up for: 15m 36s (24K q [26.087 qps], 56 conn, TX: 353K, RX: 4M)
[--] Reads / Writes: 0% / 100%
[--] Total buffers: 192.0M global + 2.7M per thread (151 max threads)
[OK] Maximum possible memory usage: 597.8M (10% of installed RAM)
[OK] Slow queries: 0% (0/24K)
[OK] Highest usage of available connections: 1% (3/151)
[OK] Key buffer size / total MyISAM indexes: 16.0M/98.0K
[!!] Key buffer hit rate: 80.0% (5 cached / 1 reads)
[!!] Query cache efficiency: 17.0% (29 cached / 171 selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 3 sorts)
[OK] Temporary tables created on disk: 19% (54 on disk / 275 total)
[OK] Thread cache hit rate: 94% (3 created / 56 connections)
[OK] Table cache hit rate: 24% (66 open / 273 opened)
[OK] Open file limit used: 4% (48/1K)
[OK] Table locks acquired immediately: 100% (24K immediate / 24K locks)
[!!] InnoDB data size / buffer pool: 413.7M/128.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    MySQL started within last 24 hours - recommendations may be inaccurate
    Enable the slow query log to troubleshoot bad queries
Variables to adjust:
    query_cache_limit (> 1M, or use smaller result sets)
    innodb_buffer_pool_size (>= 413M)

I recommend using Top to diagnose the load problems on your server.  For me, it was clear from the basic numbers that the server was using alot of swap and lots of cpu.

Finally, I recommend used the excellent sysstat / sar tools to see the history of the CPU and the iowait on the server.

I hope this helps someone.

How to test if Bacula-fd is running

I just installed a new Bacula client but for some reason the server could not connect to it. I found this out by trying to get the status of the client on the server with the following command:

sudo bconsole
status client=my.client-rd

Here is the things that I checked on the server.

Step 1 – Check that the service bacula-fd is started:

sudo service bacula-fd status

Step 2 – Check the bacula-fd process is bound to the port 9102

sudo netstat -an|grep 9102

Step 3 – Check that you can telnet into the client port from the server.

telnet 9102

I found the the client configuration did have the correct client ipaddress but each of these checks enabled me to narrow down the problem.