CSCI 344
Final Perl Program
Lab 14

I will not be in lab on May 4.

Labs 13 & 14 must be demonstrated in lab on May 11.


Write the following Perl script.  You may use the Internet as a reference for Perl and as a reference for UNIX/Linux commands, but you may not search for solutions to these problems--that would completely defeat the purpose of doing them.

Here is a link to a good intro to Perl:  perldoc.perl.org/perlintro.html

You may use the UNIX tar utility, but you may not use any other UNIX utility or tool (if you want to use /usr/bin/find you are on the wrong track, Perl does this for you).


1) (weight 10)  Write a backup utility that creates a complete or incremental backup.  If this is the first time backup has ever been called, create a complete backup (a .tar file that contains everything in the target directory, and its sub directories).  If this is not the first time it has been called, create an incremental backup (a .tar file of all the files that have been modified (including new files) since the last time backup has been run).  Do not create empty incremental backup files--if nothing has been modified, don't backup anything.

A very simple solution (which is about 75 lines of code) is outlined below.  This solution is pretty limited, but it would not be that hard to extend it into a useful tool.

You may implement something simple like my solution or something with more features.  


Simplifying assumptions:

Algorithm:

Create an array of all the files to be considered: @all_files
Make sure you skip "." ".." backup.tar backup.*.tar backup.times
If backup.times does not exist, create a tar of all the files in @all_files
If backup.times does exist
read backup.times into a hash
for each file in @all_files
if not in hash, or has a modification time greater than that in the hash,
add to @modified
create a tar file of all the files in @modified
Create the backup.times file, put an entry for each file in @all_files:  <filename,mtime>


Hints:

The package File::Find provides a mechanism for recursively traversing directories

The function system passes a command to /bin/sh to be executed.  For example:

system "tar -cf $filename @files";

will use the UNIX tar utility to create a .tar file called $filename with all the files in @files

You need to use the stat function to get modification times.  Copy the prototype for using it from a web page.

Break the problem into pieces and get the pieces working independently of the entire program.