2 #################################################################################
5 # Description: This script performs backups of vobs. By backup we mean that it
6 # will lock a vob then copy that vobs storage area to another area
7 # on disk then unlock the vob.
8 # Author: Andrew@DeFaria.com
9 # Created: June 23, 2004
11 # Warnings: Since we use Windows commands like xcopy this script will only
14 # (c) Copyright 2004, Andrew@DeFaria.com, all rights reserved.
16 ################################################################################
24 my $backup_loc = "d:\\backup";
25 my $history_loc = "d:\\vobstore\\backup";
26 my $from_loc = "d:\\";
27 my $vob_server = "rtnlprod01";
28 my $day_nbr = (localtime ()) [6]; # Day # of week.
37 my $start_time = shift;
42 my $seconds = $end_time - $start_time;
45 return "less than a second";
46 } elsif ($seconds eq 1) {
48 } elsif ($seconds < 60) {
49 return "$seconds seconds";
50 } elsif ($seconds < (60 * 60)) {
51 $minutes = $seconds / 60;
52 $seconds = $seconds % 60;
53 my $minutes_string = ($minutes eq 1) ? "minute" : "minutes";
54 my $seconds_string = ($seconds eq 1) ? "second" : "seconds";
55 return "$minutes $minutes_string $seconds $seconds_string";
57 $hours = $seconds / (60 * 60);
58 $seconds = $seconds % (60 * 60);
59 $minutes = $seconds / 60;
60 $seconds = $seconds % 60;
61 my $hours_string = ($hours eq 1) ? "hour" : "hours";
62 my $minutes_string = ($minutes eq 1) ? "minute" : "minutes";
63 my $seconds_string = ($seconds eq 1) ? "second" : "seconds";
64 return "$hours $hours_string $minutes $minutes_string $seconds $seconds_string";
69 print "Usage $me: [-v]";
71 print "\t-v\tVerbose\n";
78 print "$msg\n" if $verbose eq "yes";
84 print "$me: WARNING: $msg\n";
92 print "# $errno: " if defined $errno;
95 exit $errno if defined $errno;
103 my @space = `cleartool space $vob 2> NUL`;
110 ($cleartext) = split;
114 return $size - $cleartext;
124 my $return_code = system "cleartool lock vob:$_ > NUL 2>&1";
125 warning "Unable to lock vob $_" if $return_code ne 0;
126 $status += $return_code;
138 my $return_code = system "cleartool unlock vob:$_ > NUL 2>&1";
139 warning "Unable to unlock vob $_" if $return_code ne 0;
140 $status += $return_code;
147 my $vob_storage_basename = shift;
149 my $storage = "$backup_loc\\$vob_storage_basename";
150 my $old_storage_loc = "$history_loc\\$day_nbr\\$vob_storage_basename";
153 if (-e $old_storage_loc) {
154 @output = `rmdir /s /q $old_storage_loc`;
157 error "Error in removing old storage area $old_storage_loc";
158 error (join "\n", @output);
160 verbose "Removed old storage area $old_storage_loc";
164 @output = `move $storage $old_storage_loc`;
167 error "Error in moving storage area $storage to $old_storage_loc";
168 error (join "\n", @output);
170 verbose "Moved old storage $storage to $old_storage_loc";
177 my $vob_storage_basename = shift;
179 my $to = "$backup_loc\\$vob_storage_basename";
180 my $size = VobSize $vob;
182 $total_size += $size;
183 verbose "Copying $vob ($size meg) from $from -> $to";
185 my $start_time = time;
187 MoveOldStorage $vob_storage_basename if -e $to;
189 # Copy storage but exclude any file containing strings found in the
190 # d:\backup\exclude.strings file See
191 # http://www-1.ibm.com/support/docview.wss?rs=0&q1=being-deleted&uid=swg21129318&loc=en_US&cs=utf-8&cc=us&lang=en
193 my @output = `xcopy $from $to /q /e /i /h /k /x /exclude:d:\\backup\\exclude.strings`;
198 print "Error in copy of vob $vob\n";
201 verbose "Copying of $vob ($size meg) took " . Duration $start_time, $end_time;
206 while ($#ARGV >= 0) {
207 if ($ARGV [0] eq "-v") {
213 if ($ARGV [0] ne "") {
214 error "Unknown option: \"" . $ARGV [0] . "\"\n";
219 # Iterrate through the list of vobs
220 my $start_time = time;
222 my @vobs = `cleartool lsvob -short -host $vob_server 2> NUL`;
224 warning "Unable to lock all vobs" if (LockVobs @vobs) ne 0;
228 my $line = `cleartool lsvob $_ 2> NUL`;
234 if ($line =~ m/(\\\\\S*)/) {
238 $storage =~ s/\\\\$vob_server\\/$from_loc/;
240 my $vob_storage_basename = substr ($storage, rindex ($storage, "\\") + 1);
242 CopyStorage $_, $storage, $vob_storage_basename;
245 warning "Unable to unlock all vobs" if (UnlockVobs @vobs) ne 0;
249 verbose "Total of $total_size meg copied in: " . Duration $start_time, $end_time;