Wednesday, 2 September 2009

Reset Bacula database and files


Today I need to purge my bacula for several reasons.

Here is how I did.

First backup the database and files used in your previous setup, one never knows you might actually need it after the purge...

/usr/bin/mysqldump -aecqQ bacula > bacula_before_purge.sql


and copy the volumes and bsr files.


Stop bacula :

service bacula-director stop
service bacula-fd       stop
service bacula-sd       stop


then :

mysql -u root -p
drop database bacula;
create database bacula;
quit


next we need to recreate bacula tables. There's a bacula script to do that, but the file needs to be changed to set the correct database name.

cp /usr/share/bacula-director/make_mysql_tables ~/
vi ~/make_mysql_tables

change XXX_DBNAME_XXX by your bacula database (let's say 'bacula')
save and exit.

then run as root the script
~/make_mysql_tables


it should have recreated the tables :
mysql -u root -p
use bacula;
show tables;
+------------------+
| Tables_in_bacula |
+------------------+
| BaseFiles        |
| CDImages         |
| Client           |
| Counters         |
| Device           |
| File             |
| FileSet          |
| Filename         |
| Job              |
| JobMedia         |
| Location         |
| LocationLog      |
| Log              |
| Media            |
| MediaType        |
| Path             |
| Pool             |
| Status           |
| Storage          |
| UnsavedFiles     |
| Version          |
+------------------+
21 rows in set (0.00 sec)
quit


next you need to delete the existing volume and bsr files.
In my case I just change the location of the bacup (bacula-sd.conf 'Archive Device')

restart your bacula services and run a job to check everything is OK.
service bacula-director start
service bacula-fd       start
service bacula-sd       start 


Image from http://www.everaldo.com/

9 comments:

Jonah Dorman said...

Thanks. You saved me a lot of trouble.

Randall Mauriel said...

How do I save and exit after "vi ~/make_mysql_tables"???

Thanks!!!

Manson Thomas said...

type
Escape key
then

:wq

which mean write & quit

ⒶⓉⓎ ⒹⒺ ⒶⒾⒹⒺⓃ said...

After changing XXX_DBNAME_XXX to 'bacula' and when I enter command : ~/make_mysql_tables
I get an error message as below

/root/make_mysql_tables: 11: /root/make_mysql_tables: Bad substitution

Any solution??

Manson Thomas said...

double check your file I guess...

Honestly, it's been quite a while since I've done this setup (and You're probably using a newer version right ?)... So I guess I won't be very useful.

Subscribe to the bacula user mailing list, and ask for help there ;)

Randall Mauriel said...

Thanks Manson Thomas, in the future I will use nano :D

Manson Thomas said...

hehe ;)

vi is a good tool, but I understand that it's a bit confusing ;)

Dave said...

Very helpful.... One additional tidbit: if you have used a bacula-specific MySQL user account (in the Catalog configuration of bacula-dir.conf), don't forget to grant that user all privileges on the newly re-created bacula database! Not doing this causes a silent failure in startup of the director...

Jeff Brown said...

I found this tonight (in July 2016) and it still works, mostly. Running the "make_mysql_tables" script produced a couple of error messages, but still finished with a "successful" message. And Bacula started up with no complaints and a clean catalog. I'm running a Ubuntu 14 / Zentyal (eBox) 4.2 server; recently upgraded from a Zentyal 3.5 system. And was using Bacula prior to that (since 2009, I think). Still hard to find tidbits like this regarding Bacula, and it really helps for those of us who only know enough to be dangerous, so thanks much for posting the procedure.