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
80 chomp ($tapeDevice = `$sbindir/amgetconf tapedev 2>&1`);
81 die "tapedev not found in amanda.conf"
82 if !$tapeDevice or $tapeDevice eq "" or
83 $tapeDevice =~ m/no such parameter/;
84 chomp ($changerDevice = `$sbindir/amgetconf changerdev 2>&1`);
86 die "changerdev not found in amanda.conf"
87 if !$changerDevice or $changerDevice eq "" or
88 $changerDevice =~ m/no such parameter/;
91 # Initialise a few global variables
98 @dow = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
99 @moy = ("Jan", "Feb", "Mar", "Apr", "May", "Jun",
100 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
107 # Get the local time for the value.
110 @t = localtime (time ());
116 $r = sprintf "%s %s %2d %2d:%02d:%02d %4d",
128 my $device = shift @_;
129 my ($directory) = ($device =~ m/file\:(.*)$/);
130 if ( -d "$directory/data" ) { return 1;}
135 my $label = shift @_;
137 open (TTY, "+</dev/tty") or die "Can't open tty.\n";
138 print TTY "Insert Disk with label $label\n";
145 my $label = shift @_;
146 open (TTY, "+</dev/tty") or die "Can't open tty.\n";
147 print TTY "The current Disk has label $label\n";
152 my $device = shift @_;
153 my ($directory) = ($device =~ m/file\:(.*)$/);
154 my @dir_list = glob("$directory/data/*");
155 while ( ($_= shift(@dir_list)) ) {
156 if ( /0+\.([\w\d]+)/ ) {return $1;}
163 my $device = shift @_;
164 my ($directory) = ($device =~ m/file\:(.*)$/);
166 print LOG &do_time(), ": enter: Load $device\n";
167 if ( ! &is_mounted($device) ) {
168 print LOG &do_time(), ": mounting $directory\n";
169 system "mount $directory";
171 $label = get_label $device;
172 &print_label($label);
173 print LOG &do_time(), ": current label: $label\n";
174 print LOG &do_time(), ": leave: Load\n";
179 my $device = shift @_;
180 my ($directory) = ($device =~ m/file\:(.*)$/);
181 print LOG &do_time(), ": enter: Unload $device\n";
182 if ( &is_mounted($device) ) {
183 print LOG &do_time(), ": ejecting $directory\n";
184 system "eject $directory";
186 print LOG &do_time(), ": leave: Unload\n";
200 $opt_slot = 0; # perl -w fodder
201 $opt_info = 0; # perl -w fodder
202 $opt_reset = 0; # perl -w fodder
203 $opt_eject = 0; # perl -w fodder
204 $opt_search = 0; # perl -w fodder
205 $opt_label = 0; # perl -w fodder
207 GetOptions("slot=s", "info", "reset", "eject", "search=s", "label=s");
211 print LOG &do_time(), ": Loading slot $opt_slot requested\n";
212 if ( ! &is_mounted ($tapeDevice) ) {
216 $current_label = &get_label ($tapeDevice);
217 print LOG &do_time(), ": current label: $current_label\n";
218 print LOG &do_time(), ": 1 $tapeDevice\n";
219 print "1 $tapeDevice\n";
224 print LOG &do_time(), ": info requested\n";
225 $current_label = &get_label ($tapeDevice);
226 print LOG &do_time(), ": current label: $current_label\n";
227 print LOG &do_time(), ": 1 $max_slot 1 1\n";
228 print "1 $max_slot 1 1\n";
233 print LOG &do_time(), ": reset requested\n";
234 &Unload ($tapeDevice);
237 $current_label = &get_label ($tapeDevice);
238 print LOG &do_time(), ": current label: $current_label\n";
239 print LOG &do_time(), ": 1 $tapeDevice\n";
240 print "1 $tapeDevice\n";
245 print LOG &do_time(), ": eject requested\n";
246 &Unload ($tapeDevice);
247 print LOG &do_time(), ": 1 $tapeDevice\n";
248 print "1 $tapeDevice\n";
253 print LOG &do_time(), ": search label $opt_search requested\n";
255 $current_label = &get_label ($tapeDevice);
256 print LOG &do_time(), ": current label: $current_label\n";
257 while ( $opt_search ne $current_label && ++$retry < 5) {
258 &Unload ($tapeDevice);
259 &request ($opt_search);
261 $current_label = &get_label ($tapeDevice);
262 print LOG &do_time(), ": search label: $opt_search\n";
263 print LOG &do_time(), ": current label: $current_label\n";
266 print LOG &do_time(), ": disk not found\n";
267 print "disk not found\n";
270 print LOG &do_time(), ": 1 $tapeDevice\n";
271 print "1 $tapeDevice\n";
277 print LOG &do_time(), ": label $opt_label requested\n";
279 print LOG &do_time(), ": 1 $tapeDevice\n";
280 print "1 $tapeDevice\n";
284 print "$progname: No command was received. Exiting.\n";