Bacula
From NBSWiki
Contents |
bacula
Bacula is a powerful backup solution but the documentation criss-crosses between versions. Here are some of my notes to help sort out specific situations (when things go wrong):
- Don't use SQLight, use MySQL or PostgreSQL
- Don't use SQLight,
- ...you get the point
Here is why, although you CAN plan the DB size requirements, you don't know how your users will use the filesystem, in my case, we ended up with more than 7M files (current figure is closer to 3M), which represented an impressive load for the database. We ended up with a (corrupted) 5GB database which still sized up to 2.6GB after performing maintenance. Also, the official bacula site recomends using a more robust DB backend.
Migrating from SQLight to MySQL
Eventually, we will use PostgreSQL, but the urgency of the situation requires a quick and dirty solution (most probably why SQLight was used in the first place...). This is a specific case wehere we want to migrate from sqlight to mysql AND upgrade from 2.4.1 to 3.0.2 (under [www.gentoo.org Gentoo]. The scripts are written to handle vresions upgrades within the same DB framework. This means we will first migrate to the new DB _then_ upgrade versions. As always these are telegraphic notes, the official doc is here but won't give you much more.
While using 2.4.1
Some operations have to be performed using the installed version (with SQLight as DB). We will first perform some agressive maintenance as follows.
Compact DB
This takes a while...
cd /var/lib/bacula/ echo '.dump' | sqlite bacula.db > bacula.sql && rm bacula.db && sqlite bacula.db < bacula.sql
Index and check the DB
After fsking around for a long time, we figured out there were no indexes created by default so we will create them as per the SQLite Indexes from bacula's site.
sqlite /var/lib/bacula/bacula.db CREATE INDEX file_jobid_idx on File (JobId); CREATE INDEX file_jfp_idx on File (JobId, FilenameId, PathId);
This will take some time but is _really_ worth it. We never got dbcheck to finish without the indexes (even after 12hrs). With the indexing, which took less than 1hr, dbcheck did eventually finish in a reasonnable time (between 2-3hrs).
dbcheck -b -f -c /etc/bacula/bacula-dir.conf
This will clean up the database.
Dumped and prepare the database for MySQL
We dump it once more:
echo '.dump' | sqlite bacula.db > bacula.sqlite.sql
There is a SQLite to MySQL migration script in the source's examples/database folder which does exactly the following:
cat bacula.sqlite.sql |
awk '/^INSERT INTO / && $3 != "NextId" && $3 != "Version" { print $0 }' |
sed '/^INSERT INTO [a-zA-Z]* VALUES(/s/(NULL)/(0)/g ; /^INSERT INTO [a-zA-Z]* VALUES(/s/(NULL,/(0,/g ; /^INSERT INTO [a-zA-Z]* VALUES(/s/,NULL,/,0,/g ; /^INSERT INTO [a-zA-Z]* VALUES(/s/,NULL,/,0,/g ; /^INSERT INTO [a-zA-Z]* VALUES(/s/,NULL)/,0)/g' > bacula.mysql.sql
This cleans up the SQL query, we have noticed less errors but many remained during the import (in our case).
Create the MySQL database
Recompile bacula to use MySQL.
All utility scripts are in /usr/libexec/bacula/, we will assume you've already set up MySQL and know the root password for it (we suppress prompt and output for copy-pastability):
./create_mysql_database -u root -p ./make_mysql_tables -u root -p ./grant_mysql_privileges -u root -p
We now set the password for the bacula user:
mysql -u root -p
SET PASSWORD FOR 'bacula'@'%' = PASSWORD('le_mot_de_pAsse');
SET PASSWORD FOR 'bacula'@'localhost' = PASSWORD('le_mot_de_pAsse');
Populate the MySQL database and creatre indexes
mysql -u bacula -p -f bacula < /var/lib/bacula/bacula.mysql.sql
You will get many errors, aparently they can be ignored...
We make sure the indexes exist, we checked and they were there.
mysql bacula -p show index from File; +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | File | 0 | PRIMARY | 1 | FileId | A | 10534459 | NULL | NULL | | BTREE | | | File | 1 | JobId | 1 | JobId | A | NULL | NULL | NULL | | BTREE | | | File | 1 | JobId | 2 | PathId | A | NULL | NULL | NULL | | BTREE | | | File | 1 | JobId | 3 | FilenameId | A | NULL | NULL | NULL | | BTREE | | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
Check the MySQL database
Given the errors we got during the import, we call dbcheck once more, being recompiled for MySQL, bacula accesses the correct DB (given the correct config file too).
dbcheck -b -f -c /etc/bacula/bacula-dir.conf
...Errors were still found and corrected by this additional pass.
