home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / thcdasd.zip / BACKDASD.CMD < prev    next >
OS/2 REXX Batch file  |  1996-10-29  |  30KB  |  967 lines

  1. /* BACKDASD v1 - OS/2 REXX Script               */
  2. /* Copyright (c) Steve  Sharrad, 04/08/1996     */
  3. /* Backs up IBM OS/2 Warp/Lan Server            */
  4. /* DASD Limits to a file.                       */
  5. /*                                              */
  6. /* Program Information: ssha@henleycol.ac.uk    */
  7. /*                                              */
  8. /* The HENLEY College IT Services Unit 1996.    */
  9. /*                                              */
  10. /* For information about the College, contact   */
  11. /* info@henleycol.ac.uk, or visit               */
  12. /* www.henleycol.ac.uk                          */                         
  13.  
  14. step=1          /* step informs error handler of function with problem, substep indicates sub-routine */
  15. substep=0
  16. /* Changeable defaults follow    */
  17. '@echo off'
  18. version                 =       '1.00'                  /* version number                       */
  19. release_date            =       '04/08/96'              /* release date of version              */
  20. e_report                =       1                       /* default value for error reporting    */
  21. error_log               =       '\DASD.LOG'             /* default name for error log           */
  22. confirm                 =       0                       /* default value for asking confirmation*/
  23. verbose                 =       0                       /* default value for verbose            */
  24. timewrite               =       0                       /* default value of writing time to file*/
  25.  
  26. DASDInfo.BufferSize='6018000'
  27.  
  28.             /* DASD buffersize-6018000 does 1600 limits ok */
  29. DASDInfo.recursive      =       1                       /* default value for recursiveness      */
  30. defext                  =       '.DSD'                  /* default extension of DASD backup file*/
  31.  
  32. /* Internal defaults follow      */
  33.  
  34. backuppath              =       ''
  35. backupfile              =       ''
  36. NETWKSTA                =       350
  37. param_num               =       ''
  38. params.0                =       0
  39. NETDASD                 =       750
  40. DASDInfo.DirPath        =       ''
  41. DASDInfo.count          =       0
  42. DASDInfo.EntriesAvail   =       0
  43. SrvName                 =       ''
  44. Netcode                 =       0
  45. Loop                    =       0
  46. exitcode                =       0
  47. wcount                  =       1
  48. schk                    =       0
  49. backup_name             =       ''
  50. step                    =       0
  51. local                   =       1
  52. substep                 =       0
  53. msg                     =       ''
  54. rpath                   =       ''
  55. count                   =       1
  56. sftparm                 =       ''
  57. retcode                 =       0
  58. timewr=timewrite
  59. verb=verbose
  60. conf=confirm
  61.  
  62. main:  
  63. step=2
  64. say 'BACKDASD Version 'version'   Release 'release_date' (c) Steve Sharrad.'
  65. say 'Internet e-mail: ssha@henleycol.ac.uk'
  66. call time 'r'
  67. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  68. Signal on Syntax Name util_load
  69. call SysLoadFuncs 
  70. call RxFuncAdd 'LoadLsRxutFuncs', 'LSRXUT', 'LoadLsRxutFuncs'
  71. Signal on Syntax Name lsapi_load
  72. call LoadLsRxutFuncs
  73. Signal on Syntax Name bad_problem
  74. Signal on Error Name bad_problem
  75. step=3
  76. parse upper arg params 
  77. if params = '?' then signal help
  78. if params = '/?' then signal help
  79. if params = 'HELP' then signal help
  80. netcode = NetGetInfo(NETWKSTA, 'wkstaInfo', SrvName)
  81. if netcode <> '0' then signal get_info
  82. SrvName = wkstaInfo.computername
  83. if wkstaInfo.ver_major < '4' then signal wrong_ver
  84. drop wkstaInfo
  85. step=4
  86.     do while params \= ''
  87.         parse var params fword params
  88.         parse var fword 1 swtch +3 swval
  89.         schk=0
  90.         if swtch = '/F:' then do
  91.             step=5
  92.             if left(swval,1) = '"' then do
  93.                 if right(swval,1) \= '"' then call encap1
  94.                 if right(swval,1) = '"' then swval=strip(swval,,'"')
  95.                 end
  96.             if left(swval,1) = ':' then signal need_drive
  97.             backupfile = swval
  98.             call set_name
  99.             schk=1
  100.             end
  101.         else
  102.         if swtch = '/P:' then do
  103.             step=6
  104.             if left(swval,1) = '"' then do
  105.                 if right(swval,1) \= '"' then call encap1
  106.                 if right(swval,1) = '"' then swval=strip(swval,,'"')
  107.                 end
  108.             if left(swval,1) = '\' then signal need_drive
  109.             if left(swval,1) = ':' then signal need_drive
  110.             if left(substr(swval,3),1) \= '\' then signal need_drive
  111.             if left(substr(swval,2),1) \= ':' then signal need_drive
  112.             DASDInfo.DirPath = swval
  113.             if DASDInfo.DirPath='' then signal need_drive
  114.             schk=1
  115.             end
  116.         else
  117.         if swtch = '/L:' then do
  118.             step=7
  119.             if left(swval,1) = '"' then do
  120.                 if right(swval,1) \= '"' then call encap1
  121.                 if right(swval,1) = '"' then swval=strip(swval,,'"')
  122.                 end
  123.             if left(swval,1) = '\' then signal need_drive
  124.             if left(swval,1) = ':' then signal need_drive
  125.             error_log = swval
  126.             schk=1
  127.             end
  128.         else
  129.         if swtch = '/S:' then do
  130.             step=8
  131.             if right(left(swval,2),1) = '\' then do
  132.                 if left(swval,1) = '\' then do
  133.                     if SrvName=swval then local=1
  134.                     else local=0
  135.                     SrvName = swval
  136.                     end
  137.                 end
  138.             if right(left(swval,3),1) = '' then SrvName=''
  139.             if SrvName='' then signal bad_server
  140.             
  141.             schk=1
  142.             end
  143.         else
  144.         if swtch = '/R:' then do
  145.                 step=9
  146.                 if swval='0' then do
  147.                     DASDInfo.recursive=0
  148.                     DASDInfo.EntriesAvail=1
  149.                     DASDInfo.count=1
  150.                     end
  151.                 if swval='1' then DASDInfo.recursive=1
  152.                 if swval='2' then DASDInfo.recursive=2
  153.                 if swval>='3' then signal invalid_recur
  154.             schk=1
  155.             end
  156.         else
  157.         if swtch = '/E' then do
  158.             step=10
  159.             schk=1
  160.             e_report=0
  161.             end
  162.         else
  163.         if swtch = '/V' then do
  164.             step=11
  165.             schk=1
  166.             if verbose='0' then verb=1
  167.             if verbose='1' then verb=0
  168.             end
  169.         else
  170.         if swtch = '/C' then do
  171.             step=12
  172.             schk=1
  173.             if confirm= '0' then conf=1
  174.             if confirm= '1' then conf=0
  175.             end
  176.         else
  177.         if swtch = '/T' then do
  178.             step=13
  179.             schk=1
  180.             if timewrite= '0' then timewr=1
  181.             if timewrite= '1' then timewr=0
  182.             end
  183.  
  184.         else
  185.         if swtch = '/L:' then do
  186.             step=14
  187.             logfile = swval
  188.             schk=1
  189.             end
  190.         else
  191.         if schk = '0' then signal unknown_switch
  192.         if left(swtch,1) = '/' then do
  193.             step=15
  194.             swtch=swtch
  195.             nsw=swval
  196.             end
  197.         p = wordpos(swtch, param_num)
  198.         if p = 0 then do
  199.             step=16
  200.             param_num=param_num swtch
  201.             parno = params.0 + 1
  202.             params.parno = nsw
  203.             params.0 = parno
  204.             end
  205.         else do
  206.             step=17
  207.             params.p = nsw
  208.             end
  209.         end
  210.  
  211. if local=1 then do
  212.     step=18
  213.     signal on error name bad_dir 
  214.     if right(DASDInfo.DirPath,2)='\"' | right(DASDInfo.DirPath,1) = '\' then do
  215.         cmdline='dir "'DASDInfo.DirPath'" >nul'
  216.         cmdline
  217.         end
  218.     else 
  219.     cmdline='dir "'DASDInfo.DirPath'\" >nul'
  220.     cmdline
  221.     end
  222.     signal on error name bad_problem
  223. step=19
  224. if local=0 then call chk_remote
  225. if DASDInfo.DirPath='' then signal nobackup_path
  226. if backupfile='' then signal nobackup_file
  227. if conf='1' then do
  228.     step=20
  229.     call display_info
  230.     call confirm_first
  231.     end
  232. if verb=1 then
  233.     if conf='0' then do
  234.         call display_info
  235.     end
  236.  
  237. if filefind(backupfile) then do
  238.     step=21
  239.     call get_name
  240.     call create_backup
  241.     end
  242. step=22
  243. dataline='DASD BACKUP FILE PRODUCED BY BACKDASD (programmed by Steve Sharrad).'
  244. wcount = lineout(backupfile,dataline)
  245. if wcount=1 then signal fail_write
  246. say ' DASD limit backup file is 'backupfile
  247. say ' Enumerating DASD limit(s)...'
  248. step=23
  249. if DASDInfo.recursive=2 then do
  250.     step=24
  251.     origpath=DASDInfo.DirPath
  252.     if rpath \= '' then do
  253.         step=25
  254.         rpath=rpath'\'
  255.         DASDInfo.DirPath='"'rpath'"'
  256.         end
  257.     step=26
  258.     if right(DASDInfo.DirPath,1) \= '\' then if rpath = '' then rpath=DASDInfo.DirPath'\' 
  259.     if right(DASDInfo.DirPath,1) = '\' then if rpath = '' then rpath=DASDInfo.DirPath
  260.     sftparm='DO'
  261.     count=0
  262.     retrieved.0=1
  263.     loop=0
  264.     end
  265.  
  266. if DASDInfo.recursive=0 then do
  267.     step=27
  268.     origpath=DASDInfo.DirPath
  269.     if rpath \= '' then rpath='"'rpath'\"'
  270.     if rpath = '' then rpath=DASDInfo.DirPath
  271.     sftparm='DO'
  272.     count=0
  273.     retrieved.0=1
  274.     loop=0
  275.     step=28
  276.     DASDInfo.max=''
  277.     netcode=NetGetInfo(NETDASD, 'DASDInfo',Srvname)
  278.     if left(netcode,4) = '2117' then signal redir_path
  279.     if left(netcode,4) = '2301' then signal not_enabled
  280.     if left(netcode,4) = '2303' then signal not_386hpfs
  281.     if netcode <> '0' then signal unknown_problem
  282.     step=29
  283.     if DASDInfo.max \= '0' then do
  284.     DASDInfo.count.resource_name=right(DASDInfo.DirPath,length(DASDInfo.DirPath)-length(OrigPath))
  285.             step=30
  286.             DASDInfo.0.max=DASDInfo.max
  287.             DASDInfo.0.thresh=DASDInfo.thresh
  288.             DASDInfo.0.delta=DASDInfo.delta
  289.             count=1
  290.             end
  291.     if count=0 then signal no_limits
  292.     end
  293.  
  294. if DASDInfo.recursive=1 then do
  295.     step=31
  296.     origpath=DASDInfo.DirPath
  297.     if rpath \= '' then rpath='"'rpath'\"'
  298.     if right(DASDInfo.DirPath,1) \= '\' then if rpath = '' then rpath=DASDInfo.DirPath'\' 
  299.     if right(DASDInfo.DirPath,1) = '\' then if rpath = '' then rpath=DASDInfo.DirPath
  300.     count=0
  301.     retrieved.0=0
  302.     loop=1
  303.     sftparm='DOS'
  304.     end
  305.  
  306. if DASDInfo.recursive = '1' then do
  307. drop count
  308. step=32
  309. netcode = NetEnumerate(NETDASD, 'DASDInfo', SrvName)
  310. if left(netcode,4) = '2117' then signal redir_path
  311. if left(netcode,4) = '2301' then signal not_enabled
  312. if left(netcode,2) = '53' then signal unknown_problem
  313. if left(netcode,4) = '2303' then signal not_386hpfs
  314. if netcode <> '0' then signal unknown_problem
  315. if DASDInfo.EntriesAvail='0' then signal no_limits
  316. if DASDInfo.EntriesAvail>DASDInfo.count then call stack_space
  317. if DASDInfo.EntriesAvail=1 then
  318.     if DASDInfo.1.resource_name='' then
  319.         DASDInfo.1.resource_name=DASDInfo.DirPath
  320. if DASDInfo.recursive='0' then do
  321.     step=33
  322.     if DASDInfo.max='0' then signal no_limits
  323.     DASDInfo.1.max=DASDInfo.max
  324.     DASDInfo.1.thresh=DASDInfo.thresh
  325.     DASDInfo.1.delta=DASDInfo.delta
  326.     DASDInfo.1.resource_name=''
  327.     end
  328. count=DASDInfo.count
  329. end
  330.  
  331. step=34
  332.  
  333. if DASDInfo.recursive = 2 then do
  334. retcode=SysFileTree(rpath,'retrieved',sftparm)
  335.  
  336. if DASDInfo.recursive = 0 then i=0
  337. else i=1
  338.     do i=0 to Retrieved.0
  339.         step=35
  340.         if i>0 then DASDInfo.DirPath=retrieved.i
  341.         if i=0 then DASDInfo.DirPath=origpath
  342.     if i \= 0 then if local=0 then call get_local
  343.         DASDInfo.max=''
  344.         netcode=NetGetInfo(NETDASD, 'DASDInfo',Srvname)
  345.         if left(netcode,4) = '2117' then signal redir_path
  346.         if left(netcode,4) = '2301' then signal not_enabled
  347.         if left(netcode,4) = '2303' then signal not_386hpfs
  348.         if netcode <> '0' then signal unknown_problem
  349.         if DASDInfo.max \= '0' then do
  350.             step=36
  351.             DASDInfo.count.resource_name=right(DASDInfo.DirPath,length(DASDInfo.DirPath)-length(OrigPath))
  352.             DASDInfo.count.max=DASDInfo.max
  353.             DASDInfo.count.thresh=DASDInfo.thresh
  354.             DASDInfo.count.delta=DASDInfo.delta
  355.             count=count+1
  356.             end
  357.     end
  358. if count = '0' then signal no_limits
  359. end
  360. step=37
  361. say ' Writing data to backup file ('count' entries)...'
  362. origpath='"'origpath'"'
  363. dataline='/T:'time('N')' /D:'date('E') '/S:'SrvName' /N:'count' /R:'DASDInfo.recursive' /P:'origpath' /V:'version
  364. call lineout backupfile,dataline
  365.  
  366. if DASDInfo.recursive = 0 | DASDInfo.recursive = 2 then count=count-1
  367.  
  368. do until Loop>count
  369. step=38
  370. DASDInfo.Loop.resource_name='"'DASDInfo.Loop.resource_name'"'
  371. if verb=1 | conf=1 then do
  372.     step=25
  373.     say ' '
  374.     say ' Backed up DASD limits for: 'SrvName': 'strip(origpath,,'"')''strip(DASDInfo.Loop.resource_name,,'"') 
  375.  
  376.     end
  377.     dataline='/1:'DASDInfo.Loop.resource_name' /2:'DASDInfo.Loop.max' /3:'DASDInfo.Loop.thresh' /4:'DASDInfo.Loop.delta
  378.     wcount = lineout(backupfile,dataline)
  379.     if wcount=1 then signal fail_write
  380.     Loop=Loop+1
  381. end
  382. step=39
  383. call stream backupfile,'c','close'
  384. call stream logfile,'c','close'
  385. step=40
  386. if count=0 & if DASDInfo.recursive = 1 | DASDInfo.recursive = 2 then count=count+1
  387. say ' Number of DASD limits backed up to 'backupfile' : ' count
  388. signal end
  389.  
  390. encap1:
  391. substep=1
  392. lstring=swval
  393. do while params \= ''
  394.     i=length(params) 
  395.     parse var params fword params
  396.     j=length(params)
  397.     if j \=0 then j=j+1
  398.     k=length(fword)
  399.     l=i-j-k
  400.     do while l>=0
  401.         lstring=lstring' '
  402.         l=l-1
  403.         end
  404.     lstring=lstring''fword
  405.     if right(fword,1) = '"' then fin=1
  406.     p = wordpos(swtch, param_num)
  407.         if p = 0 then do
  408.             step=12
  409.             param_num=param_num swtch
  410.             parno = params.0 + 1
  411.             params.parno = nsw
  412.             params.0 = parno
  413.             end
  414.         else do
  415.             step=13
  416.             params.p = nsw
  417.             end
  418. if fin=1 then do
  419.     substep=2
  420.     i=length(lstring)
  421.     swval=strip(lstring,,'"') 
  422. /*      drop i */
  423.     drop fin
  424.     drop j
  425.     drop k
  426.     drop l
  427.     drop lstring
  428.     return
  429. end
  430. return
  431.  
  432. help:
  433. step=31
  434. say ' '
  435. say 'Backs up DASD directory limits on 386-HPFS DASD-enabled volumes.'
  436. say 'BACKDASD backs up all DASD information for a specified path into'
  437. say 'a backup file. You can then use RESTDASD to restore this file.'
  438. say ' '
  439. say 'The syntax of this command is:'
  440. say 'BACKDASD /F:[filename] /P:[pathname] [/R:[value]] [/L:[filename]] [/S:\\[servername]] [[/E]] [[/C]] [[/V]] [[/T]]'
  441. say ' '
  442. say 'Required Parameters: /F:[filename] Specify a filename to backup to'
  443. say '                                   Default extension is 'defext
  444. say '                /P:[pathname]      Specify the pathname/tree to backup'
  445. say 'Optional Parameters: /R:[value]            Specify 0 to turn off recursive backup'
  446. say '                                   Specify 1 (default) to backup all sub-'
  447. say '                                   directories, or 2 to backup only sub-'
  448. say '                                   directories upto 1 level down.'
  449. say '                /L:[filename]      Specify a different errorlog filename'
  450. say '                                   Defaults to 'error_log
  451. say '                /S:\\[server]      Specify a valid server on domain. If'
  452. say '                                   used, then pathname must be on server'
  453. say '                /E                 Turns-off the error logging to file'
  454. 'pause'
  455. say '                /C                 Displays info and asks for confirmation'
  456. say '                /V                 Displays information during process'
  457. say '                /T                 Write the operation time and backup'
  458. say '                                   count to error log upon completion'
  459. say ' '
  460. say 'BACKDASD 1.00      -  Copyright 1996, Steve Sharrad.'
  461. say '                      Copyright 1996, The HENLEY College.'
  462. say 'This program may be freely copied so long as it is not modified.'
  463. say 'All rights reserved. For further information, view help file.'
  464. exitcode=0
  465. signal finito
  466.  
  467. nobackup_path:
  468. say ' '
  469. say 'BACKDASD 0002: You must specify a valid path for BACKDASD to back up'
  470. say 'with the /P:[path] switch.'
  471. say ' '
  472. say 'This must be a qualified pathname, i.e. C:\USERS, not USERS.'
  473. say 'Type BACKDASD /? for help'
  474. exitcode=2
  475. if e_report = '0' then signal end
  476. call write_header
  477. logline='BACKDASD 0002: Invalid backup path or path not specified.'
  478. call lineout error_log,logline
  479. signal end
  480.  
  481. nobackup_file:
  482. say ' '
  483. say 'BACKDASD 0003: You must specify a filename for BACKDASD to backup'
  484. say 'DASD limits to with the /F:[filename] switch.'
  485. say ' '
  486. say 'Type BACKDASD /? for help'
  487. exitcode=3
  488. if e_report = '0' then signal end
  489. call write_header
  490. logline='BACKDASD 0003: No backup file specified'
  491. call lineout error_log,logline
  492. signal end
  493.  
  494. invalid_recur:
  495. say ' '
  496. say 'BACKDASD 0004: You have specified an invalid parameter for the recursive'
  497. say 'option. Use /R:[x] where x is either 1 (default) or 0 to inhibit action'
  498. say 'on sub-directories'
  499. exitcode=4
  500. if e_report = '0' then signal end
  501. call write_header
  502. logline='BACKDASD 0004: Invalid value for /R: (Recursive) specified.'
  503. call lineout error_log,logline
  504. signal end
  505.  
  506. stack_space:
  507. say ' '
  508. step=42
  509. say "BACKDASD 0005: Warning: Failing due to insufficient stack space."
  510. say " "
  511. say "There are too many DASD limits present for BACKDASD to fully comply."
  512. say "Try increasing BACKDASD's stack space by increasing the"
  513. say "DASDInfo.BufferSize parameter in the BACKDASD.CMD file."
  514. say ' '
  515. say "Continuing to backup the collected limits within the confined stack space."
  516. say " "
  517. say 'Number of entries available (truncated): ' DASDInfo.EntriesAvail
  518. say 'Number of entries actually backed up   : ' DASDInfo.count
  519. say 'Current buffer size                    : ' DASDInfo.BufferSize
  520. say 'Suggested required buffer size         : ' format(DASDInfo.BufferSize/DASDInfo.count * DASDInfo.EntriesAvail,,0)
  521. say ' '
  522. exitcode=5
  523. if e_report = '0' then return
  524. say 'Details will also be written to log file.'
  525. call write_header
  526. logline="BACKDASD 0005: Warning: Failing due to insufficient stack space."
  527. call lineout error_log,logline
  528. logline="There are too many DASD limits present for BACKDASD to fully comply."
  529. call lineout error_log,logline
  530. logline="Try increasing BACKDASD's stack space by increasing the"
  531. call lineout error_log,logline
  532. logline="DASDInfo.BufferSize parameter in the BACKDASD.CMD file."
  533. call lineout error_log,logline
  534. logline="Continuing to backup the collected limits within the confined stack space."
  535. call lineout error_log,logline
  536. logline='Number of entries available (truncated): ' DASDInfo.EntriesAvail
  537. call lineout error_log,logline
  538. logline='Number of entries actually backed up   : ' DASDInfo.count
  539. call lineout error_log,logline
  540. logline='Current buffer size                    : ' DASDInfo.BufferSize
  541. call lineout error_log,logline
  542. logline='Suggested required buffer size         : ' format(DASDInfo.BufferSize/DASDInfo.count * DASDInfo.EntriesAvail,,0)
  543. call lineout error_log,logline
  544. say ' '
  545. return
  546.  
  547. not_enabled:
  548. say ' '
  549. say 'BACKDASD 0006: (NET 2301) DASD limits are not enabled on the specified'
  550. say '386-HPFS volume. Enable DASD limits using the NET DASD command.'
  551. say 'Use NET HELP DASD for more information.'
  552. exitcode=6
  553. if e_report = '0' then signal end
  554. call write_header
  555. logline='BACKDASD 0006: (NET 2301) DASD limits are not enabled on specified drive.'
  556. call lineout error_log,logline
  557. signal end
  558.  
  559. not_386hpfs:
  560. say ' '
  561. say 'BACKDASD 0007: (NET 2303) DASD limits are only supported on 386-HPFS'
  562. say 'volumes, not FAT disks. Use NET HELP DASD for more information.'
  563. exitcode=7
  564. if e_report = '0' then signal end
  565. call write_header
  566. logline='BACKDASD 0007: (NET 2303) Not a 386HPFS volume.'
  567. call lineout error_log,logline
  568. signal end
  569.  
  570. unknown_problem:
  571. say ' '
  572. say 'BACKDASD 0008: (NET 'netcode')'
  573. say 'Could not perform DASD operation for an unknown reason (check error code'
  574. say 'above in brackets). Check that the server 'SrvName' is running and that'
  575. say 'you have specified valid pathnames and/or servernames.'
  576. exitcode=8
  577. if e_report = '0' then signal end
  578. call write_header
  579. logline='BACKDASD 0008: (NET 'netcode')'
  580. call lineout error_log,logline 
  581. logline='Check specified servernames and pathnames.'
  582. call lineout error_log,logline
  583. signal end
  584.  
  585. need_drive:
  586. say ' '
  587. say 'BACKDASD 0009: You need to specify a fully qualified drive and pathname'
  588. say 'to be backed up:'
  589. say ' '
  590. say '   i.e.    /P:C:\USERS     is acceptable'
  591. say '           /P:\USERS       is not acceptable'
  592. say ' '
  593. say 'If you specify a servername (/S:\\[SrvName]) then you must specify a pathname'
  594. say 'which is not a redirected pathname, i.e. to backup the D drive of server'
  595. say 'APPSRV then you must specifiy /P:D:\ /S:\\APPSRV'
  596. say 'Check also that all filenames that you have given are valid.'
  597. exitcode=9
  598. if e_report = '0' then signal end
  599. call write_header
  600. logline='BACKDASD 0009: Drive and pathname not fully specified or incorrect filename'
  601. call lineout error_log,logline
  602. signal end
  603.  
  604. fail_write:
  605. say ' '
  606. say 'BACKDASD 0010: An error occurred while writing to disk. '
  607. say 'Could not write to file 'backupfile
  608. say 'If you are using the FAT file system, check the size of the filename. Also'
  609. say 'check disk space and that the backup file is not read-only and that you'
  610. say 'can write to it.'
  611. say ' '
  612. say 'Also check that all pathnames and directory names you have given are valid'
  613. exitcode=10
  614. if e_report = '0' then signal end
  615. call write_header
  616. logline='BACKDASD 0010: Error occurred writing to disk. Check paths, permissions and space.'
  617. call lineout error_log,logline
  618. signal end
  619.  
  620. bad_server:
  621. say ' '
  622. say 'BACKDASD 0011: The server name you have specified should start with two'
  623. say 'backslashes (\\) and then the servername. The server should be on the'
  624. say 'default domain.'
  625. exitcode=11
  626. if e_report = '0' then signal end
  627. call write_header
  628. logline='BACKDASD 0011: Servername specified does not start "\\" or is empty.'
  629. call lineout error_log,logline
  630. signal end
  631.  
  632. no_limits:
  633. call stream backupfile,'c','close'
  634. if filefind(backupfile) then rc=SysFileDelete(backupfile)
  635. say ' '
  636. say 'BACKDASD 0012: Warning! No DASD limits found for backing up.'
  637. say 'There may be no DASD limits on the path you have specified.'
  638. exitcode=12     
  639. if e_report = '0' then signal end
  640. call write_header
  641. logline='BACKDASD 0012: Warning! No DASD limits found - check existence of limits.'
  642. call lineout error_log,logline
  643. signal end
  644. end
  645.  
  646. unknown_switch:
  647. say ' '
  648. say 'BACKDASD 0013: Unknown or incomplete switch on command line.'
  649. say ' '
  650. say 'The option "'swtch''swval'" is unknown.'
  651. say 'Type BACKDASD /? for help.'
  652. exitcode=13
  653. if e_report = '0' then signal end
  654. call write_header
  655. logline='BACKDASD 0013: Incorrect or unknown switch on command line.'
  656. call lineout error_log,logline
  657. signal end
  658.  
  659. bad_problem:
  660. error:
  661. say ' '
  662. say 'BACKDASD 0014: BACKDASD has encountered an internal error.'
  663. say 'Please check available memory and stack space. Report this'
  664. say 'problem and how you created it together with the information'
  665. say 'below to internet e-mail: ssha@henleycol.ac.uk:'
  666. say ' '
  667. elapsed = time('e') % 1
  668. minutes = elapsed % 60
  669. seconds = elapsed // 60
  670. say 'Debug Information: '
  671. say 'Error RC: 'rc'     Elapsed Time:'minutes' 'seconds
  672. say 'Buffersize:   'DASDInfo.BufferSize'    Error Handler: 00014'
  673. say 'Version: 'version'   Release: 'release_date '   DASD: 'DASDInfo.recursive
  674. say ' Step: 'step'         Substep: 'substep
  675. say 'Count: 'count'          Loop: 'loop'        Local: 'local
  676. say ' Verb: 'verb'           Conf: 'conf'       Timewr: 'timewr
  677. say ' '
  678. say 'Description of error:'
  679. say ' '
  680. msg=SysGetMessage(rc)
  681. say msg
  682. exitcode=14
  683. if e_report = '0' then signal end
  684. call write_header
  685. logline='BACKDASD 0014: Fatal Internal error. Error: 'rc
  686. call lineout error_log,logline
  687. logline='Error Description: 'msg
  688. call lineout error_log,logline
  689. signal end
  690. end
  691.  
  692. lsapi_load:
  693. If rc=43 Then Do
  694.     say ' '
  695.     say 'BACKDASD 0015: BACKDASD failed to correctly initialise the'
  696.     say 'network API support module, LSRXUT.DLL.'
  697.     say ' '
  698.     say 'Please check that the file LSRXUT.DLL resides in any sub-'
  699.     say 'directory pointed to the LIBPATH statement in your CONFIG.SYS'
  700.     say 'file. If this file exists, then check the amount of available'
  701.     say 'memory and/or stack space available.'
  702.     say ' '
  703.     exitcode=15
  704.     if e_report = '0' then signal end
  705.     call write_header
  706.     logline='BACKDASD 0015: Failed to initialise API module LSRXUT.DLL.'
  707.     call lineout error_log,logline
  708.     signal finito
  709.     end
  710. else signal bad_problem
  711. end
  712.  
  713. util_load:
  714. If rc=43 Then Do
  715.     say ' '
  716.     say 'BACKDASD 0016: BACKDASD failed to correctly initialise the'
  717.     say 'advanced REXX function module, REXXUTIL.DLL'
  718.     say ' '
  719.     say 'Please check that the file REXXUTIL.DLL resides in any sub-'
  720.     say 'directory pointed to the LIBPATH statement in your CONFIG.SYS'
  721.     say 'file. If this file exists, then check the amount of available'
  722.     say 'memory and/or stack space available.'
  723.     say ' '
  724.     exitcode=16
  725.     if e_report = '0' then signal end
  726.     call write_header
  727.     logline='BACKDASD 0016: Failed to initialise base OS/2 module REXXUTIL.'
  728.     call lineout error_log,logline
  729.     signal finito
  730.     end
  731. else signal bad_problem
  732. end
  733.  
  734. no_backup:
  735. say ' '
  736. say 'BACKDASD 0017: An error occurred while copying or deleting one of the'
  737. say 'following files: 'backup_name' or 'backupfile
  738. say ' '
  739. say 'Please check that none of these files are read-only and that sufficient'
  740. say 'disk space is available.'
  741. exitcode=13
  742. if e_report = '0' then signal end
  743. call write_header
  744. logline='BACKDASD 0017: The destination file is read only or backup could not be made.'
  745. call lineout error_log,logline
  746. signal finito
  747. end
  748.  
  749. bad_dir:
  750. say ' '
  751. say 'BACKDASD 0018: You have specified a bad directory or pathname to be'
  752. say 'backed up. Check that the path exists.'
  753. exitcode=18
  754. if e_report = '0' then signal end
  755. call write_header
  756. logline='BACKDASD 0018: The path specified to have its limits backed up does not seem to exist.'
  757. call lineout error_log,logline
  758. signal finito
  759. end
  760.  
  761. get_info:
  762. say ' '
  763. say 'BACKDASD 0019: Could not get local machine network information.'
  764. say 'Check that the server and requester are running correctly.'
  765. exitcode=19
  766. if e_report = '0' then signal end
  767. call write_header
  768. logline='BACKDASD 0019: Could not get local machine network information.'
  769. call lineout error_log,logline
  770. signal finito
  771. end
  772.  
  773. wrong_ver:
  774. say ' '
  775. say 'BACKDASD 0020: DASD limits (and BACK/REST DASD) are not'
  776. say 'on versions of IBM OS/2 Lan Server or Warp Server prior to version 4.'
  777. exitcode=20
  778. if e_report = '0' then signal end
  779. call write_header
  780. logline='BACKDASD 0020: Version of Lan Server too old.'
  781. call lineout error_log,logline
  782. signal finito
  783. end
  784.  
  785. fail_remote:
  786. say ' '
  787. say 'BACKDASD 0023: The path on the remote server cannot be found.'
  788. say 'Check that the remote server is running and that the pathname is'
  789. say 'correct.'
  790. say ' '
  791. say 'Also note that if you are operating on a remote server, then'
  792. say 'you will also need to be logged on to the local workstation.'
  793. exitcode=23
  794. if e_report = '0' then signal end
  795. call write_header
  796. logline='BACKDASD 0023: The path on the remote server cannot be found. '
  797. call lineout error_log,logline
  798. signal finito
  799. end
  800.  
  801. redir_path:
  802. say ' '
  803. say 'BACKDASD 0024: You cannot specify a redirected resource for DASD'
  804. say 'operations. If you wish to backup a remote server, use the'
  805. say '/S:\\[servername] switch with the /P: switch pointing to a local'
  806. say 'drive on that server'
  807. exitcode=24
  808. if e_report = '0' then signal end
  809. call write_header
  810. logline='BACKDASD 0024: Redirected resources cannot be specified.'
  811. call lineout error_log,logline
  812. signal finito
  813. end
  814.  
  815. chk_remote:
  816. substep=3
  817. i=length(DASDInfo.DirPath)
  818. signal on error name fail_remote
  819. rpath=SrvName'\'left(DASDInfo.DirPath,1)'$'right(DASDInfo.DirPath,i-2)
  820. if right(rpath,1)='\' then do
  821.     substep=4
  822.     cmdline='dir "'rpath'" >nul'
  823.     cmdline
  824.     end
  825. else do
  826.     substep=5
  827.     cmdline='dir "'rpath'\" >nul'
  828.     cmdline
  829.     end
  830. signal on error name bad_problem
  831. return
  832.  
  833. get_local:
  834. substep=6
  835. l=length(DASDInfo.DirPath)
  836. s=length(SrvName)
  837. s=s+1
  838. DASDInfo.DirPath=right(DASDInfo.DirPath,l-s)
  839. ldrive=left(DASDInfo.DirPath,1)
  840. s=s+2
  841. substep=7
  842. DASDInfo.DirPath=right(DASDInfo.DirPath,l-s)
  843. DASDInfo.DirPath=ldrive':'DASDInfo.DirPath
  844. drop s
  845. drop l
  846. drop ldrive
  847. return
  848.  
  849. write_header:
  850. substep=8
  851. logline='--------- Date: 'date('E')' Time: 'time('N')
  852. wlog=lineout(error_log,logline)
  853. if wlog=1 then say 'BACKDASD 0025: Error writing to error log during operations.'
  854. drop wlog
  855. return
  856.  
  857. filefind: Procedure
  858. substep=9
  859. return ('' \= stream( arg(1), 'c', 'query exists') )
  860.  
  861. confirm_first:
  862. substep=10
  863. say ' '
  864. say 'Press Y <enter> to continue, or any other key <enter> to abort.'
  865. parse upper pull c
  866. if c='Y' then return
  867. say 'Operation aborted.'
  868. signal end
  869.  
  870. display_info:
  871. substep=11
  872. say ' '
  873. say 'BACKDASD will perform the following:'
  874. say ' '
  875. say 'Path to backup DASD limits         : 'DASDInfo.DirPath
  876. say 'File to backup DASD limits to      : 'backupfile
  877. if DASDInfo.recursive = '1' then say 'Backup sub-directories (recursive) : Yes'
  878. if DASDInfo.recursive = '0' then say 'Backup sub-directories (recursive) : No'
  879. if DASDInfo.recursive = '2' then say 'Backup sub-directories (recursive) : Down to one level'
  880. if e_report = '0' then say 'Error log file reports             : Disabled'
  881. if e_report = '1' then say 'Error log file reports written to  : 'error_log
  882. if local=1 then say 'Server Name                        : 'srvname' (local machine)'
  883. else say 'Server Name                        : 'srvname' (remote machine)'
  884. if timewr='1' then say 'Operation time will be written to log upon completion.'
  885. substep=12
  886. if filefind(backupfile) then do
  887.     call get_name
  888.     say ' '
  889.     say 'The backup file 'backupfile' already exists. It will'
  890.     say 'be copied to file 'backup_name' before being overwritten.'
  891. end
  892.  
  893. get_name:
  894. substep=13
  895. backup_name=''
  896. do i=1 to length(backupfile)
  897.     if left(right(backupfile,i),1) = '.' then backup_name=left(backupfile,length(backupfile)-i)'.BAK'
  898. end
  899. if backup_name='' then do
  900.     substep=14
  901.     backupfile=backupfile'.'
  902.     call get_name
  903.     end
  904. return  
  905.  
  906. set_name:
  907. substep=15
  908. dot=0
  909. do i=1 to length(backupfile)
  910.     if left(right(backupfile,i),1) = '.' then dot=1
  911. end
  912. if dot=0 then backupfile=backupfile''defext
  913. return  
  914.  
  915.  
  916. create_backup:
  917. /* remember if <> is the same as if not */
  918. substep=16
  919. if backup_name='' then call get_name
  920. if filefind(backup_name) then do
  921.     substep=17
  922.     rc=SysFileDelete(backup_name)
  923.     if rc <> '0' then signal no_backup
  924.     end
  925. cmdline='copy "'backupfile'" "'backup_name'" >nul'
  926. cmdline
  927. if filefind(backup_name) then do
  928.     substep=18
  929.     rc=SysFileDelete(backupfile)
  930.     if rc <> '0' then signal no_backup
  931.     end
  932. else signal no_backup
  933. say ' Successfully renamed 'backupfile' to 'backup_name
  934. return
  935.  
  936. end:
  937. step=27
  938. elapsed = time('e') % 1
  939. minutes = elapsed % 60
  940. seconds = elapsed // 60
  941. say ' '
  942. if exitcode <> '0' then do
  943.     say 'BACKDASD ended encountering at least 1 error or warning.'
  944.     call stream logfile,'c','close'
  945.     end
  946. if exitcode = '0' | exitcode = '5' | exitcode = '12' then do
  947.     say 'Total Operation Time:' minutes' minutes, 'seconds 'seconds.'
  948.     say 'BACKDASD completed successfully.'
  949.     end
  950. if exitcode = '0' | exitcode = '5' | exitcode ='12' then
  951.     if timewr='1' then do
  952.     call write_header
  953.     logline='BACKDASD: Operation successful: Total Operation Time:' minutes' minutes, 'seconds 'seconds.'
  954.     call lineout error_log,logline
  955.     logline='          Number of entries backed up: 'count' of path 'DASDInfo.DirPath
  956.     call lineout error_log,logline
  957.     call stream logfile,'c','close'
  958.     end
  959. signal finito
  960.  
  961. finito:
  962. drop DASDInfo
  963. drop count
  964. if verb = '1' & if exitcode != '0' then exit exitcode
  965. exit
  966.  
  967.