home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / bakitup1.zip / bakitup.cmd < prev    next >
OS/2 REXX Batch file  |  1995-01-15  |  7KB  |  226 lines

  1. /* This is a REXX file to back up selected files to one diskette drive  */
  2. /* while writing a log to the other drive */
  3. cls
  4.  
  5. /* This is set up to log on A: and place backups on B:
  6.  * If you want to reverse, change it here
  7.  */
  8. backupdisk = "B:"
  9. logdisk    = "A:"
  10.  
  11. /* This can be used to change what external command is
  12.  * executed by the program
  13.  */
  14. extcmd    = "backup"
  15.  
  16. say  "This procedure backs up selected files to drive" backupdisk
  17. call getlogdisk 
  18. call setupparms
  19. call bakemup
  20. EXIT
  21.  
  22. getlogdisk:
  23. /* Set it up to be able to use SysFileTree */
  24. rc = RxFuncQuery( 'SysDriveInfo' )
  25. /* say "RxFuncQuery rc = " rc */
  26. if rc = 1 then
  27.   do
  28.     rc = RxFuncAdd( 'SysDriveInfo', 'RexxUtil', 'SysDriveInfo' )
  29.     /*   "RxFuncAdd rc = " rc  */
  30.   end
  31.  
  32. /* Check success, and do the job 
  33.  * rc can be 0 if SysDriveInfo is already registered or if it is
  34.  * already registered successfully.
  35.  */
  36. if rc = 0 then do
  37.   
  38.   driveinfo = ""
  39.   do while driveinfo = ""
  40.       say  "Please put the log diskette in drive" logdisk "and press ENTER"
  41.       pull newbie
  42.       driveinfo = SysDriveInfo( logdisk )
  43.   end
  44. end
  45. call RxFuncDrop( 'SysDriveInfo' )
  46. return    /* getlogdisk  */
  47.  
  48.    
  49. setupparms:
  50. /* This variable governs directory searches later on */
  51.           
  52. dattribs = '*+-**'
  53.  
  54. /*  Attributes for directories:
  55.         Archive   * (don't care)
  56.          Directory + (yes)
  57.          Hidden    - (no)
  58.          Read only * (don't care )
  59.          System    * (don't care )        */
  60.  
  61. say  "To start a new set enter N, otherwise anything else"   
  62.  
  63. parse upper pull newbie .
  64. /* say "newbie = " newbie 
  65.  * The dot ensures that blanks are stripped from around the first
  66.  * word and collects any multiple word garbage that might be
  67.  * entered to check robustness.
  68.  */
  69. new = substr(newbie, 1, 1 )
  70.  
  71. if new = "N" then  
  72.   do
  73.       parms = "/L:" || logdisk || "\backup.log"
  74.  
  75.       /*  New diskette set, no append, no check for modification
  76.          Attributes are: (L to R )
  77.  
  78.          Archive   * (don't care)
  79.          Directory - (no)
  80.          Hidden    - (no)
  81.          Read only * (don't care )
  82.          System    - (no)         */
  83.  
  84.       attrib = "*--*-"
  85.       'del a:backup.log 2> nul'
  86.   end
  87. else
  88.   do
  89.       parms = "/A /M /L:" || logdisk || "\backup.log"
  90.  
  91.       /*  Continue: append to current backup diskette,
  92.           backup only modified files
  93.  
  94.          Attributes are: (L to R )
  95.          Archive   + (must be set - selective backup)
  96.          Directory - (no)
  97.          Hidden    - (no)
  98.          Read only * (don't care )
  99.          System    - (no)         */
  100.  
  101.       attrib = "+--*-"
  102.   end
  103.  
  104. /* say "parms =" parms " attrib =" attrib */
  105. RETURN
  106.  
  107. bakemup:
  108. /*  These are the selected files  */
  109.  
  110. /*  Each selection is made as a pair, paths. and files.
  111.  *  The variable paths selects a root directory to be searched
  112.  *  for files of various types.  
  113.  *  The variable files contains the set of file extensions that
  114.  *  will be searched for.
  115.  *  To add/delete files, add/delete them in pairs.
  116.  *
  117.  *  Specify first the path to be backed up, then
  118.  *  the string of files to be searched for in each
  119.  *  subdirectory of the chosen directory, as well as the
  120.  *  directory itself.  Then change the limit variable below:
  121.  */
  122. paths.0 = "e:\files"
  123. files.0  = "*doc *wk1 *wk3 *wg2 *cdr *fm1 *fm3"
  124.  
  125. paths.1 = "e:\c600\binp" 
  126. files.1 = "*.cmd" 
  127.  
  128. paths.2 = "e:\word55"
  129. files.2 = "*.gly *.sty"
  130.  
  131. paths.3 = "d:\tk"
  132. files.3 = "*.tk"
  133.  
  134. paths.4 = "d:\sw\songs"
  135. files.4 = "*"
  136.  
  137. paths.5 = "d:\folks"
  138. files.5 = "*.dt?"             
  139.  
  140. paths.6 = "d:\bridge"
  141. files.6 = "*.dat"
  142.  
  143. paths.7 = "d:\windows"
  144. files.7 = "*.crd"
  145.  
  146. paths.8 = "e:\usr\bin"
  147. files.8 = "*.cmd"
  148.  
  149. paths.9 = "e:\prj" 
  150. files.9 = "*.doc *.y *.lxi *.asm *.mak *,v *.c *.cpp *.cc *.h *.mk" 
  151.  
  152. limit = 9  /* Change this when more file
  153.                       specs are added to the list.  The value 
  154.                       should be the same as the highest number on
  155.                       the files and paths variables.  */
  156.  
  157. /* This is a precaution, because this is the only
  158.  * directory where we back up all files, and don't
  159.  * want the .bak files.  
  160.  * 2> means redirect stderr, to avoid a frequent
  161.  * confusing message. 
  162.  * Some users may not wish to have such a command executed.
  163.  */
  164. 'del d:\sw\songs\*bak 2> nul'
  165.  
  166. /* Set it up to be able to use SysFileTree */
  167. rc = RxFuncQuery( 'SysFileTree' )
  168. /* say "RxFuncQuery rc = " rc */
  169. if rc = 1 then
  170.   do
  171.     rc = RxFuncAdd( 'SysFileTree', 'RexxUtil', 'SysFileTree' )
  172.     /* say "RxFuncAdd rc = " rc */
  173.   end
  174.  
  175. /* Check success, and do the job */
  176. if rc = 0 then do
  177.     say "Starting backup by looking for files"
  178.     do i = 0 to limit
  179.       rc = SysFileTree( paths.i || "\*", 'dirs', 'SDO', dattribs )
  180.  
  181.       if rc = 0 then do
  182.         pathcount = dirs.0
  183.         dirs.0 = paths.i
  184.         do j = 0 to pathcount
  185.           dirs.j =  dirs.j || "\"
  186.           /*  say "   dirs."j"=" dirs.j */
  187.           temporary = files.i                           
  188.           do while temporary \= ''
  189.             parse var temporary pfeil temporary /* REXX idiom for pulling
  190.                                                  * successive words out of a
  191.                                                  * string in a hurry
  192.                                                  */
  193.             searcher =  dirs.j || pfeil
  194.             rc = SysFileTree( searcher, 'fyles','FO', attrib ) 
  195.             /* say searcher "  rc =" rc "fyles.0 =" fyles.0 */
  196.             if (rc = 0) & (fyles.0 > 0) then do
  197.               commandtodo = extcmd searcher backupdisk parms
  198.               commandtodo
  199.               if new = 'N' then do
  200.                 new = 'O'  /* Once only!  */
  201.                 parms = '/A' parms
  202.                 /* say "PARMS FIXED"   */
  203.               end  /* if new = 'N'  */
  204.               /*  pull newbie */
  205.             end /* if ( rc = 0 ) & ( fyles.0 > 0 )  */
  206.             drop fyles /* Economize our memory space */
  207.           end  /* do k = 0 to filenamecount  */
  208.           /* pull newbie  */
  209.         end  /* do j = 0 to pathcount     */
  210.       end  /* if rc = 0 then do      */
  211.       else /* rc /= 0, SysFileTree failed */ do
  212.         say "SysFileTree call failed - exiting!"
  213.         return
  214.       end
  215.       drop dirs /* Ecnomize on space, probably not necessary */
  216.     end  /* do i = 1 to limit      */
  217.     /*  Now unload the entry point that was registered */
  218.  
  219.     call RxFuncDrop( 'SysFileTree' )
  220.     say "Backup procedure completed"
  221.  
  222.   end /* of do   */
  223.  
  224. else  say "Unable to load SysFileTree - execution ended" 
  225. RETURN        
  226.