home *** CD-ROM | disk | FTP | other *** search
Wrap
:: ------------------------------------------------------------------ : BKUP.BTM, version 12, May 20, 1995 : -- Read BKUP.DOC for detailed description, or type BKUP H : -- Call BKUP.INI to modify defaults. :: ------------------------------------------------------------------ : This is the main BKUP batch. See BKUP.LST for a full list. :: ------------------------------------------------------------------ : Itamar Even-Zohar (itamarez@plato.tau.ac.il) :: ------------------------------------------------------------------ :2help :: (displays HELP if you type H, ?, or /?, or I) iff %@index[%1,h] eq 0 .or. %@index[%1,?] ge 0 .or. %@index[%1,i] eq 0 then call bk-hlp.btm %1 endiff iff %_4ver lt 5 then cls beep screen 2 0 text This version of BKUP does not support 4DOS version 4.x. Please use previous versions. endtext cancel endiff setlocal set args=%1& gosub bk-prams :: (checks and sets various parameters) :ex_choice :: (if x or -x specified, the extraction part will work) iff %@index[%1,x] ge 0 .and. %@index[%1,x] lt 2 then goto extract_f endiff gosub check_args :: (defining drives for opeations if not defined elsewhere) :check_compu :: (checking computer's "name") if "%compuname"=="" gosub compuname ::goto set_params :get_date :: (separates typed date from -s or s ["since"] in date) iff %@index[%1,/s] ge 0 .or. %@index[%1,-s] ge 0 then set date0=%@substr[%1,2] goto set_defaults elseiff %@index[%1,s] eq 0 then set date0=%@substr[%1,1] goto set_defaults else goto compu_date endiff :compu_date set days=%@date[%_date] : This is today'y date in full numbers since 1-1-1980 set date0=%@makedate[%@eval[%days-%1]] : This is the actual date desired for the archive file. : If no number of days indicated by user, you get today's : date again. if %@index[%date0,0] eq 0 set date0=%@substr[%date0,1] : If a zero (0) is contained on the first position (01, etc.), : it will be removed. :set_defaults :: (setting: temporary archive name, final archive name; :: removing: old temporary archive; verifying: colors for message) :: set rsp=%temp%upd.rsp set zipfn=%temp%upd.%zip_ext set tmpf=%@unique[%temp] if exist %zipfn del /q %zipfn :: (This is just a precaution; this file is moved anyway, if batch :: terminates in a normal way.) if .%colordir==. set colordir=dirs:bright white;zip uc:black on white; :re-use? :: (Use again the updates file or create a new one?) cls if exist %rsp goto ask goto accumulate :ask :: (use extant list of updates or create a new one?) echo. gosub legenda screen 2 0 inkey /K"YNVESQ" Use extant list file? (created %@filedate[%rsp], at %@filetime[%rsp])? [time now: %_time]n (List File is: %@upper[%rsp])nnType Y/N, V(iew), S(creen), E(dit), or Q(uit) %%rep iff %rep == Q then cls^screen 2 0^set ech=echo Stopped by user^ goto end elseiff %rep == Y then goto backup elseiff %rep == V then *list %rsp^cls^goto ask elseiff %rep == E then %edt %rsp^goto backup elseiff %rep == S then echo. >%tmpf^cls^set num=0^goto edit elseiff %rep == N goto accumulate endiff :accumulate cls iff %_monitor == mono then screen 4 5 [ making a list of all new files created since %date0 ] screen 3 5 Working ... else scrput 4 5 gre on whi [ making a list of all new files created since %date0 ] scrput 3 5 blu on whi Working ... endiff :make_list :: (Create the updates file with 4DOS internal dir /d command :: [valid only from version 5.x]) cdd %search_drive:\ dir /bsa:a /[d%date0] >%rsp :check_list iff %@lines[%rsp] lt 0 then set ech=scrput 3 17 bri whi on bla No files were found for/since %date0! del /q %rsp goto end endiff scrput 3 17 bri whi on bla List created as %@upper[%rsp] :edit? screen 6 5 Select an option (press first letter): screen 7 5 text Screen select files on screen (one file after another) (this option allows viewing and deleting) Edit edit results file via editor View view results before making any decision Go go to immediate archiving (no selection) Quit stop now (results file will remain intact) endtext screen 16 3 inkey /K"SEQGV[ESC][Enter]" Your choice? %%rep iff %rep == G then goto backup elseiff %rep == S .or. %rep == @28 then echo. >%tmpf cls set num=0 goto edit elseiff %rep == E then %edt %rsp goto backup elseiff %rep == V then *list %rsp cls^goto edit? elseiff %rep == Q .or. %rep == %@char[27] then set ech=echo Stopped by user^goto end endiff :edit rem This procedure displays all the files saved today, one by one, : allowing you to (a) select only those you wish to back up, or : (b) delete, or (c) view a file before making a decision, or : (d) view the list of selections, or (e) stop selecting and go : to immediate archiving, or (f) quit. : iff %@eval[%num] gt %@lines[%rsp] then move /q %tmpf %rsp goto backup endiff set fn=%@line[%rsp,%num] if .%fn==. (set num=%@eval[%num+1]^goto edit) scrput 0 0 black on white Accept=A/enter Omit=O/Esc D=Delete V=View G=Begin archiving L=View list Q=Quit echo. iff %_row lt 2 then screen 2 0 endiff echo ==`>` %fn iff %_row ge %@eval[%_rows -1] then cls goto edit^endiff inkey /K"YNAODVGLQ[ESC][Enter]" A(ccept)? O(mit)? D(elete)? V(iew)? G(o)? (L)ist Q(uit)? %%rep iff %rep == %@char[27] .or. %rep == O .or. %rep == N then set num=%@eval[%num +1] goto edit :REM: see label ':note' below elseiff %rep == A .or. %rep == @28 .or. %rep == Y then echo %fn >>%tmpf set num=%@eval[%num +1] goto edit elseiff %rep == D then del /q %fn echo ==`>` %fn deleted^echo. set num=%@eval[%num +1] goto edit elseiff %rep == V then *list %fn echo.^goto edit elseiff %rep == G then set num=%@eval[%@lines[%rsp]+1] goto edit elseiff %rep == L then *list %tmpf echo.^goto edit elseiff %rep == Q then set ech=echo Stopped by user^goto end endiff :backup cdd %temp rem (Checking if there are any file at all to back up) gosub void :update rem (If zip archive exists on target diskette, update it) cls^echo.^echo. gosub check_drive iff exist %dr:\%date0.%zip_ext then set fn=%dr:\%date0.%zip_ext set state=old :: (The following 2 lines are just to remind the reader of parameters :: set up in BKUP.INI.) :: if "%zip_pgm"=="zip" set pkz=zip -uk -b%temp -9 :: if "%zip_pgm"=="pkzip" set pkz=pkzip -b%temp -P -u -ex cls screen 2 0 gosub void if "%zip_pgm"=="zip" set pkz=%pkz %dr:\%date0.%zip_ext -@ `<`%rsp %exclude `>&>`nul if "%zip_pgm"=="pkzip" set pkz=%pkz %exclude %dr:\%date0.%zip_ext @%rsp if "%zip_pgm"=="uc" set pkz=%pkz %dr:\%date0.%zip_ext @%rsp %exclude :: (execute compression now) %pkz gosub success goto end endiff :create_zip cls screen 2 0 gosub void if "%zip_pgm"=="zip" set pkz=%pkz %zipfn -@ `<`%rsp %exclude `>&>`nul if "%zip_pgm"=="pkzip" set pkz=%pkz %exclude %zipfn @%rsp if "%zip_pgm"=="uc" set pkz=%pkz %zipfn @%rsp %exclude :: :: (execute compression now) %pkz gosub success :check_room rem (Checking if there is room for backup file on target) iff %@diskfree[%dr:,b] lt %@filesize[%zipfn,b] then set ech=Echo No room on drive %@upper[%dr:]! %zipfn was left on %temp goto end else set ech=echo Backup archive created on drive %@upper[%dr:] endiff :move_zip gosub check_drive move /q %zipfn %dr:\%date0.%zip_ext set brand=upd set fn=%dr:\%date0.%zip_ext gosub brand :end if exist %tmpf del /q %tmpf if exist %excls_file del /q %excls_file echo. %ech echo. iff %@index[%ech,Stopped] ge 0 then goto interrupt elseiff %@index[%ech,No new] ge 0 then goto interrupt elseiff %@index[%ech,No files we] ge 0 then goto interrupt elseiff %@index[%ech,could not be] ge 0 then goto interrupt endiff if exist %dr:\%date0.%zip_ext dir /klm %dr:\%date0.%zip_ext echo. if .%integrity==.yes gosub integrity :interrupt endlocal quit ::*===========End of archiving part===================*:: ::*===========Begin extraction part===================*:: :extract_f :: Since version 8, a menu will pop up even if the archive diskette :: contains only one archive (zip) file. This will allow canceling :: extraction (by ESC). If you prefer the older procedure, you will :: have to add one more preliminary step before "select...". :set_extr_drive gosub check_args_x cdd %archive_drive:\ cdd %toupdate_drive:\ if not exist %archive_drive:*-?*-??.%zip_ext goto failure :set_names set drv=%toupdate_drive if .%compuname != %@label[%drv:] set compuname=%@lower[%@label[%drv]] :extract set fnt=%@unique[%temp%] select /d dir /km >>%fnt (%archive_drive:*-?*-??.%zip_ext) set count=%@lines[%fnt] : :select_file cls cdd %toupdate_drive:\ set num=-1 :operate :: This procedure was written with the help of Sam Wilson :: (SAM.WILSON@emerald.com), 9 Jan 1994, to whom I am deeply :: grateful. The procedure replaces a previous one, with @select, :: which allowed file selection only one by one. :: set num=%@eval[%num+1] set fn=%@line[%fnt,%num] if .%fn==.**EOF** goto end_x set fn=%archive_drive:%@substr[%fn,0,15] cls scrput 1 0 bla on whi Extracting now NEW files from %fn to Drive %toupdate_drive: rem (change colors ['bla on whi'] to suit your preference) screen 2 0 if %@index[%@descript[%fn],Extracted] ge 0 gosub continue? if "%zip_pgm"=="zip" set unz=unzip -d -uo %fn %exclude `>&>`nul if "%zip_pgm"=="pkzip" set unz=pkunzip -d -n %exclude %fn `>&>`nul if "%zip_pgm"=="uc" set unz=uc es /f %fn %exclude ##\ `>&>`nul :do_extract %unz gosub success_x goto operate :failure echo. echo No backup files found on drive %archive_drive: endlocal quit :end_x del /q %fnt if exist %excls_file del /q %excls_file endlocal cls quit :===========End of the extraction part================== :==================SUB-ROUTINES========================= ::(1)----sub-routines for the archiving part------------ :legenda screen 17 0 text Y == extant list will immediately be used for archiving N == a new list of files will be generated V == the extant list will be viewed, then you can make decision E == the list will be called by an editor S == the list will be called to screen, one file after the other Q == quit endtext drawbox 16 0 23 73 1 whi on bla return :------------------------------------------------------- :check_drive iff %@ready[%dr:] eq 0 then echo Insert diskette to Drive %@upper[%dr:], and pause endiff if exist %@search[upname.btm] call upname :: ("upname.btm" checks if your updates disk has got a "name") return :------------------------------------------------------ :success if .%zip_pgm == .zip .or. .%zip_pgm == .pkzip goto _zip if .%zip_pgm == .uc goto _uc :_uc iff errorlevel eq 0 then if .%state==.old (set brand=upd^gosub brand) set ech=echo Backup archive updated on drive %@upper[%dr:] return elseiff errorlevel eq 160 .or. errorlevel eq 165 then set ech=echo No memory for UC2 to work goto end else set ech= goto end endiff :_zip rem Checking results of archiving (with pkzip) iff errorlevel eq 12 then set ech=Echo (No new or updated files have been created) elseiff errorlevel eq 4 then cls set ech=screen 1 2 (No memory for ZIP to create updates archive) goto end elseiff errorlevel ge 4 .and. errorlevel le 11 then set ech=Echo (Backup archive could not be created / updated) goto end elseiff errorlevel ge 20 then set ech=Echo (Backup archive could not be created / updated) goto end else if .%state==.old (set brand=upd^gosub brand) set ech=echo Backup archive updated on drive %@upper[%dr:] endiff return :integrity : (Checking archive's integrity if requested) echo. echo ==> Checking archive's integrity. . . if .%zip_pgm==.zip unzip -t %dr:\%date0.%zip_ext if .%zip_pgm==.pkzip pkunzip -t %dr:\%date0.%zip_ext if .%zip_pgm==.uc uc -t %dr:\%date0.%zip_ext return :----------------------------------------------------------- :--------sub-sub-routine for marking a file----------------- : This sub-routine is designed to handle marking files. To save space, : it handles both "Updated..", and "Extracted" descriptions. This can : be implemented if the different formulas are first saved on variables. :brand iff .%brand==.upd then set mark1=Updated set mark2=Updated from: set mark3=Extracted elseiff .%brand==.ext then set mark1=Extracted set mark2=Extracted to: set mark3=Updated endiff set dscr=%@descript[%fn] if "%dscr"=="" goto 1st_desc iff %@word[0,%dscr] eq %mark3 .or. "%brand" eq "upd" then set %dscr= goto 1st_desc endiff iff %@word[0,%dscr] eq %mark1 then goto add_compu endiff :add_compu if .%compuname==. (describe %fn "%dscr; %mark1; "^return) describe %fn "%dscr %compuname; " return :1st_desc iff .%compuname==. then describe %fn "%mark1; " return else describe %fn "%mark2 %compuname; " return endiff :----subroutine for checking if archive be updated---- :void iff %@lines[%rsp] lt 0 .or. %@lines[%rsp] le 0 .and. %@len[%@line[%rsp,0]] lt 1 then set ech=scrput %@eval[%_row+1] 2 bri whi on bla No files were found /selected to back up! echo. del /q %rsp goto end else return endiff ::(2)-----------SUB-ROUTINES FOR THE EXTRACTION PART----- :success_x iff "%zip_pgm"=="zip" then :: (There is a problem with ZIP errorlevel; it does not work) set checkerror=iff errorlevel gt 0 .and. errorlevel lt 9 then elseiff "%zip_pgm"=="pkzip" then set checkerror=iff errorlevel gt 10 .and. errorlevel lt 12 then elseiff "%zip_pgm"=="uc" then set checkerror=iff errorlevel lt 0 then endiff %checkerror echo (No NEW files found for extracting in %fn) ::if %count ge 0 (echo Press any key to continue...^pause>nul) delay 2 else :ok_x echo All NEW files from %fn extracted to %toupdate_drive: set brand=ext gosub brand endiff return :continue? iff %@index[%@descript[%fn],%compuname] ge 0 then goto force? else return endiff :force? set rsp=Q inkey /W4 /K"EDQ" File %@upper[%fn] already extracted. E(xtract), D(elete), Q(uit)? %%rsp if %rsp == E return if %rsp == Q (echo Forced extraction canceled^goto operate) if %rsp == D (del /q %fn^echo File %fn deleted^goto operate) :-----------SUBROUTINES FOR DRIVE CHECKING----------- ::(1)-------archiving part--------------- :check_args iff %@eval[%#] eq 0 then gosub defaults goto start_program elseiff %@eval[%#] eq 1 then goto check_1 elseiff %@eval[%#] eq 2 then goto check_2 elseiff %@eval[%#] ge 3 then goto check_3 endiff :ask_drives inkey Search Drive (letter only)? %%search_drive inkey Archive Drive (letter only)? %%archive_drive return :check_1 iff not %@index[%1,:] ge 0 then gosub defaults goto start_program else echo Only one drive specified! gosub ask_drives shift goto start_program endiff :check_2 iff %@index[%1,:] ge 0 .xor. %@index[%2,:] ge 0 then gosub ask_drives shift 1 goto start_program else set search_drive=%1 set archive_drive=%2 shift 2 goto start_program endiff :check_3 set search_drive=%1 set archive_drive=%2 shift 2 :start_program :: (Eliminate "/zip", "/pkz" or "uc" from the arguments passed on) iff %@index[%1,/pkz] ge 0 .or. %@index[%1,/zip] ge 0 .or. %@index[%1,/uc] ge 0 then shift 1 endiff :: (Eliminate "/x" from the arguments passed on) iff %@index[%1,/x] ge 0 then shift 1000 endiff :: (Eliminate "/int" or "noint" from the arguments passed on) iff %@index[%1,/int] ge 0 .or. %@index[%1,/noint] ge 0 then shift 1 endiff :drives :: (eliminate colon from drive names) set dr=%archive_drive iff %@index[%dr,:] eq 1 then set dr=%@substr[%dr,1,-1] endiff iff %@index[%search_drive,:] eq 1 then set search_drive=%@substr[%search_drive,1,-1] endiff return rem (return to the beginning of updating) ::(2)-------extraction part--------------- :check_args_x shift iff %@eval[%#] eq 0 then gosub defaults_x goto start_ext elseiff %@eval[%#] eq 1 then goto check_1_x elseiff %@eval[%#] ge 2 then goto check_2_x endiff :ask_drives_x inkey Drive to extract to (letter only)? %%toupdate_drive inkey Drive to extract from (letter only)? %%archive_drive return :check_1_x iff not %@index[%1,:] ge 0 then gosub defaults_x goto start_ext else echo Only one drive specified! gosub ask_drives_x shift goto start_ext endiff :check_2_x iff %@index[%1,:] ge 0 .xor. %@index[%2,:] ge 0 then gosub ask_drives_x shift 1 goto start_ext else set toupdate_drive=%@substr[%1,1,-1] set archive_drive=%@substr[%2,1,-1] shift 2 goto start_ext endiff :start_ext :: (Eliminate "/zip" or "/pkz" or "/uc" from the arguments passed on) iff %@index[%1,/pkz] ge 0 .or. %@index[%1,/zip] ge 0 .or. %@index[%1,/uc] ge 0 then shift 1 endiff :drives_x :: (eliminate colon from drive names) iff %@index[%archive_drive,:] eq 1 then set archive_drive=%@substr[%archive_drive,1,-1] elseiff %@index[%toupdate_drive,:] eq 1 then set toupdate_drive=%@substr[%toupdate_drive,1,-1] endiff return rem (go back to the beginning of extraction) ::=========================================== :----sub-sub-routines to 'checking drives'--- ::=========================================== :: (setting default drives for compression and extraction. :: These defaults can be overridden via BKUP.INI, or from :: the command line.) :defaults if .%search_drive ==. set search_drive=%_boot if .%archive_drive==. set archive_drive=B: return :defaults_x if .%toupdate_drive==. set toupdate_drive=%_boot if .%archive_drive ==. set archive_drive=B return :=============END of SUB-ROUTINES============ ::-------------------------------------------:: :: EVALUATION OF PARAMETERS AND OPTIONS :: ::-------------------------------------------:: :bk-prams :check_batches :: (look for batch files used by BKUP) iff not exist %@search[bk-hlp.btm] then beep^echo BK-HLP.BTM not found. It is needed for BKUP to work echo (See BKUP.LST for details.) cancel elseiff not exist %@search[settemp.btm] then beep^echo SETTEMP.BTM not found. It is needed for BKUP to work echo (See BKUP.LST for details.) cancel elseiff not exist %@search[upname.btm] then beep^echo UPNAME.BTM not found. It is needed for BKUP to work echo (See BKUP.LST for details.) cancel endiff call settemp :: ("settemp.btm" determines which drive will be defined as "temp", :: if it is not yet defined by user [preferably in AUTOEXEC.BAT file].) :load_ini :: (loads configuration file) if exist %@search[bkup.ini] set /r %@search[bkup.ini] :set_params :: :(1)zip_pgm :: (compressions pgm: Free ZIP/UNZIP, Katz's PKZIP/PKUNZIP, or UC2) :: (/pkz, /zip, or /uc on the command line will select PKZIP, ZIP, or UC2 :: respectively. Default [below, :defaultzip] is PKZIP.) iff %@index[%args,/pkz] ge 0 then set zip_pgm=pkzip set zip_ext=zip elseiff %@index[%args,/zip] ge 0 then set zip_pgm=zip set zip_ext=zip elseiff %@index[%args,/uc] ge 0 then set zip_pgm=uc set zip_ext=uc2 elseiff .%zip_pgm==. then :defaultzip :: (Modify default below if desired) set zip_pgm=pkzip set zip_ext=zip endiff :set_prams iff "%zip_pgm"=="zip" then iff %@eval[%@dosmem[k]] lt 600 then beep echo No memory for compression with %@upper[%zip_pgm] cancel endiff set zip_ext=zip set pkz=zip -uk -9 -b %temp elseiff "%zip_pgm"=="pkzip" then set zip_ext=zip set pkz=pkzip -b%temp -P -u -ex elseiff "%zip_pgm"=="uc" then set zip_ext=uc2 set pkz=uc a -## -f iff %@eval[%@dosmem[k]] lt 400 then ::us.exe ::set pkz=uuc a -## -f beep echo No memory for compression with %@upper[%zip_pgm] cancel endiff endiff :(2)exclude_list :: (files not to be included in update archives or not to be extracted :: from the archive. The filenames are read from BKUP.INI, but this can :: be overridden by the /x switch on the command line. :: iff %@index[%args,/x] ge 0 then set exc=%@eval[%@index[%args,/x]+2] set excludes=%@substr[%args,%exc] goto an_excludes elseiff not "%excludes"=="" then goto an_excludes endiff :an_excludes set lenexc=%@len[%excludes] iff "%zip_pgm"=="zip" then set exclude=-x goto parse_excludes elseiff "%zip_pgm"=="pkzip" .or. "%zip_pgm"=="uc" then set exclude= goto parse_excludes endiff :parse_excludes if %_4ver lt 5 goto 4ver_loop set num=0 do forever set wo=%@word[%num,%excludes] if "%wo"=="" leave set num=%@eval[%num+1] gosub cmpr_pgm enddo goto check_type :4ver_loop call bk-4ver.btm parse_exclude4 :check_type if %lenexc ge 54 set excl_file=on if .%excl_file==.on gosub mark_excl :(3)editor :: (if not defined in ini file) if not "%editor"=="" set edt=%editor if "%edt"=="" INPUT No editor defined. Type your preferred editor's name: %%edt :(4)integrity :: (Check if integrity checking was requested / overridden on :: the command line) if %@index[%args,/int] ge 0 set integrity=yes if %@index[%args,/noint] ge 0 set integrity=no return :: (return to main program) ::===========SUB-ROUTINES FOR PARAMETERS=========== ::---sub-routine for checking computer "name"------ :compuname :: (temporarily naming your computer if not named yet) if "%@label[%search_drive]"=="" goto give_name set compuname=%@label[%search_drive] return :give_name cls screen 2 2 Your BKUP.INI file is missing and your search drive screen 3 2 (currently %search_drive%:) has no label. screen 4 2 inkey /K"YN" Give it a (temporary) name now? (Y/N) %%rep iff %rep == Y then goto name2 elseiff %rep == N then return endiff :name2 input Type the name you wish to call your computer: %%compuname inkey /K"YN" Read how to make it permanent? (Y/N) %%rep iff %rep == Y then set compu=on^call bk-hlp name_text^return elseiff %rep == N then return endiff ::----------end of "name" sub-routine--------- ::----------sub-routine for recomposing------- :cmpr_pgm ::-----sub-routine to recompose the components :: of the exclusion line according to the syntax :: of each compression program supported. iff %lenexc ge 54 .and. .%zip_pgm==.pkzip .or. .%zip_pgm==.uc then gosub excl_file elseiff %lenexc ge 54 .and. .%zip_pgm==.zip then echo You must reduce your exclude line by %@eval[%lenexc-53] characters echo (It is currently %lenexc) cancel endiff if .%excl_file==.on return iff .%zip_pgm==.pkzip then set exclude=%exclude -x%wo return elseiff .%zip_pgm==.zip then set exclude=%exclude \%wo return elseiff .%zip_pgm==.uc then set exclude=%exclude !%wo return endiff :: Note (April 29, 1994): exclude list does not work yet :: for script files in UC2; therefore make sure you do not :: leave undesired filenames in the edited list of updated files. :excl_file echo %wo >> %excls_file set excl_file=on return ::----sub-routine for excl_file---- :mark_excl iff .%zip_pgm==.pkzip then set exclude=-x@%excls_file return elseiff .%zip_pgm==.zip then :: no solution for longer exclude line in ZIP at the moment ::echo %exclude > %excls_file ::set exclude=-@ %excls_file return elseiff .%zip_pgm==.uc then set exclude=!@%excls_file return endiff