Linux Labs

Storage / Stage 9 of 11

The archive exists — now check the restore

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 7 · theory · 6 min

What goes into the archive

Here is the list tar builds the archive from, and where .release got lost on the way.

tar packs files and directories into one archive file. The -c option creates an archive, -f sets its file name. Every stored file or directory is an archive member: a path, contents, mode, owner and modification time.

The nightly script builds the archive like this:

bash
cd ~/backup-lab/live
tar -cf /srv/backup-lab/app.tar app/*

app/* is a filename pattern: Bash replaces it with the list of matching names before tar even starts, as in the "Help and the shell" lesson. Names that start with a dot are not matched by *. tar received app/bin, app/config, app/data and app/secret.env, and never heard of .release.

Give tar a whole directory and it walks it itself, hidden files included:

bash
tar -cf /srv/backup-lab/app.tar -C ~/backup-lab/live app

-C changes into a directory before tar reads the names that follow. That is why the paths inside the archive start with app/. Whatever paths the archive records are the paths that appear on extraction:

Command Paths in the archive
tar -cf a.tar app/* app/bin/…, app/secret.env; no .release
tar -cf a.tar -C live app app/, app/.release, app/bin/…
tar -cf a.tar live/app live/app/… — an extra level
Check yourself 1 question

You are in student's home directory. You need to save all of it, .bashrc included. Which command does it?

  • tar stores everything it receives, but the * pattern hands it a list without the hidden names.

  • The same * pattern: Bash substitutes the names without a leading dot, and .bashrc stays out of the archive.

  • Bash expands the * pattern, and names starting with a dot stay out of the list. Check: echo /home/student/* does not show .bashrc.

Given a whole directory, tar walks it itself and stores every name, .bashrc included. Bash expands the * pattern before tar starts, and hidden names stay out of the list.

Key points

  • tar stores only the names it receives; given a whole directory, it walks it with every file, hidden ones included.
  • Bash expands the * pattern before tar starts, and names beginning with a dot stay out of the list.
  • The command decides the paths inside the archive: with -C live app they start with app/.
Ubuntu 24.04
Loading…