3 # Catch for sh/csh on systems without #! ability.
4 eval '(exit $?0)' && eval 'exec @PERL@ -S $0 ${1+"$@"}'
5 & eval 'exec @PERL@ -S $0 $argv:q'
9 # This changer script is designed for IOMEGA or JAZZ disks of various sizes
10 # as well as any other removable disk media.
12 # This is a PURELY MANUAL changer. It requests insertion of disk media via
13 # messages on /dev/tty. So it cannot be used via crontab.
15 # Make sure you comply with any of the following.
17 # tpchanger "chg-iomega"
18 # tapedev "file:<mount_point_of_removable_disk>"
19 # # (e.g. tapedev "file:/mnt/iomega" )
23 # define tapetype IOMEGA {
24 # comment "IOMega 250 MB floppys"
29 # to your /etc/amanda/<backup_set>/amanda.conf file
30 # - Add entry to /etc/fstab to specify mount point of removable disk
31 # and make this disk mountable by any user.
32 # - Format all disks, add a "data" sub directory and label all disks
33 # by a call to amlabel.
34 # - Be aware that as of version 2.4.4p1, amanda can't handle backups that are
35 # larger than the size of the removable disk media. So make sure
36 # /etc/amanda/<backup_set>/disklist specifies chunks smaller than the
39 # This script is built up out of bits and pieces of other scripts, in
40 # particular chg-chio.pl. That script was written by
41 # Nick Hibma - nick.hibma@jrc.it
43 # Permission to freely use and distribute is granted (by me and was granted by
44 # the original authors).
46 # Christoph Pospiech <pospiech@de.ibm.com>
51 ($progname = $0) =~ s#/.*/##;
56 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV', 'PATH'};
57 $ENV{'PATH'} = "/usr/bin:/usr/sbin:/sbin:/bin";
61 if (-d "@AMANDA_DBGDIR@") {
62 $logfile = "@AMANDA_DBGDIR@/changer.debug";
64 $logfile = "/dev/null";
66 die "$progname: cannot open $logfile: $ERRNO\n"
67 unless (open (LOG, ">> $logfile"));
71 # get the information from the configuration file
75 $prefix=$prefix; # avoid warnings about possible typo
76 $exec_prefix="@exec_prefix@";
77 $exec_prefix=$exec_prefix; # Ditto
79 if ( "@USE_VERSION_SUFFIXES@" eq "yes" ) {
85 chomp ($tapeDevice = `$sbindir/amgetconf$SUF tapedev 2>&1`);
86 die "tapedev not found in amanda.conf"
87 if !$tapeDevice or $tapeDevice eq "" or
88 $tapeDevice =~ m/no such parameter/;
89 chomp ($changerDevice = `$sbindir/amgetconf$SUF changerdev 2>&1`);
91 die "changerdev not found in amanda.conf"
92 if !$changerDevice or $changerDevice eq "" or
93 $changerDevice =~ m/no such parameter/;
96 # Initialise a few global variables
103 @dow = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
104 @moy = ("Jan", "Feb", "Mar", "Apr", "May", "Jun",
105 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
112 # Get the local time for the value.
115 @t = localtime (time ());
121 $r = sprintf "%s %s %2d %2d:%02d:%02d %4d",
133 my $device = shift @_;
134 my ($directory) = ($device =~ m/file\:(.*)$/);
135 if ( -d "$directory/data" ) { return 1;}
140 my $label = shift @_;
142 open (TTY, "+</dev/tty") or die "Can't open tty.\n";
143 print TTY "Insert Disk with label $label\n";
150 my $label = shift @_;
151 open (TTY, "+</dev/tty") or die "Can't open tty.\n";
152 print TTY "The current Disk has label $label\n";
157 my $device = shift @_;
158 my ($directory) = ($device =~ m/file\:(.*)$/);
159 my @dir_list = glob("$directory/data/*");
160 while ( ($_= shift(@dir_list)) ) {
161 if ( /0+\.([\w\d]+)/ ) {return $1;}
168 my $device = shift @_;
169 my ($directory) = ($device =~ m/file\:(.*)$/);
171 print LOG &do_time(), ": enter: Load $device\n";
172 if ( ! &is_mounted($device) ) {
173 print LOG &do_time(), ": mounting $directory\n";
174 system "mount $directory";
176 $label = get_label $device;
177 &print_label($label);
178 print LOG &do_time(), ": current label: $label\n";
179 print LOG &do_time(), ": leave: Load\n";
184 my $device = shift @_;
185 my ($directory) = ($device =~ m/file\:(.*)$/);
186 print LOG &do_time(), ": enter: Unload $device\n";
187 if ( &is_mounted($device) ) {
188 print LOG &do_time(), ": ejecting $directory\n";
189 system "eject $directory";
191 print LOG &do_time(), ": leave: Unload\n";
205 $opt_slot = 0; # perl -w fodder
206 $opt_info = 0; # perl -w fodder
207 $opt_reset = 0; # perl -w fodder
208 $opt_eject = 0; # perl -w fodder
209 $opt_search = 0; # perl -w fodder
210 $opt_label = 0; # perl -w fodder
212 GetOptions("slot=s", "info", "reset", "eject", "search=s", "label=s");
216 print LOG &do_time(), ": Loading slot $opt_slot requested\n";
217 if ( ! &is_mounted ($tapeDevice) ) {
221 $current_label = &get_label ($tapeDevice);
222 print LOG &do_time(), ": current label: $current_label\n";
223 print LOG &do_time(), ": 1 $tapeDevice\n";
224 print "1 $tapeDevice\n";
229 print LOG &do_time(), ": info requested\n";
230 $current_label = &get_label ($tapeDevice);
231 print LOG &do_time(), ": current label: $current_label\n";
232 print LOG &do_time(), ": 1 $max_slot 1 1\n";
233 print "1 $max_slot 1 1\n";
238 print LOG &do_time(), ": reset requested\n";
239 &Unload ($tapeDevice);
242 $current_label = &get_label ($tapeDevice);
243 print LOG &do_time(), ": current label: $current_label\n";
244 print LOG &do_time(), ": 1 $tapeDevice\n";
245 print "1 $tapeDevice\n";
250 print LOG &do_time(), ": eject requested\n";
251 &Unload ($tapeDevice);
252 print LOG &do_time(), ": 1 $tapeDevice\n";
253 print "1 $tapeDevice\n";
258 print LOG &do_time(), ": search label $opt_search requested\n";
260 $current_label = &get_label ($tapeDevice);
261 print LOG &do_time(), ": current label: $current_label\n";
262 while ( $opt_search ne $current_label && ++$retry < 5) {
263 &Unload ($tapeDevice);
264 &request ($opt_search);
266 $current_label = &get_label ($tapeDevice);
267 print LOG &do_time(), ": search label: $opt_search\n";
268 print LOG &do_time(), ": current label: $current_label\n";
271 print LOG &do_time(), ": disk not found\n";
272 print "disk not found\n";
275 print LOG &do_time(), ": 1 $tapeDevice\n";
276 print "1 $tapeDevice\n";
282 print LOG &do_time(), ": label $opt_label requested\n";
284 print LOG &do_time(), ": 1 $tapeDevice\n";
285 print "1 $tapeDevice\n";
289 print "$progname: No command was received. Exiting.\n";