Re: How to run bconsole commands in a bash for loop?

Rob Gerber <[email protected]>
Newsgroups gmane.comp.bacula.user
Message-ID <CAMKi9mTt0s=fp0rZ0F_rD=tkNPRhDT4iHp=tY5+TCE_MMnKH5g@mail.gmail.com>
The following is my rocky Linux, bacula community 15.0.2 "how to delete all
bacula volumes and reset a bacula installation" runbook. It's been
customized for my specific environment. My bacula was installed from the
bacula community repositories, so bacula was installed in /opt/bacula/.

You will need to customize some of this to match the actual paths on your
system.

Runbook starts:
# This document discusses how to reset a bacula installation, post or
during the testing phase.
# All local volumes will be deleted.
# The entire database will be dropped.
# HERE BE DRAGONS
# HERE BE DRAGONS
# HERE BE DRAGONS
# HERE BE DRAGONS
# HERE BE DRAGONS
# HERE BE DRAGONS


# as root:

# Stop bacula.
/usr/sbin/bacula stop

# print every volume file and folder that will be deleted
find /mnt/synology/bacula/* -mindepth 1 -print

# flip this on its head and see what folders will remain.
find /mnt/synology/bacula/* -maxdepth 0 -print

# Now, to actually delete all those files
# THERE WILL BE NO PROMPTING OR TAKEBACKSIES
#find /mnt/synology/bacula/* -mindepth 1 -delete


# Log into Backblaze B2 and delete any cloud volumes. Make sure object
lifecycle is set to keep previous versions of objects for max 1 day.
# alternately, you can use cyberduck or something, but the B2 volume file
browser might be more thorough.

# delete any bacula storage volume encryption keys in
/opt/bacula/etc/keydir.
# YOU WILL NOT BE ABLE TO DECRYPT ANY CLOUD VOLUMES WITHOUT THESE KEYS
#rm -f /opt/bacula/etc/keydir/*



# Drop the bacula database and then re-create it:

# As postgres:
su - postgres

# drop the bacula tables.
# we could drop the whole database, but I think we'd have to set the
password again.
# dropping tables should be enough.

/opt/bacula/scripts/drop_bacula_tables

# re-create the tables and grant permissions.
# /opt/bacula/scripts/create_postgresql_database # shouldn't need this,
since we didn't drop the database.
/opt/bacula/scripts/make_postgresql_tables
/opt/bacula/scripts/grant_postgresql_privileges
# you may see a message "psql:<stdin>:2: ERROR: role "bacula" already
exists". This seems to be fine and reasonable.


exit

# restart bacula and get status
systemctl start bacula-dir bacula-sd bacula-fd
/usr/sbin/bacula status

# should be done!
# please note this didn't delete any cloud volumes.
# that is easy enough to do in cyberduck.
# dear god, why isn't there a suitable GUI S3 browser for linux?


Robert Gerber
402-237-8692
[email protected]

On Tue, Sep 16, 2025, 12:04 PM Gary Dale <[email protected]> wrote:

> Internet searches have been futile. The ones that actually mention
> bconsole suggest what I've been trying to do should work, but it doesn't.
>
> Through my initial setup struggles, my storage volumes have become a
> disjointed mess. To make matters worse, there are close to a hundred
> volumes showing "Error" when I "List Volumes". I have only about 20 that
> show up as physical disk volumes. And automatic volume creation seems to
> be failing. All my backups for the last 5 days have failed.
>
> To fix this, I'm trying to go back to the start (without purging and
> reinstalling bacula) by removing everything to date. However, I can't do
> that for the volumes - way to many of them. So I'm trying to run a bash
> script to cycle through them to purge them.
>
> I've found multiple answers that suggest using a bash for loop then
> doing something like:
>          echo "purge volume ${volname} yes" | bconsole  - where $volname
> is created by the for loop -
> should work. And it does actually to a point. It will invoke the "purge
> volume" dialogue then asks which pool to use. Inserting the pool number
> after the volume command (e.g. echo "purge volume 2 ${volname} yes" |
> bconsole) doesn't work either. Nor does inserting \n into the echoed
> command at various points.
>
> Being able to put bconsole commands into a bash script seems like
> something that will be generally useful but I can't find a way to make
> it work.
>
> Any ideas?
>
>
>
> _______________________________________________
> Bacula-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bacula-users
>

_______________________________________________
Bacula-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bacula-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.