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