Hi,
Keith Edmunds wrote on 14.05.2007 at 00:00:33 [[BackupPC-users] API for full
size?]:
> Is there a way for a script to retrieve the "Full Size/GB" as reported on
> the Host Summary page?
yes, as the Host Summary page does :-). See BackupPC::CGI::Summary.
Setting XEmacs to quick-hack-mode, I get something like this:
-*- quick-hack -*-
#!/usr/bin/perl
use strict;
use lib '/usr/share/backuppc/lib'; # adapt to match your installation
use BackupPC::Lib;
my $hostname = shift
or die "Usage: $0 <hostname>\n";
my $bpc = new BackupPC::Lib
or die "Can't create BackupPC object!\n";
my @backups = $bpc -> BackupInfoRead ($hostname)
or die "Invalid hostname '$hostname' or other error!\n";
for (my $i = @backups - 1; $i >= 0; $i --) {
if ($backups [$i] {type} eq 'full') {
printf "%.2f\n", $backups [$i] {size} / 1024 / 1024 / 1000;
last;
}
}
-*- /quick-hack -*-
Note that
- you need to run that as the backuppc user for access to the information,
- you only get the number as output, formatted as in the host summary page,
- the number is in units of "1000 MB", where 1 MB is 2^20 Bytes - I don't
know if I've seen *that* definition of "GB" somewhere before ;-),
- no error checking, no guarantees etc.
> I want to write a script that checks that users
> haven't exceeded their backup quota.
If you want to iterate over all hosts belonging to one user, look at
GetUserHosts in BackupPC::CGI::Lib ...
-*- quick-hack -*-
$hostinfo = $bpc -> HostInfoRead ();
@hosts = sort grep { $hostinfo -> {$_} {user} eq $user ||
$hostinfo -> {$_} {moreUsers} =~ /(?:^|,)$user(?:,|$)/ }
keys %$hostinfo;
-*- /quick-hack -*-
(you might consider "belonging to one user" to mean to leave out the
moreUsers check).
Regards,
Holger
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
BackupPC-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/backuppc-users
http://backuppc.sourceforge.net/