Bacula-users

Re: [Bacula-users] Remove purged disk volumes

2011-10-31 12:29:34
Subject: Re: [Bacula-users] Remove purged disk volumes
From: Phil Stracchino <alaric AT metrocast DOT net>
To: bacula-users AT lists.sourceforge DOT net
Date: Mon, 31 Oct 2011 12:26:30 -0400
> On 10/31/2011 3:16 AM, Lyn Amery wrote:
>> A previous poster to this list mentioned that he moved purged disk
>> volumes/files to a scratch pool.  Periodically, anything located in
>> his scratch pool is deleted.  Is this a good procedure?  How would I
>> go about it?  Where would I define the scratch pool?

Lyn,
Here's how I have it set up.

First, the Pools.  Notice that every pool has unlimited volumes,
unlimited jobs per volume, but has a volume use duration of 23h forcing
a new volume each day per pool.  All the Pools autolabel their volumes
by date, and all recycle into Scratch.


Pool {
  Name = Scratch
  Storage = babylon4-file
  Pool Type = Backup
}

Pool {
  Name = VirtualFull
  Storage = babylon4-virtual
  Pool Type = Backup
  Recycle = no
  Recycle Oldest Volume = no
  Recycle Current Volume = no
  AutoPrune = yes                     # Prune expired volumes
  Volume Retention = 2 months
  Maximum Volume Jobs = 1
  Label Format =
"VIRTUAL-$Year${Month:p/2/0/r}${Day:p/2/0/r}-${Hour:p/2/0/r}:${Minute:p/2/0/r}-$Client"
  RecyclePool = Scratch
}

Pool {
  Name = Full-Disk
  Storage = babylon4-file
  Pool Type = Backup
  Recycle = no
  Recycle Oldest Volume = no
  Recycle Current Volume = no
  AutoPrune = yes                     # Prune expired volumes
  Volume Retention = 2 months
  Maximum Volume Jobs = 0
  Volume Use Duration = 23h
  Label Format =
"FULL-$Year${Month:p/2/0/r}${Day:p/2/0/r}-${Hour:p/2/0/r}:${Minute:p/2/0/r}"
  RecyclePool = Scratch
  NextPool = VirtualFull
}

Pool {
  Name = Diff-Disk
  Storage = babylon4-file
  Pool Type = Backup
  Recycle = no
  Recycle Oldest Volume = no
  Recycle Current Volume = no
  AutoPrune = yes
  Volume Retention = 2 months
  Maximum Volume Jobs = 0
  Volume Use Duration = 23h
  Label Format =
"DIFF-$Year${Month:p/2/0/r}${Day:p/2/0/r}-${Hour:p/2/0/r}:${Minute:p/2/0/r}"
  RecyclePool = Scratch
  NextPool = VirtualFull
}

Pool {
  Name = Incr-Disk
  Storage = babylon4-file
  Pool Type = Backup
  Recycle = no
  Recycle Oldest Volume = no
  Recycle Current Volume = no
  AutoPrune = yes
  Volume Retention = 1 month
  Maximum Volume Jobs = 0
  Volume Use Duration = 23h
  Label Format =
"INCR-$Year${Month:p/2/0/r}${Day:p/2/0/r}-${Hour:p/2/0/r}:${Minute:p/2/0/r}"
  RecyclePool = Scratch
  NextPool = VirtualFull
}



So, once purged volumes are in scratch, you need a periodic admin job to
clear them out.  Mine looks like this:



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"
}


And this is the Perl script that it runs:


#!/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.

------------------------------------------------------------------------------
Get your Android app more play: Bring it to the BlackBerry PlayBook 
in minutes. BlackBerry App World&#153; now supports Android&#153; Apps 
for the BlackBerry&reg; PlayBook&#153;. Discover just how easy and simple 
it is! http://p.sf.net/sfu/android-dev2dev
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users

<Prev in Thread] Current Thread [Next in Thread>