home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / bakini.zip / BACKINI.CMD next >
OS/2 REXX Batch file  |  1994-02-02  |  4KB  |  143 lines

  1. /*rexx*/
  2. /* Copyright 1994 John H. Lederer                CIS:  74020,210
  3. Unlimited permission to use or modify is granted you so long as you agree
  4. to make improvements of general applicability available to the public
  5. by posting changed code on public BBS' or forums. */
  6. /*program checks the ini files in  the directory c:\os2 for changes
  7. by comparing ini.lst with a dir *.ini.  If there are changes it makes
  8. a several level backup. "*.tmp" is a copy of the current .ini file.
  9. "*.bak" is a backup copy of the prior ini file and *.bk2 is the prior
  10. ini file to that. */
  11.  
  12. /*==========================================================main control block*/
  13. /* main control block--- shows program logic */
  14. call initialize
  15. call getlists               /* get a new and old directory listing */
  16.  
  17. do x=6 to c-2               /* just the lines of directory having file listings*/
  18.    call checkchanges        /* see if there are differences */
  19.    if  changes then do      /* if there are then call a backup routine*/
  20.       if oldini then
  21.          call oldinibackup  /* backs up an exisiting, but changed file*/
  22.       else
  23.          call newinibackup  /* backs up a new file*/
  24.    end
  25.  
  26. end
  27.  
  28. call printmessage          /* gives the user a screen saying waht was done*/ 
  29. exit
  30. /*=========================================================initialize*/
  31.  
  32. initialize:
  33.  
  34.    /* initialize */
  35.    dirlist = "C:/OS2/INI.LST"
  36.    filelist.=""
  37.    c=0
  38.    ct =0
  39.    changes =0
  40. return
  41. /*=========================================================getlists*/ 
  42.  
  43. getlists:
  44.  
  45.    /* read in  old list */
  46.    filelist = charin(dirlist,1,99999)
  47.    ok = stream(dirlist,"C","CLOSE")
  48.    /* make new ini.list */
  49.    cmd ="DIR C:\OS2\*.INI > C:\OS2\INI.LST"
  50.    cmd
  51.    say "[BACKINI.CMD]: Wrote new ini.lst file."
  52.    /* read in new list*/
  53.  
  54.    do until lines(dirlist) = 0
  55.       c = c+1
  56.       newlist.c= linein(dirlist)
  57.    end
  58.  
  59.  
  60. return
  61.  
  62. /*=========================================================checkchanges*/ 
  63.  
  64. /* see if need to do a backup */
  65.  
  66. checkchanges:
  67. /*   sets flags, changes =1 if the directory listing for the file is different
  68.      or nonexistent.  Oldini = 1 if it exists but is different.*/
  69.  
  70.    root = strip(word(newlist.x,1))
  71.    /* see if the new directory line is in the old directory list */
  72.   if  pos(newlist.x,filelist) > 0 then
  73.       changes = 0  
  74.    else do
  75.       changes = 1
  76.       oldini = 0
  77.       if pos(root,filelist) > 0 then oldini = 1
  78.    end
  79.  
  80.  
  81. return
  82.  
  83. /*=========================================================oldinibackup*/
  84.  
  85. oldinibackup:
  86.  
  87.    /* file is a previously existing ini file that has changed */
  88.    say "[BACKINI.CMD]: Backup of "root".ini file changes initiated"
  89.    cmd = "ERASE "ROOT".BK2"
  90.    cmd
  91.    cmd = "RENAME "root".BAK *.BK2"
  92.    cmd
  93.    cmd = "RENAME "root".CUR *.BAK"
  94.    cmd
  95.    cmd = "COPY "root".INI  *.CUR"
  96.    cmd
  97.    ct = ct +1
  98.    msg.ct = "Created backup of changes in "root".ini file"
  99.  
  100. return
  101.  
  102. /*=========================================================newinibackup*/ 
  103. newinibackup:
  104.  
  105.    /* file is a new ini file */
  106.    say  "[BACKINI.CMD]:    " root".INI is a new ini file, initial backups initiated"
  107.    cmd = "COPY "||root||".INI  *.CUR"
  108.    cmd
  109.    cmd = "COPY "||root||".CUR *.BAK"
  110.    cmd
  111.    cmd = "COPY "||root||".BAK  *.BK2"
  112.    cmd
  113.    ct = ct +1
  114.    msg.ct = "Created initial backups of "root".ini file"
  115.  
  116. return
  117.  
  118. /*=========================================================printmessage*/ 
  119. printmessage:
  120.    say " "
  121.    say " "
  122.    say "=========================Backini Actions ===================="
  123.    ok = stream(dirlist,"C","CLOSE")
  124.    if ct = 0  then
  125.        say "No changes detected"
  126.   
  127. else
  128.    do x = 1 to ct
  129.       say msg.x
  130.    end
  131.  
  132.    say "=========================Backini Completed===================="
  133.    /* pause for 5 seconds to allow reading message */
  134. if ct > 0 then do 
  135.    x=time('E')
  136.  
  137.    do until (time('E') - x) > 5
  138.       nop
  139.    end
  140. end
  141. return
  142.  
  143.