home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / perf31.zip / perf_30 / SIMPLBAK.CMD < prev    next >
OS/2 REXX Batch file  |  1994-01-06  |  10KB  |  327 lines

  1. /* Simple Backup*/
  2. /*Copyright (c) 1993 CLEAR & SIMPLE, INC.*/
  3. ECHO OFF
  4. arg directory destination frequency
  5. if directory='' | destination ='' then do
  6.    Say 'The format of SimpleBAK is:'
  7.    say;say '   SimplBAK  directory  destination '
  8.    say;say 'Please refer to PLUS documentation, and repeat.'
  9.         say 'SimplBAK use is most effective when setup with SetUPlus.Cmd'
  10.         say;say 'Press Enter to end...'; pull
  11. exit
  12.   end  /* Do */
  13. parse upper var destination driv '\' rest .
  14. FromDrive=left(directory,2)
  15. if frequency='' then frequency=0
  16. if right(directory,1)='\' then directory=strip(directory,'T','\')
  17. say 'Copyright (c) 1994 CLEAR & SIMPLE, INC.';say;
  18. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  19. call SysLoadFuncs
  20.  
  21. today=date('U')
  22. parse var today month '/' day '/' year
  23. call julian year month day
  24. todayJulian=result
  25. call FatOrHpfs
  26.  
  27. call getBackupDate
  28.  
  29. call szdisk driv
  30. parse var result tofree .
  31.  
  32. call dirsize directory
  33.  
  34. parse var result SizeOfFiles NumberOfFiles
  35.  
  36. if SizeOfFiles < toFree then call copyall
  37. else call copypart
  38.  
  39. exit
  40.  
  41. copyall:
  42. say 'Copying 'NumberofFiles 'Files'
  43. do j=1 to NumberofFiles
  44.    call copyfile
  45. end /* do */
  46. return
  47.  
  48. copypart:
  49. say 'Copying 'NumberofFiles 'Files'
  50. if driv='A:' | driv='B:' then diskette=1
  51. else diskette=0
  52.  
  53. if diskette then do
  54.    say 'There are 'NumberOfFiles 'Files to be backed up'
  55.    say 'They require 'SizeOfFiles 'free space on the diskette in 'driv' drive'
  56.    Say 'The diskette only has 'tofree' space available'
  57.    say 'Would you like to proceed with this diskette - type "Y"'
  58.     say '   or use a new diskette Type "N"?'
  59.    pull newdiskette
  60.    if newdiskette ='N' then do
  61.         say 'Insert a new diskette - Press Enter to proceed';pull
  62.         call mmd destination 'y'
  63.         call szdisk driv
  64.         parse var result tofree .
  65.        
  66.    end  /* newdiskette Do */
  67.  
  68.         do j=1 to dirs.0
  69.            if filesize.j<tofree then do
  70.                 call copyfile
  71.                 tofree=tofree-filesize.j
  72.                 end /*copyfile*/
  73.  
  74.            else do
  75.                 do while tofree < filesize.j
  76.                 call szdisk driv
  77.                 parse var result tofree .
  78.                 say 'There''s not enough room on the diskette for the next file'
  79.                 say 'The File Name is = 'dirs.j ' The file size is ='filesize.j
  80.                 say   'Diskette free space total is = 'tofree
  81.                 say 'There are ' filecount-j 'Files remaining to be copied'
  82.                 say 'Insert a new diskette - Press Enter to proceed';pull
  83.                 call szdisk driv
  84.                 parse var result tofree .
  85.                 end /* While tofree is smaller than filesize */
  86.                 call mmd destination 'y'
  87.                 call copyfile
  88.               end /* do */
  89.                
  90.        end /* j loop do */
  91.  
  92.  
  93. end  /* diskette = 1 Do */
  94. else do
  95.         say 'There is not enough room in the destination'
  96.         say ' -  '  destination 'Free Space=' tofree
  97.         say 'There are 'dirs.0 'files to be copied - they require 'SizeOfFiles 'Space'
  98.         Say 'Either change your destination 'destination ' or change the Frequency of backup' frequency
  99.         exit
  100. end /* not a diskette Do */
  101. return
  102.  
  103.  
  104. copyfile:
  105. fdestination=destination
  106. dirlen=lastpos('\',dirs.j)-3
  107. fullDir.j=substr(dirs.j,4,dirlen)
  108. fullDir.j=strip(fullDir.j,'T','\')
  109.  
  110.   if fatalert then do
  111.         parse var fulldir.j  '\' s.1 '\' s.2 '\' s.3 '\' s.4 '\' s.5 '\' s.6 '\' s.7 '\' s.8 '\' s.9 '\' s.10 '\' s.11 '\' s.12 '\' s.13 '\' s.14 '\' s.15 '\' s.16 '\' s.17 '\' s.18 '\' s.19 '\' s.20
  112.         h=1
  113.         fulldir.j=''
  114.         do while s.h \= ''
  115.  
  116.                 parse var s.h dname '.' dext
  117.                 dname=left(dname,8)
  118.                 dname=strip(dname)
  119.                 fulldir.j=fulldir.j'\'dname
  120.  
  121.                 if dext \='' then do
  122.                         dext=left(dext,3)
  123.                         dext=strip(dext)
  124.                         fulldir.j=fulldir.j'.'dext
  125.                         end  /* Do */
  126.                 h=h+1
  127.         end /* do while */
  128.   end  /* Fat Alert Do */
  129.  call mmd destination||fulldir.j 'y'
  130.  
  131. fdestination=destination||fulldir.j
  132.  
  133.  
  134.  
  135. if FatAlert then do
  136.         dirlen=lastpos('\',dirs.j)
  137.         fullDir.j=left(dirs.j,dirlen)
  138.         parse var filename.j first'.'ext'.'addl
  139.         if length(first) > 8 | length(ext) >3 | addl \='' then long=1
  140.         else long=0
  141.  
  142.         shortn.j=left(first,8)
  143.         shortn.j=strip(shortn.j)
  144.         shortext.j=left(ext,3)
  145.         shortext.j=strip(shortext.j)
  146.         if long then do
  147.                 duplicatecheck:
  148.                 k=j-1
  149.                 do while k>0
  150.                         dirlen=lastpos('\',dirs.k)
  151.                         fullDir.k=left(dirs.k,dirlen)
  152.                         if fulldir.k=fulldir.j then do
  153.                           if shortn.k=shortn.j then do
  154.                                 if datatype(shortext.k,N) then do;shortext.j=1+shortext.k;k=0;end
  155.                                 else do; shortext.j=1;k=0; end
  156.  
  157.                             end  /* dup shortn Do */
  158.                           k=k-1;
  159.                          end /* fulldir do */
  160.                  else  k=0; /* there are no duplicates in this directory */
  161.            end /* K do */
  162.  
  163.          fdestination=fdestination'\'shortn.j
  164.          if shortext.j \= ''  then fdestination=fdestination'.'shortext.j
  165.  
  166.         end  /* long Do */
  167.  
  168. end  /* FAT Drive Do */
  169. fdestination='"'fdestination'"'
  170. say 'Copying ...'dirs.j  'to'  fdestination
  171. 'copy ' dirs.j fdestination '>nul'
  172. return
  173.  
  174. dirsize:
  175. newq= RXQUEUE('create')
  176. oq=RXQUEUE('Set', newq)
  177. totalsize=0;filecount=0
  178.  
  179. 'Dir ' directory '/s/n/o:-d | rxqueue 'newq
  180. do until queued() = 0
  181. entry=lineIN('Queue:')
  182. parse var entry filedate ftime fsize easize name
  183. name=strip(name,L)
  184. fmo='';fday='';fyr='';
  185. parse upper var filedate fmo '-' fday '-' fyr;
  186. if fyr ='' then do;
  187.    if translate(filedate)='DIRECTORY'  then  directory=fsize
  188. iterate
  189.    end  /* fyr */
  190. else do /*Date & Time Convert*/
  191.  
  192.         call julian fyr fmo fday
  193.         jdate=result
  194.         if jdate=bakdate then do
  195.                 parse var ftime hr ':' min
  196.                 if right(min,1)='p' then hr=hr+12
  197.                 fileTime=hr'.'left(min,2)
  198.                 if filetime > baktime then jdate=jdate+1 
  199.  
  200.              end /* jdate=bakdate */
  201.                 
  202.       end  /* Date & time convert */
  203. if jdate > bakdate+frequency then do;
  204.  
  205.    if datatype(fsize,N) then do;
  206.         totalsize=totalsize+fsize+easize;
  207.         filecount=filecount+1
  208.         dirs.filecount='"'directory'\'name'"'
  209.         filename.filecount=name;
  210.         filesize.filecount=fsize+easize
  211.         end  /* datatype */
  212.    else totalsize=totalsize+easize
  213.   end  /* frequency */
  214. else call dirsearch /* no more in this directory */
  215.   end /* do queued() */
  216. rc=rxqueue('delete', newQ)
  217. dirs.0=filecount
  218. return totalsize filecount
  219.  
  220. dirsearch:
  221. do until strip(filedate)='DIRECTORY' | queued()=0
  222. entry=lineIN('Queue:')
  223. parse upper var entry filedate ftime fsize easize name;
  224.    if strip(filedate)='DIRECTORY'  then  directory=fsize
  225. end
  226. return
  227.  
  228. getBackupDate:
  229.  
  230. parse var directory fromdrive'\'fromdir
  231. newdir=destination'\'fromdir
  232. parse var newdir todirdrive'\'newdir
  233. newdir='\'newdir
  234. /*
  235. if fatalert then do
  236.         parse var newdir  '\' d.1 '\' d.2 '\' d.3 '\' d.4 '\' d.5 '\' d.6 '\' d.7 '\' d.8 '\' d.9 '\' d.10 '\' d.11 '\' d.12 '\' d.13 '\' d.14 '\' d.15 '\' d.16 '\' d.17 '\' d.18 '\' d.19 '\' d.20
  237.         f=1
  238.         newdir=''
  239.         do while d.f \= ''
  240.  
  241.                 parse var d.f dxname '.' dxext
  242.                 dxname=left(dxname,8)
  243.                 dxname=strip(dxname)
  244.                 newdir=newdir'\'dxname
  245.  
  246.                 if dxext \='' then do
  247.                         dxext=left(dxext,3)
  248.                         dxext=strip(dxext)
  249.                         newdir=newdir'.'dxext
  250.                         end  /* Do */
  251.                 f=f+1
  252.         end /* do while */
  253.   end  /* Fat Alert Do */
  254. newdir=todirdrive||newdir
  255. call mmd newdir 'Y'
  256. */
  257. if lines(directory'\p21pbak') = 0 then
  258. do; bakdate=todayjulian; baktime=0;end
  259.  
  260. else do;   do until lines(directory'\p21pbak') = 0
  261.                 parse value linein(directory'\p21pbak') with bakdate baktime .
  262.         end /*until do */
  263.         if bakdate='' then do;bakdate=todayjulian;baktime=0;end
  264.         call lineout directory'\p21pbak'
  265.         end /*else do*/
  266. parse value time('N') with nowhr ':' nowmin ':' nowsec
  267. nowtime=nowhr'.'nowmin
  268. datetime= todayjulian nowtime
  269. call lineout directory'\p21pbak',todayjulian nowtime '-' month'/'day'/'year
  270. call lineout directory'\p21pbak'
  271.  
  272.  
  273.  
  274. /*
  275. if result then do; bakdate=todayjulian; baktime=0;end
  276.   else do
  277.    nobakdate=0
  278.         do until lines(newdir'\p21pbak') = 0
  279.                 parse value linein(newdir'\p21pbak') with bakdate baktime
  280.         end /*until*/
  281.         if bakdate='' then do;bakdate=todayjulian;baktime=0;end
  282.         call lineout newdir'\p21pbak'
  283.  end  /* else do */
  284.  
  285. parse value time('N') with nowhr ':' nowmin ':' nowsec
  286. nowtime=nowhr'.'nowmin
  287. datetime= todayjulian nowtime
  288. call lineout newdir'\p21pbak',todayjulian nowtime
  289. */
  290.  
  291. return
  292.  
  293. FatOrHpfs:
  294.  
  295. rc=SysMkDir(FromDrive'\'muchtoolargeforFAT)
  296. if rc=206  then do; FatAlert=0; return; end
  297. else DO; FromHPFS=1; call SysRmDir(drive'\'muchtoolargeforfat);END
  298.  
  299. rc=SysMkDir(destination'\'muchtoolargeforFAT)
  300. if rc=206  then FatAlert=1
  301. else DO; FatAlert=0; call SysRmDir(drive'\'muchtoolargeforfat);END
  302. RETURN
  303.  
  304. julian:
  305. arg cyear cmonth cday
  306. cmonth=strip(cmonth,'L',0)
  307. if cyear // 4=0 & cyear // 200 \=0 then leap=1
  308. else leap=0
  309. mo.1=0
  310. mo.2=31
  311. mo.3=59+leap
  312. mo.4=90+leap
  313. mo.5=120+leap
  314. mo.6=151+leap
  315. mo.7=181+leap
  316. mo.8=212+leap
  317. mo.9=243+leap
  318. mo.10=273+leap
  319. mo.11=304+leap
  320. mo.12=334+leap
  321. DofYr=mo.cmonth+cday
  322. if length(DofYr)=1 then dofyr='00'||dofyr
  323. else if length(DofYr)=2 then dofyr='0'||dofyr
  324.    else if length(DofYr)\=3 then do; say date error; exit; end
  325. jdate=right(cyear,2)||DofYr
  326. return jdate
  327.