Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this recitation, you will write a BASH script which will backup a directory, keeping only the last N days of backups (default 5). Your
In this recitation, you will write a BASH script which will backup a directory, keeping only the last N days of backups (default 5). Your script should be able to change this value via the command-line.
The skills that you will demonstrate:
- Ability to write a bash program
- Ability to access command-line arguments
- Ability to run programs from your script and capture the output
- Ability to use tar and gzip to pack a directory into a compressed file
Complete the following tasks. You may receive guidance from your instructor or other students. All code that you submit should be written by you.
- Obtain the name of the directory from the command line as a required parameter.
- Check for an optional switch and parameter (-t
) which will override the default retention - Calculate the name of the backup file based on the directory and the date. Ex: src_2020_01_27
- Use tar cvfz
- Remove any files older than N days from the backup directory.
Some useful hints:
- The date program can output in any format. Try date +%Y for an example
- In your script you can capture the output of command lines in reverse quotes `date`
- Your output filename should be built up as a string by concatenation
- The find command can delete certain files. Look at -mtime and -delete switches.
Requirements:
- Your program should be named backup.sh without the quotes.
- You should include your name and EUID in a comment at the top of the file
- Your program should use the bash shell
- The optional switch -t will take a numeric argument in days
- The default retention is 5 days
- Create a new directory of your choice to hold backups
- Your program will be graded largely on whether is works correctly on the CSE machines (e.g. cse01, cse02, , cse06) so you should make sure that your program compiles and runs correctly on one of these machines.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started