Big update of Clearadm
[clearscm.git] / clearadm / updateccfs.pl
1 #!/usr/local/bin/perl
2
3 =pod
4
5 =head1 NAME $RCSfile: updateccstorage.pl,v $
6
7 Update Filesystem
8
9 =head1 VERSION
10
11 =over
12
13 =item Author
14
15 Andrew DeFaria <Andrew@ClearSCM.com>
16
17 =item Revision
18
19 $Revision: 1.29 $
20
21 =item Created:
22
23 Mon Dec 13 09:13:27 EST 2010
24
25 =item Modified:
26
27 $Date: 2011/06/16 15:12:50 $
28
29 =back
30
31 =head1 SYNOPSIS
32
33  Usage updateccstorage.pl: [-u|sage] [-ve|rbose] [-deb|ug]
34                            [-view [<tag>|all]| -vob [<tag>|all]]
35
36  Where:
37    -u|sage:     Displays usage
38  
39    -ve|rbose:   Be verbose
40    -deb|ug:     Output debug messages
41    
42    -view [<tag>|all]      Update view storage (Default: all)
43    -vob  [<tag>|all]      Update vob storage (Default: all)
44    -region [<region>|all] Update region (Default: all)
45
46 =head1 DESCRIPTION
47
48 This script will record the state of Clearcase storage
49
50 =cut
51
52 use strict;
53 use warnings;
54
55 use FindBin;
56 use Getopt::Long;
57
58 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
59
60 use Clearadm;
61 use Clearexec;
62 use Clearcase::Views;
63 use Clearcase::View;
64 use Clearcase::Vobs;
65 use Clearcase::Vob;
66 use DateUtils;
67 use Display;
68 use Utils;
69
70 my $VERSION  = '$Revision: 1.29 $';
71   ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
72
73 my $clearadm = Clearadm->new;
74
75 # Given a view tag, snapshot the storage sizes
76 sub snapshotViewStorage($$) {
77   my ($tag, $region) = @_;
78
79   my %viewstorage = (
80     tag    => $tag,
81     region => $region,
82   );
83
84   my $view = Clearcase::View->new($tag, $region);
85   
86   $viewstorage{private} = $view->viewPrivateStorage;
87   $viewstorage{db}      = $view->viewDatabase;
88   $viewstorage{admin}   = $view->viewAdmin;
89   $viewstorage{total}   = $view->viewSpace;
90
91   my ($err, $msg) = $clearadm->AddViewStorage(%viewstorage);
92
93   error $msg, $err if $err;
94 } # snapshotVobStorage
95
96 # Given a vob tag, snapshot the storage sizes
97 sub snapshotVobStorage($$) {
98   my ($tag, $region) = @_;
99
100   my %vobstorage = (
101     tag    => $tag,
102     region => $region,
103   );
104
105   my $vob = Clearcase::Vob->new($tag, $region);
106
107   $vobstorage{admin}      = $vob->admsize;
108   $vobstorage{db}         = $vob->dbsize;
109   $vobstorage{cleartext}  = $vob->ctsize;
110   $vobstorage{derivedobj} = $vob->dosize;
111   $vobstorage{source}     = $vob->srcsize;
112   $vobstorage{total}      = $vob->size;
113
114   my ($err, $msg) = $clearadm->AddVobStorage(%vobstorage);
115
116   error $msg, $err, if $err;
117 } # snapshotVobStorage
118
119 my %opts;
120
121 # Main
122 GetOptions (
123   \%opts,
124   'usage'   => sub { Usage },
125   'verbose' => sub { set_verbose },
126   'debug'   => sub { set_debug },
127   'view=s',
128   'vob=s',
129   'region=s',
130 ) or Usage "Invalid parameter";
131
132 Usage 'Extraneous options: ' . join ' ', @ARGV if @ARGV;
133
134 unless ($opts{view} or $opts{vob}) {
135   $opts{view} = 'all';
136   $opts{vob}  = 'all';
137 } # unless
138
139 $opts{region} ||= 'all';
140
141 # Announce ourselves
142 verbose "$FindBin::Script V$VERSION";
143
144 if ($opts{view} and $opts{view} =~ /all/i) {
145   if ($opts{region} =~ /all/i) {
146     for my $region ($Clearcase::CC->regions) {
147       my $views = Clearcase::Views->new($region);
148
149       for my $view ($views->views) {
150         verbose "Snapshotting view $view in region $region";
151
152         snapshotViewStorage $view, $region;
153       } # for
154     } # for
155   } else {
156     my $views = Clearcase::Views->new($opts{region});
157
158     for my $view ($views->views) {
159       verbose "Snapshotting view $view in region $opts{region}";
160
161       snapshotViewStorage $view, $opts{region};
162     } # for
163   } # if
164 } elsif ($opts{view}) {
165   if ($opts{region} =~ /all/i) {
166     for my $region ($Clearcase::CC->regions) {
167       verbose "Snapshotting view $opts{view} in region $region";
168
169       snapshotViewStorage $opts{view}, $region;
170     } # for
171   } else {
172     verbose "Snapshotting view $opts{view} in region $opts{region}";
173
174     snapshotViewStorage $opts{view}, $opts{region};
175   } # if
176 } # if
177
178 if ($opts{vob} and $opts{vob} =~ /all/i) {
179   if ($opts{region} =~ /all/i) {
180     for my $region ($Clearcase::CC->regions) {
181       my $vobs = Clearcase::Vobs->new(undef, $region);
182
183       for my $vob ($vobs->vobs) {
184         verbose "Snapshotting vob $vob in region $region";
185
186         snapshotVobStorage $vob, $region;
187       } # for
188     } # for
189   } else {
190     my $vobs = Clearcase::Vobs->new(undef, $opts{region});
191
192     for my $vob ($vobs->vobs) {
193       verbose "Snapshotting vob $vob in region $opts{region}";
194       
195       snapshotVobStorage $vob, $opts{region};
196     } # for
197   } # if
198 } elsif ($opts{vob}) {
199   if ($opts{region} =~ /all/i) {
200     for my $region ($Clearcase::CC->regions) {
201       verbose "Snapshotting view $opts{vob} in region $region";
202
203       snapshotVobStorage $opts{vob}, $region;
204     } # for
205   } else {
206     verbose "Snapshotting vob $opts{vob} in region $opts{region}";
207
208     snapshotVobStorage $opts{vob}, $opts{region};
209   } # if
210 } # if
211
212 =pod
213
214 =head1 CONFIGURATION AND ENVIRONMENT
215
216 DEBUG: If set then $debug is set to this level.
217
218 VERBOSE: If set then $verbose is set to this level.
219
220 TRACE: If set then $trace is set to this level.
221
222 =head1 DEPENDENCIES
223
224 =head2 Perl Modules
225
226 L<FindBin>
227
228 L<Getopt::Long|Getopt::Long>
229
230 L<Net::Domain|Net::Domain>
231
232 =head2 ClearSCM Perl Modules
233
234 =begin man 
235
236  Clearadm
237  Clearexec
238  DateUtils
239  Display
240  Utils
241
242 =end man
243
244 =begin html
245
246 <blockquote>
247 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
248 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearcase/Vobs.pm">Clearcase::Vobs</a><br>
249 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearcase/Vobs.pm">Clearcase::Vob</a><br>
250 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearcase/Views.pm">Clearcase::Views</a><br>
251 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearcase/View.pm">Clearcase::View</a><br>
252 <a href="http://clearscm.com/php/scm_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
253 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
254 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
255 </blockquote>
256
257 =end html
258
259 =head1 BUGS AND LIMITATIONS
260
261 There are no known bugs in this script
262
263 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
264
265 =head1 LICENSE AND COPYRIGHT
266
267 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.
268
269 =cut