2 setlocal ENABLEDELAYEDEXPANSION
\r
5 REM Bacula interface to virtual autoloader using disk storage
\r
7 REM $Id: disk-changer.in,v 1.3 2006/07/30 16:00:32 kerns Exp $
\r
9 REM If you set in your Device resource
\r
11 REM Changer Command = "disk-changer %c %o %S %a %d"
\r
12 REM you will have the following input to this script:
\r
14 REM So Bacula will always call with all the following arguments, even though
\r
15 REM in some cases, not all are used.
\r
17 REM disk-changer "changer-device" "command" "slot" "archive-device" "drive-index"
\r
20 REM By default the autochanger has 10 Volumes and 1 Drive.
\r
22 REM Note: For this script to work, you *must" specify
\r
23 REM Device Type = File
\r
24 REM in each of the Devices associated with your AutoChanger resource.
\r
26 REM changer-device is the name of a file that overrides the default
\r
27 REM volumes and drives. It may have:
\r
28 REM maxslot=n where n is one based (default 10)
\r
29 REM maxdrive=m where m is zero based (default 1 -- i.e. 2 drives)
\r
31 REM This code can also simulate barcodes. You simply put
\r
32 REM a list of the slots and barcodes in the "base" directory/barcodes.
\r
33 REM See below for the base directory definition. Example of a
\r
35 REM C:\TEMP\bacula\barcodes
\r
40 REM archive-device is the name of the base directory where you want the
\r
41 REM Volumes stored appended with \drive0 for the first drive; \drive1
\r
42 REM for the second drive, ... For example, you might use
\r
43 REM C:\Temp\bacula\drive0 Note: you must not have a trailing slash, and
\r
44 REM the string (e.g. \drive0) must be unique, and it must not match
\r
45 REM any other part of the directory name. These restrictions could be
\r
46 REM easily removed by any clever script jockey.
\r
48 REM Full example: disk-changer C:\Temp\bacula\conf load 1 C:\Temp\bacula\drive0 0
\r
50 REM The Volumes will be created with names slot1, slot2, slot3, ... maxslot in the
\r
51 REM base directory. In the above example the base directory is C:\Temp\bacula.
\r
52 REM However, as with tapes, their Bacula Volume names will be stored inside the
\r
53 REM Volume label. In addition to the Volumes (e.g. C:\Temp\bacula\slot1,
\r
54 REM C:\Temp\bacula\slot3, ...) this script will create a C:\Temp\bacula\loadedn
\r
55 REM file to keep track of what Slot is loaded. You should not change this file.
\r
58 SET dbgfile=%CD%\disk-changer.log
\r
60 REM to turn on logging, uncomment the following line
\r
61 IF NOT EXIST %dbgfile% COPY nul %dbgfile% >nul
\r
64 REM check parameter count on commandline
\r
66 REM Check for special cases where only 2 arguments are needed,
\r
67 REM all others are a minimum of 5
\r
69 IF "%1" EQU "" goto :param_count_invalid
\r
70 IF "%2" EQU "" goto :param_count_invalid
\r
71 IF "%2" EQU "list" goto :param_count_valid
\r
72 IF "%2" EQU "slots" goto :param_count_valid
\r
73 IF "%3" EQU "" goto :param_count_invalid
\r
74 IF "%4" EQU "" goto :param_count_invalid
\r
75 IF "%5" EQU "" goto :param_count_invalid
\r
76 GOTO :param_count_valid
\r
78 :param_count_invalid
\r
79 echo Insufficient number of arguments given.
\r
81 echo At least two arguments must be specified.
\r
82 ) else echo Command expected 5 arguments.
\r
85 ECHO usage: disk-changer ctl-device command [slot archive-device drive-index]
\r
86 ECHO Valid commands are: unload, load, list, loaded, and slots.
\r
105 SET device=%device:/=\%
\r
106 SET device=%device:\\=\%
\r
108 REM Pull in conf file
\r
109 IF EXIST %ctl% CALL %ctl%
\r
111 FOR %%i IN ( %ctl% ) DO SET dirname=%%~dpi
\r
112 IF NOT EXIST %dirname%nul (
\r
113 ECHO ERROR: Autochanger directory "%dirname%" does not exist.
\r
114 ECHO You must create it.
\r
118 CALL :debug "Parms: %ctl% %cmd% %slot% %device% %drive%"
\r
119 IF "%cmd%" EQU "unload" GOTO :cmdUnload
\r
120 IF "%cmd%" EQU "load" GOTO :cmdLoad
\r
121 IF "%cmd%" EQU "list" GOTO :cmdList
\r
122 IF "%cmd%" EQU "loaded" GOTO :cmdLoaded
\r
123 IF "%cmd%" EQU "slots" GOTO :cmdSlots
\r
127 CALL :debug "Doing disk -f %ctl% unload %slot% %device% %drive%"
\r
128 IF NOT EXIST %dirname%loaded%drive% ECHO 0 >%dirname%loaded%drive%
\r
129 FOR /f %%i IN ( %dirname%loaded%drive% ) DO SET ld=%%i
\r
131 IF "%slot%" EQU "%ld%" (
\r
132 CALL :debug "Unloaded slot %ld% from drive %drive%"
\r
133 ECHO 0 >%dirname%loaded%drive%
\r
134 DEL %dirname%%device% >nul 2>nul
\r
137 ECHO Storage Element %slot% is Already Full
\r
138 CALL :debug "Storage Element %slot% is Already Full"
\r
144 CALL :debug "Doing disk -f %ctl% load %slot% %device% %drive%"
\r
146 IF NOT EXIST %dirname%loaded%drive% ECHO 0 >%dirname%loaded%drive%
\r
147 FOR /f %%i IN ( %dirname%loaded%drive% ) DO SET ld=%%i
\r
149 IF NOT EXIST %dirname%slot%slot% COPY nul %dirname%slot%slot% >nul
\r
151 fsutil hardlink create %device% %dirname%slot%slot% >nul 2>&1
\r
152 SET rtn=%ERRORLEVEL%
\r
154 ECHO %slot% >%dirname%loaded%drive%
\r
155 CALL :debug "Loaded slot %slot% into drive %drive%"
\r
157 CALL :debug "Create hardlink failed, return = !rtn!"
\r
160 ECHO Drive %drive% Full - Storage element %ld% loaded
\r
161 CALL :debug "Drive %drive% Full - Storage element %ld% loaded"
\r
166 CALL :debug "Doing disk -f %ctl% -- to list volumes"
\r
167 IF EXIST %dirname%barcodes (
\r
168 TYPE %dirname%barcodes
\r
170 FOR /l %%i IN ( 1, 1, %maxslot% ) DO ECHO %%i:
\r
176 CALL :debug "Doing disk -f %ctl% %drive% -- to find what is loaded"
\r
177 IF EXIST %dirname%loaded%drive% ( TYPE %dirname%loaded%drive% ) ELSE ECHO 0
\r
182 CALL :debug "Doing disk -f %ctl% -- to get count of slots"
\r
191 ECHO '%cmd%' is an invalid command.
\r
198 IF NOT EXIST %dbgfile% GOTO :EOF
\r
199 FOR /f "usebackq tokens=2-4,5-7 delims=/:. " %%i IN ( '%DATE% %TIME%' ) do SET TIMESTAMP=%%k%%i%%j-%%l:%%m:%%n
\r
200 ECHO %TIMESTAMP% %* >> %dbgfile%
\r