Bacula-users

Re: [Bacula-users] Switch Volume at end of month

2014-09-15 13:10:46
Subject: Re: [Bacula-users] Switch Volume at end of month
From: Andrea Conti <alyf AT alyf DOT net>
To: bacula-users AT lists.sourceforge DOT net
Date: Mon, 15 Sep 2014 18:37:40 +0200
Hello,
> I will probably do this using an Admin Job, but I am unsure how to write
> a command for the update to happen.
> I don't have much experience with Unix scripting.

In order to update the status of a volume you can either pipe an update
command through bconsole or access the database directly.

Personally I find that going through bconsole, while technically
cleaner, is extremely cumbersome (mainly because it is not that easy to
find out exactly which volumes you need to update without doing a lot of
output parsing and possibily even some queries), so I went the database way.

Just to give you an idea, this is what I use in my setup in order to
manually rotate the active volume in my pools at the beginning of every
month:

--------------------
Job {
  Name = "MarkDiskVolumeUsed"
  JobDefs = "DefaultJob"
  Type = "Admin"
  FileSet = "Catalog"
  Schedule = "sched.MF.00"
  RunBeforeJob = "/usr/libexec/bacula/mark_disk_volumes_used <db_name>
<db_user> <db_passwd>"
  Priority = 1
}
--------------------


The "sched.MF.00" schedule is such that this job is run at the
*beginning* of the month, immediately before any backup jobs that will
write to one of the affected pools. I find it easier this way than to
run at the end of the month, as it is easier to predict the start time
than the end time of backup jobs; however either can be done by choosing
the right schedule and priority relative to your backup jobs.

This is the "mark_disk_volumes_used" script:

--------------------
#!/bin/sh

if [ $# -lt 3 ]; then
    echo "Usage: $0 <dbname> <dbuser> <dbpassword>"
    exit
fi

for pool in <list_of_pools>; do
    STATEMENT="update media set volstatus='Full' where poolid=(select
poolid from pool where name='${pool}') and volstatus='Append' and
voljobs > 0 and volbytes > 5000000000;"
    echo "${STATEMENT}" | PGPASSWORD="$3" psql -U $2 $1 -f -
done
--------------------

It will take the database connection parameters on the command line and
will set every volume in 'Append' status within one of the pools listed
in <list_of_pools> and with at least 5GB of written data to 'Full'.

The filter on the volume size is there so that you can have more than
one appendable volume within each pool (either because of preallocation
or auto-recycling), but only the one which has actually been used for
backups will be marked full; you may need to adjust the amount based
upon your installation and backup schedule.

The script above is for a postgreSQL database; if you are using
something else you will have to update the next-to-last line with the
appropriate command to execute a given query with the right user
credentials.

HTH,
andrea

> 
> Regards,
> 
> Florian S.
> 
> Am 15.09.2014 um 14:00 schrieb Ana Emília M. Arruda:
>> Hi Florian,
>>
>> Maybe you could run an Admin Job for "update volume" status from
>> append to used when the last day of the month is reached?
>>
>> Regards,
>> Ana
>>
>> On Mon, Sep 15, 2014 at 3:40 AM, Florian <florian.splett AT web DOT de
>> <mailto:florian.splett AT web DOT de>> wrote:
>>
>>     Hello.
>>
>>     I would like to use a Volume for the duration of one month and
>>     after the
>>     last backup of a month, I want to change the status of the Volume to
>>     "Used" or "Full".
>>     I use the Volumes this long to have all Backup-Data from one monthly
>>     cycle in one file.
>>
>>     I figured out how to check, if it is the last day of the month,
>>     but I am
>>     not sure how to automatically change the status of the specific Volume
>>     that has been used till then.
>>
>>     Any suggestions are appreciated.
>>
>>     Regards,
>>
>>     Florian S.


------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users