On 8/5/21 3:36 PM, Robert Earl wrote:
> Hi folks,
> I have a large number of abandoned volumes with no data, no associated
> file, and haven't been written in years. I believe they are the obstacle
> to automatic labeling of new volumes; my Maximum Volumes for this pool
> is 120.
>
> Alarmingly, I just found a "Full" volume whose mtime is April 9, 2021
> but Baculum's "Last Written" record is Feb. 28, 2019.
>
> I also have 10 old volumes that are outdated and I can purge/recycle.
>
> I am looking at batch-processing a large number of volumes, though, so
> this is unwieldy through the GUI, and I'm dense on the niceties of
> bconsole. What would be the procedure for a set of mass operations like
> this from a script/command line?
Robert,
You might try something like the following example. This configuration
sets all purged volumes to be automatically moved into the Scratch pool,
then the Job "Clean Expired Volumes" periodically invokes the
clean_volumes script in order to scan the Scratch pool, delete the
volumes from the catalog, and delete the physical files from disk.
Pool {
Name = Scratch
Pool Type = Backup
}
Pool {
Name = Full-Disk
...
RecyclePool = Scratch
}
Pool {
Name = Diff-Disk
...
RecyclePool = Scratch
}
[and so on]
Job {
Name = "Clean Expired Volumes"
Type = Admin
Enabled = Yes
Pool = Scratch
Storage = asgard-file
FileSet = Dummy
Client = asgard
Level = Full
RunBeforeJob = "/etc/bacula/clean_volumes -v"
Messages = Daemon
Priority = 20
Rerun Failed Levels = yes
Allow Duplicate Jobs = no
Cancel Queued Duplicates = yes
Schedule = "Volume Cleanup"
}
#!/usr/bin/perl
use strict;
use Getopt::Long;
use IPC::Open2;
use IO::Handle;
my $bconsole = '/usr/sbin/bconsole';
my (%opts, @purged, $pid);
GetOptions(\%opts,
'verbose|v',
'test');
my ($IN, $OUT) = (IO::Handle->new(), IO::Handle->new());
$pid = open2($OUT, $IN, $bconsole) || die "Unable to open bconsole";
if (scalar (@purged = check_volumes()))
{
printf("Bacula reports the following purged volumes:\n\t%s\n",
join("\n\t", @purged)) if ($opts{verbose});
my $deleted = delete_volumes(@purged);
print "$deleted volumes deleted.\n" if ($opts{verbose});
}
elsif ($opts{verbose})
{
print "No purged volumes found to delete.\n";
}
print $IN "exit\n";
waitpid($pid, 0);
exit (0);
sub check_volumes
{
my $dividers = 0;
my (@purged, @row);
print $IN "list volumes pool=Scratch\n";
for (;;)
{
my $resp = <$OUT>;
last if ($resp =~ /No results to list./);
$dividers++ if ($resp =~ /^[\+\-]+$/);
last if ($dividers == 3);
@row = split(/\s+/, $resp);
push (@purged, $row[3]) if ($row[5] eq 'Purged');
}
return (@purged);
}
sub delete_volumes
{
my $volume_dir = '/spool/bacula/';
my $count = 0;
foreach my $vol (@_)
{
my $l;
my $file = $volume_dir.$vol;
print "Deleting volume $vol from catalog ... " if ($opts{verbose});
print $IN "delete volume=$vol yes\n";
$l = <$OUT>;
$l = <$OUT>;
print "Done.\nDeleting volume $file from disk ... " if
($opts{verbose});
if (-f $file)
{
$count++;
unlink ($file);
}
print "Done.\n" if ($opts{verbose});
}
return ($count);
}
--
Phil Stracchino
Babylon Communications
ph...@caerllewys.net
p...@co.ordinate.org
Landline: +1.603.293.8485
Mobile: +1.603.998.6958
___
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users