First of all, read the notes about shell programming in Unix Shell Scripting (google also "bash tutorial" for other tutorials) and study the examples in the lab1-src directory. You can get those examples by downloading the file lab1-src.tar.gz and by typing:
bash> gunzip lab2-src.tar.gzNow that you are an expert in shell scripting write the following script to automatically back up a directory.
bash> tar -xvf lab2-src.tar
Write a backup script backupd.sh that
will automatically backup a directory.
backupd.sh dir
backupdir interval-secs max-backups
This script will first backup the directory dir by making a copy of dir in the directory backupdir/<current-date>.
Then, every interval-secs if
the dir has been modified
since the last backup, it will back it up again in the directory backupdir/<current-date>.
<current-date> will
have the format YYYY-MM-DD-hh-ss
To compare if a directory has been modified, first run a "ls -lR dir > ls-lR.last " before backing up dir. The command "ls -lR" lists the entries of a directory and subdirectories and displays the last modification time of every file. Then every interval-secs run again a" ls -lR dir > ls-lR.new". If ls-lR.new and ls-lR.last are different then back up the directory again into backupdir/<current-date> and copy ls-lR.new into ls-lR.last.
Algorithm:
ls -lR > ls-lR.last
copy the directory dir into backupdir/<current-date>
while (1) {
sleep interval-secs
ls -lR > ls-lR.new
diff ls-lR.new ls-lR.last
if (if they are different) {
copy the directory dir into backupdir/<current-date>
mv ls-lR.new ls-lR.last
}
}
Feature |
Grade (Max) |
Backup is done correctly |
30 |
Backup is done at regular
intervals |
10 |
Backup is done when there is a
difference |
10 |
Number of backups is limited to
max-backups |
20 |
Mail Notification works |
10 |
Script is well documented |
10 |
Robustness, runs without
crashing. |
10 |
0. Login to lore
1. Write a README file with your
Place the README file and backupd.sh in the directory lab1-src/
2. Make sure that your script is well written, with good comments
and it is easy to understand.
3. Go one directory above lab1-src and type:
turnin -c cs290 -p lab1 lab1-src
4. Verify that your files have been turned in by typing:
turnin -c cs290 -p lab1 -v
The deadline for lab2 is 11:59pm September 13th, 2010.