home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 308.lha / treewalk / daily.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1980-12-05  |  3.3 KB  |  117 lines

  1. /*
  2.  * Daily - do daily dumps of it's arguments.
  3.  *
  4.  * For each argument dev (with no ':'), find all files on dev: that
  5.  * are newer than dev:last-backup, and copy them (complete with directory
  6.  * structure) to daily:dev.
  7.  *
  8.  * See build_exclusion for tailoring the list of files to be excluded from
  9.  * backing up. Note that the loop in main also does some filtering.
  10.  *
  11.  * Future enhancement: compress file to ram:, then copy it to daily:
  12.  *
  13.  *    Copyright (C) 1989  Mike Meyer
  14.  *
  15.  *    This program is free software; you can redistribute it and/or modify
  16.  *    it under the terms of the GNU General Public License as published by
  17.  *    the Free Software Foundation; either version 1, or any later version.
  18.  *
  19.  *    This program is distributed in the hope that it will be useful,
  20.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22.  *    GNU General Public License for more details.
  23.  *
  24.  *    You should have received a copy of the GNU General Public License
  25.  *    along with this program; if not, write to the Free Software
  26.  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27.  */
  28.  
  29. parse arg devices
  30.  
  31. logfile = 'logs:daily.backup'
  32.  
  33. if ~exists(logfile) then 'copy nil: to' logfile
  34. signal on error
  35. options failat 1
  36.  
  37. /* Build the exclusion list, and put it in clip space */
  38. call build_exclusions
  39.  
  40. do args = 1 to words(devices)
  41.     /* Verify we have a valid file system to backup up */
  42.     dev = word(devices, args)
  43.     if index(dev, ':') ~= 0 then do
  44.         call log "Don't specify ':' in device name" dev
  45.         iterate args
  46.         end
  47.     if ~exists(dev':last-backup') then do
  48.         call log dev':last-backup does not exist'
  49.         iterate args
  50.         end
  51.  
  52.     /* Ok, we're gonna do it, so tell the user about it */
  53.     call log "starting backup of" dev'.' dailysize() 'blocks free on daily:'
  54.  
  55.     /* Let treewalk run daily.ftw on real files, and do the real work */
  56.     'treewalk dir' dev': filter "file && date > 'dev':last-backup.date && daily && false"'
  57.  
  58.     /* Log that we're done with it all */
  59.     call log 'Backup of' dev 'done,' dailysize() 'blocks free on daily:'
  60.     end
  61.  
  62. exit
  63.  
  64. /*
  65.  * build_exclusions - returns a treewalk filter expression to test
  66.  * names in the file against the exclusion list.
  67.  */
  68. build_exclusions: procedure expose logfile
  69.  
  70.     'execio read s:mrbackup.xcld stem excludes.'
  71.     out = "name !* 'fish.mff'"    /* Bloody big file... */
  72.     do i = 1 to excludes.0
  73.         if left(excludes.i, 1) = '#' then iterate i
  74.         if verify(excludes.i, ":/", 'Match') = 0 then
  75.             out = out "&& filename !* '"excludes.i"'"
  76.         else out = out "&& name !* '"excludes.i"'"
  77.         end
  78.     call setclip "daily.backup", out
  79.     return
  80.  
  81. /*
  82.  * Returns the # of free blocks on the daily backup disk.
  83.  */
  84. dailysize: procedure expose logfile
  85.  
  86.     'info | execio locate daily for 1 var dailyline'
  87.     return word(dailyline, 4)
  88.  
  89.  
  90. /*
  91.  * Catch command errors, and diagnose them for the user.
  92.  */
  93. error:
  94.  
  95.     if syntax = 2 then do
  96.         call log "Interrupted; backup incomplete." dailysize() "blocks free."
  97.         exit
  98.         end
  99.  
  100.     call log 'line' sigl 'failed; backup incomplete.'
  101.     call log dailysize() "blocks free on daily:"
  102.     exit
  103.  
  104. /*
  105.  * Log - log the message we've been given.
  106.  */
  107. log: procedure expose logfile
  108.     parse arg message
  109.  
  110.     if ~open(file, logfile, 'Append') then do
  111.         say "Can't open" logfile', exiting!'
  112.         exit
  113.         end
  114.     call writeln file, date() time() || ':' message
  115.     call close file
  116.     return
  117.