Bacula-users

Re: [Bacula-users] How to get free hard disk space back ?

2012-04-19 17:32:26
Subject: Re: [Bacula-users] How to get free hard disk space back ?
From: Phil Stracchino <alaric AT metrocast DOT net>
To: bacula-users AT lists.sourceforge DOT net
Date: Thu, 19 Apr 2012 17:30:41 -0400
On 04/19/2012 05:04 PM, Jerome Alet wrote:
> On Thu, Apr 19, 2012 at 10:11:20AM -0400, Josh Fisher wrote:
>>
>> Changing the "action on purge" for the pool does not change it for the
>> old volumes that were created before the change was made. You have to
>> individually update the action on purge for each of those old volumes.
> 
> Sorry I didn't mention it but I did this with :
> 
>       UPDATE media SET actiononpurge=1;
> 
> But still no volume is truncated excepted at recycle time, when possible
> (in our case not possible anymore for our Full storage pool).
> 
> Since all storage pools are on the same disk partition, despite the
> Differential and Incremental storage pools having hundreds (they are
> small) of "dead" volumes, Full backups still can't happen because
> there's not a single recyclable volume in the Full storage pool.
> 
> Any other idea ?

I gather you are creating a new volume for every job, and never reusing
the old ones.  So write a simple shell script that will connect to the
bacula DB, select VolumeName from Media where VolStatus = 'Purged', save
the list of volume names, and delete them from the disk.

What I do:  All disk volumes have   RecyclePool = Scratch
Then I run this admin job once a week:


Job {
  Name = "Clean Expired Volumes"
  Type = Admin
  Enabled = Yes
  Pool = Scratch
  FileSet = Dummy
  Storage = babylon4-file
  Client = babylon4
  Level = Full
  RunBeforeJob = "/opt/bacula/sbin/clean_volumes -v"
  Rerun Failed Levels = yes
  Messages = Daemon
  Priority = 20
  Allow Duplicate Jobs = no
  Cancel Queued Duplicates = yes
  Schedule = "Volume Cleanup"
}


/opt/bacula/sbin/clean_volumes:

#!/usr/bin/perl
use strict;
use Getopt::Long;
use IPC::Open2;
use IO::Handle;


my $bconsole = '/opt/bacula/bin/bconsole';
my (%opts, @purged, $pid);

GetOptions(\%opts,
           'verbose|v',
           'test');

my ($IN, $OUT) = (IO::Handle->new(), IO::Handle->new());

$pid = open2($OUT, $IN, $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, CDK#2     DoD#299792458     ICBM: 43.5607, -71.355
  alaric AT caerllewys DOT net   alaric AT metrocast DOT net   phil AT 
co.ordinate DOT org
  Renaissance Man, Unix ronin, Perl hacker, SQL wrangler, Free Stater
                 It's not the years, it's the mileage.

------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users