Assignment 10

Task A – Backup your system (Using crontab) [100 points]
Scenario: Performing system backup can be time-consuming, and the process is often overlooked. For this scenario,
1. (10 Points) Create a new user Alice (with home directory) and

2. (50 Points) Write a shell script that backups Alice’s home directory by creating a tar file (tape archive), using the following steps:
a. • Take 2 inputs with their values- your MIDAS name and current date (for example, midas=svatsa).
• Create a variable named as filename that should be assigned the value as MIDAS-date (example output after executing the script would be like, svatsa- 2021.3.17-01.16.430).
• Using tar command, create a tape archive for Alice’s home directory (/home/Alice) and the filename created above (in step-2-ii). (Please learn about tar command in Linux for its usage)
b. Move the tape archive file/tar file (created in step 2-iii) to /var/backups/ directory using correct command in linux.
c. To optimize the disk usage, pick a compression algorithm (bz2, gzip, or xv) to compress the tar file you created in /var/backups/ in the previous step-2b.


3. (30 Points) Create a crontab file to keep the scheduled task running for 3 minutes, then check the contents in the /var/backups directory.

4. (10 Points) Cancel the crontab jobs.

TASK B: SYSTEM CLEANUP (EXTRA CREDIT) [20 Points]
Scenario: In the above scenario, your system disk will be filled up eventually without cleaning up the old backups. Therefore, in this optional task, create a script that checks the number of backups you created in Task A. If the number of the backup file is more than a pre-defined threshold, the script will delete the old archives to maintain the backups under a reasonable size. This script should do the following:
1. Count the number of backups created in Task A and determine if this number is larger than 3.
2. Nothing should happen if the number of backups is less than the threshold, 3.
3. If more backup archives are detected, calculate the number of backups to delete. Then delete the old archives.

Note: As the script needs to write contents in the “/var/backups” folder, which is owned by root, you should consider the permission issue properly. (Using sudo to create crontab file)

Leave a Reply

Your email address will not be published. Required fields are marked *