1 ################################################################
6 Bacula® - The Network Backup Solution
8 Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
10 The main author of Bacula is Kern Sibbald, with contributions from
11 many others, a complete list can be found in the file AUTHORS.
13 This program is Free Software; you can redistribute it and/or
14 modify it under the terms of version two of the GNU General Public
15 License as published by the Free Software Foundation plus additions
16 that are listed in the file LICENSE.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 Bacula® is a registered trademark of Kern Sibbald.
29 The licensor of Bacula is the Free Software Foundation Europe
30 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
31 Switzerland, email:ftf@fsfeurope.org.
35 package scripts::functions;
37 # Export all functions needed to be used by a simple
38 # perl -Mscripts::functions -e '' script
40 our @ISA = qw(Exporter);
41 our @EXPORT = qw(update_some_files create_many_files check_multiple_copies);
43 # open a directory and update all files
50 print "Update files in $dest\n";
51 opendir(DIR, $dest) || die "$!";
55 open(FP, ">$f") or die "$f $!";
56 print FP "$t update $f\n";
62 print "$nb files updated\n";
65 # create big number of files in a given directory
66 # Inputs: dest destination directory
67 # nb number of file to create
69 # perl -Mscripts::functions -e 'create_many_files("$cwd/files", 100000)'
77 $base = chr($nb % 26 + 65); # We use a base directory A-Z
80 if (-f "$dest/$base/a${base}a750000aaa$base") {
81 print "Files already created\n";
85 # auto flush stdout for dots
87 print "Create $nb files into $dest\n";
88 for(my $i=0; $i < 26; $i++) {
92 for(my $i=0; $i<=$nb; $i++) {
93 $base = chr($i % 26 + 65);
94 open(FP, ">$dest/$base/a${base}a${i}aaa$base") or die "$dest/$base $!";
98 open(FP, ">$dir/b${base}a${i}csq$base") or die "$dir $!";
99 print FP "$base $i\n";
103 $dir = "$dest/$base/$base$i$base";
106 print "." if (!($i % 10000));
111 # This test ensure that 'list copies' displays only each copy one time
113 # Input: read stream from stdin or with file list argument
114 # check the number of copies with the ARGV[1]
115 # Output: exit(1) if something goes wrong and print error
116 sub check_multiple_copies
118 my ($nb_to_found) = @_;
120 my $in_list_copies=0; # are we or not in a list copies block
121 my $nb_found=0; # count the number of copies found
125 while (my $l = <>) # read all files to check
127 if ($l =~ /list copies/) {
133 # not in a list copies anymore
134 if ($in_list_copies && $l =~ /^ /) {
140 # | 3 | Backup.2009-09-28 | 9 | DiskChangerMedia |
141 if ($in_list_copies && $l =~ /^\|\s+\d+/) {
142 my (undef, $jobid, undef, $copyid, undef) = split(/\s*\|\s*/, $l);
143 if (exists $seen{$jobid}) {
144 print "ERROR: $jobid/$copyid already known as $seen{$jobid}\n";
147 $seen{$jobid}=$copyid;
153 # test the number of copies against the given arg
154 if ($nb_to_found && ($nb_to_found != $nb_found)) {
155 print "ERROR: Found wrong number of copies ",
156 "($nb_to_found != $nb_found)\n";