Professional Documents
Culture Documents
Problem
Problem
Problem
For homework, you'll expand on what you learned by researching additional features of tar and
cron. In particular, you'll learn about:
You will have to complete a series of readings, exercises, and questions. Please record your
solution commands and answers to the questions in a text file for submission. Use the
template in Submission.md.
Instructions
Tar
Stripping Components
By default, tar includes directory structures when you unpack archives. For example:
# Extracts `Tardocs/Movies`
$ ls Tardocs
Movies
If you just want to extract the Movies directory, and not TarDocs/Movies , you can use the --
strip-components flag.
Exercise 1
Run: tar --help | less . Search for --strip-components .
Modifying Archives
You will often find yourself needing to add, remove, or update files from an existing tarball.
You can do this with the following flags:
Note that the <updated file> and <file to delete> must exist in <existing archive> for
the above commands to work.
In these exercises, you will practice using these flags to update an existing tarball.
Exercise 1
Incremental Backups
You'll often use tar to back up the same directories on a regular basis—e.g., you might back up
/home every day at midnight.
Full Backup: Create a new backup from scratch. This is what you've been doing with tar . In
this scenario, you'll back up every file in /home , every day. Full backups are safe, but slow,
and take up a lot of space.
Incremental Backups: Updates an existing backup with only the files that changed. For
example, if you back up /home on Sunday, and add a file called /home/new.file on
Monday, the next backup will only include /home/new.file . Since the other files didn't
change, they won't be backed up. Incremental backups are fast, and each incremental
backup is small.
A full backup is simply a tar archive. To restore it, you simply extract the archive.
Incremental backups are a little more complicated. You'll have one "base backup", such as
backup.tar . This is a full backup of the file system you want to save. This is also your starting
point. When you make incremental backups, tar will create small archives that only contain the
files that changed since you created backup.tar . So, you would end up with something like:
$ ls -1 /var/backups
base.tar
# Contains files that changed from/weren't in `base.tar`
incremental.1.tar
To restore from incremental backups, you need base.tar , and every incremental backup up to
the point of restoration.
A related skill is updating tar archives manually. This way, you can add/remove files to/from an
archive on an ad hoc basis.
For these exercises, you will create incremental backups with tar .
Exercise 1
Read more about incremental backups at: https://www.gnu.org/software/tar/manual/ht
ml_node/Incremental-Dumps.html
List the contents of your level 1 backup, and read /var/log/home.snar . Do you
see what you expect?
Cron
Managing crontabs
It is best practice to keep backups of your cron table. This ensures that there is a backup in case
of accidental deletion.
In the next exercise, you will practice writing commands using the cron simulator at https://cront
ab-generator.org to run on the Virtual Machine.
Using a simulator is a great way to validate existing cron statements or to create new ones. Using
a tool like this is a good habit to get into.
Part 1: Practice
Working in your home directory, launch the nano editor: nano cronsim.txt
Part 2: Schedule a job to run in your crontab file on the Virtual Machine.
First, return to your ~/Projects/TarDocs directory.
Now let's look at what the cron job will do. You'll use many of the commands from
previous activities.
The cron job should create a cronjob.tar tarball that contains ONLY the text files
in the ~/data/cron/Documents directory.
The job should then untar the tarball into a data/cron/exercises directory.
Suggestion: Try each part ( tar , untar ) of the command in a terminal window to make sure
they work.
Using the simulator schedule the job to run:
Tue, Thu and Sat - Note: some systems will not accept numbers. Please use the
names of the days.
Every 2 minutes
The cron job is a single line.
Copy the generated line into your crontab file.
Disable all the cron jobs from the lesson activities in your crontab.
Backup the file to backup-cron-jobs.txt .
Submission
Please fill out and submit the template in Submission.md.