/
dudl-dbstatus
97 lines (66 loc) · 1.72 KB
/
dudl-dbstatus
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/perl -w
# $Id: dudl-dbstatus,v 1.6 2008-12-28 11:39:22 bj Exp $
#
# Copyright (c) 2008 Rainer Clasen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms described in the file LICENSE included in this
# distribution.
#
use strict;
use Dudl::DB;
use Getopt::Long;
my $wanthelp;
my $needhelp;
if( ! GetOptions(
"help|h!" => \$wanthelp,
)){
$needhelp++;
}
if( $wanthelp ){
print <<EOF;
usage: $0 <opt>
show some Database statistics
options:
--help this short usage information.
EOF
exit 0;
}
if( $needhelp ){
print STDERR "use --help for usage info\n";
exit 1;
}
=pod
=head1 NAME
dudl-dbstatus - show some Database statistics
=head1 DESCRIPTION
This script shows some statistics for the Dudl Database. The output is
split into 3 columns:
=over 4
=item 1
Description.
=item 2
Number.
=item 3
Size in GigaByte.
=back
=head1 SEE ALSO
I<Dudl::Overview>
=head1 AUTHOR
Rainer Clasen
=cut
my $dudl = new Dudl::DB;
my $db = $dudl->db;
# TODO: move database access to module
&col( "units", "SELECT COUNT(*),0 FROM stor_unit");
&col( "sl units", "SELECT max(colnum),0 FROM stor_unit WHERE collection='sl'");
&col( "files all", "SELECT COUNT(*),SUM(fsize)/1073741824 FROM stor_file");
&col( "files intact", "SELECT COUNT(*),SUM(fsize)/1073741824 FROM stor_file WHERE NOT broken");
&col( "albums", "SELECT COUNT(*),0 FROM mus_album");
&col( "titles all", "SELECT COUNT(*),SUM(fsize)/1073741824 FROM stor_file WHERE album_id NOTNULL");
&col( "titles nontmp", "SELECT COUNT(*),SUM(fsize)/1073741824 FROM stor_file WHERE album_id > 0");
sub col {
my( $desc, $query ) = @_;
my( $num, $sz ) = $db->selectrow_array( $query );
printf "%-15s %15d %15d\n", $desc, $num, $sz;
}