CT320 HW3: backup script                
Individual Work                
Bash Shell Script                
The purpose of this assignment is to write a bash script called
backup that is both practical and uses many features of bash. Your
script may incidentally use other programs such as grep, but it must
be, primarily, a bash script.
                
Description                
This assignment consists of writing a backup and restore program for user data on a Linux system. This assignment will be graded on how you meet the requirements in this document, so read all parts of the assignment carefully. We have listed the requirements and a list of steps to follow.                 
Debugging                
If you encounter “STACK FRAME LINK OVERFLOW”, then try this:
export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a
Requirements                
The manager of system administration at your company is evaluating backup solutions from different companies, and has not yet found one that meets all the requirements. In the meantime he wants an interim solution for backing up user data on the Linux workstations in the engineering lab. Each workstation can have one or more user, each of whom often uses the workstation every day and has large amounts of data. The manager asks you to develop a bash script that will backup data on all workstations nightly. The same script must be capable of allowing you to restore data from the backup in case recovery is needed because files were accidentally deleted.                 
Steps                
Develop a bash script called backup that takes three command-line
arguments. The first argument is an action, which is either -S for
save or -R for restore. The second is the directory where user
accounts reside, which would normally be /home. The third argument
is the directory where the backup files will reside, for example
/tmp/archive.
                
The -S action causes the script to:
                
- Enumerate all users in the specified directory.
- Create tar files, one for each user, in the backup directory,
that contain the entire contents of that user’s home directory.
- The tar file name should be username
.tgz, where username is, well, the user’s name (login). - The
.tgzindicates that the tar file should be compressed using the gzip option to tar.
- The tar file name should be username
The script must also create a file in the backup directory called
backups-here that contains backup status:
                
- user name
- home directory
- backup date, in epoch seconds (seconds since 1970 began)
- number of non-directory files
- number of directories
- total backup size in bytes (after compression)
When the -R action is requested, the script will:
                
- Enumerate all users in the
backups-herefile. - Find the associated tar file for each user and
unpack it into
/tmp/workingdir.- If no backup is found, the
script should emit an error message that includes
“
There isn't anything available for username” and skip that user.
- If no backup is found, the
script should emit an error message that includes
“
- Do a recursive file-by-file check of the files in the backup against the files in the home directory. If a file exists in the backup but not the home directory, restore it.
- Delete
/tmp/workingdirbefore completing this command.
Here is an example of the format of backups-here:
                
smith,/home/smith,1475112654,100,10,14598723
jones,/home/jones,1475061234,6,1,15794175
Testing                
To verify your script, you must do the following:                 
- Create a directory in your home directory called
~/fakehome, and create user directories in it called alpha, beta, gamma, delta, and epsilon. - Populate the user directories. At least one user should have at least two levels of directory hierarchy, and every user should have multiple files.
- Put files in the hierarchy that have different content, size, and protection, for example you could include audio, video, photo, and text files.
- Use the find command to enumerate all of the files in
~/fakehomewith a full listing including size, date, and protections, and store it inbaseline.txt. - Run the script as
./backup -S ~/fakehome /tmp/archive. Ensure that the tar files are created correctly in/tmp/archive, and check thebackups-herefile. - Delete several random files from different user directories at different levels in the hierarchy to simulate files being accidentally lost.
- Run the script as
./backup -R ~/fakehome /tmp/archiveto restore any missing files for all users. - Repeat the
findcommand to enumerate all of the files in~/fakehomewith a full listing including size, date, and protections, and store it inrestored.txt. - Verify that
baseline.txtandrestored.txthave identical contents, thereby showing that the restore worked correctly.
More Requirements                
- Display a usage message and exit for:
- wrong number of arguments
- bad first argument
- Display an error message and exit for directory arguments that:
- aren’t directories
- aren’t readable
- aren’t executable
- All error messages go to stderr, not stdout.
- Any error message must include
$0. - Any error message that complains about an argument must mention the offending argument.
Hints                
No logging is required for the assignment. It’s ok if your script displays a few extra messages, but don’t display an extra message for every file or directory—that’s too much.                 
How to submit your homework:                
Via web checkin, or:                 
~ct320/bin/checkin HW3 backup
How to receive negative points:                
Turn in someone else’s work.                 
