5 =head1 NAME $RCSfile: clearadmscrub.pl,v $
15 Andrew DeFaria <Andrew@ClearSCM.com>
23 Sun Jan 2 19:40:28 EST 2011
27 $Date: 2012/11/09 06:45:36 $
33 Usage clearadmscrub.pl: [-u|sage] [-ve|rbose] [-deb|ug]
36 -u|sage: Displays usage
39 -deb|ug: Output debug messages
43 This script will scrub all old records in the Clearadm database
54 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
62 my $VERSION = '$Revision: 1.9 $';
63 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
65 my $clearadm = Clearadm->new;
70 scrubdays => $Clearadm::CLEAROPTS{CLEARADM_SCRUBDAYS}
76 'usage' => sub { Usage },
77 'verbose' => sub { set_verbose },
78 'debug' => sub { set_debug },
80 ) or Usage "Invalid parameter";
82 Usage 'Extraneous options: ' . join ' ', @ARGV if @ARGV;
85 verbose "$FindBin::Script V$VERSION";
89 for my $system ($clearadm->FindSystem($host)) {
90 ($err, $msg) = $clearadm->TrimLoadavg($system->{name});
92 if ($msg eq 'Records deleted' or $msg eq '') {
93 verbose "Scrub loadavg $system->{name}: $err $msg:";
98 for my $filesystem ($clearadm->FindFilesystem($system->{name}, $fs)) {
99 ($err, $msg) = $clearadm->TrimFS($system->{name}, $filesystem->{filesystem});
101 if ($msg eq 'Records deleted' or $msg eq '') {
102 verbose "Scrub filesystem $system->{name}:$filesystem->{filesystem}: $err $msg";
109 my $scrubdate = SubtractDays(Today2SQLDatetime, $opts{scrubdays});
113 started => Today2SQLDatetime,
114 system => hostname(),
117 # Scrub view and vob storage records
118 for ($clearadm->FindVob) {
119 ($err, $msg) = $clearadm->TrimStorage('vob', $_->{tag}, $_->{region});
121 if ($msg eq 'Records deleted' or $msg eq '') {
122 verbose "Scub VOB $_->{tag} $err $msg";
128 for ($clearadm->FindView) {
129 ($err, $msg) = $clearadm->TrimStorage('view', $_->{tag}, $_->{region});
131 if ($msg eq 'Records deleted' or $msg eq '') {
132 verbose "Scub View $_->{tag} $err $msg";
138 # Make sure the Clearcase objects we have in Clearadm are still valid
139 my ($views, $vobs) = $clearadm->ValidateCCObjects;
141 if ($vobs !~ /^\d+/) {
142 error "Unable to validate Clearcase objects: $vobs", $views;
146 $runlog{message} = "Deleted $views views\n" if $views;
147 $runlog{message} .= "Deleted $vobs vobs" if $vobs;
149 $clearadm->AddRunlog(%runlog);
152 # Scrub old alertlogs
153 ($runlog{status}, $runlog{message}) =
154 $clearadm->DeleteAlertlog ("timestamp<='$scrubdate'");
156 verbose "$runlog{task} alertlog: $runlog{status} $runlog{message}";
158 $clearadm->AddRunlog (%runlog);
160 $runlog{started} = Today2SQLDatetime;
163 ($runlog{status}, $runlog{message}) =
164 $clearadm->DeleteRunlog ("started<='$scrubdate'");
166 verbose "$runlog{task} runlog: $runlog{status} $runlog{message}";
168 $clearadm->AddRunlog(%runlog);
172 =head1 CONFIGURATION AND ENVIRONMENT
174 DEBUG: If set then $debug is set to this level.
176 VERBOSE: If set then $verbose is set to this level.
178 TRACE: If set then $trace is set to this level.
186 L<Getopt::Long|Getopt::Long>
188 =head2 ClearSCM Perl Modules
203 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
204 <a href="http://clearscm.com/php/scm_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
205 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
206 <a href="http://clearscm.com/php/scm_man.php?file=lib/TimeUtils.pm">TimeUtils</a><br>
207 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
212 =head1 BUGS AND LIMITATIONS
214 There are no known bugs in this script
216 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
218 =head1 LICENSE AND COPYRIGHT
220 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.