File backup tools
Create and extract an archive
Package a directory with tar, inspect it before extraction, and restore into a separate destination.
10 minute lesson
An archive combines files and metadata into one stream. That single file is easy to copy, checksum, and store, which is why tar has been the backbone of Unix backups for decades. Compression changes size, not whether the archive is an independent backup — a compressed archive on the same disk as the original protects you from nothing.
Create, inspect, extract
Create and restore a practice archive:
tar -czf notes.tar.gz notes/
tar -tzf notes.tar.gz
mkdir restored
tar -xzf notes.tar.gz -C restored
The flags read naturally once you decode them: -c create, -z gzip compression, -f the archive filename, -t list contents, -x extract, -C change to a directory before extracting.
The -t listing is your inspection step. It prints every path the archive contains:
notes/
notes/report.txt
notes/meetings/2026-07-14.md
Always look at this before extracting anything. You want to see relative paths under a single top-level directory, so extraction can’t scatter files around or overwrite something outside your target.
Extracting with -C restored keeps the restore away from the live notes/ directory. That’s a habit worth keeping: restore to a separate destination, verify, then decide what to move.
Verify the round trip
Compare source and restored files:
diff -r notes/ restored/notes/
# no output means identical content
Silence is the success signal here. Repeat the exercise with names containing spaces, symbolic links, and nested directories — these are exactly the cases where a naive backup script breaks, and tar handles them all.
The failure mode
Inspect archives from untrusted sources before extraction. Paths and links can target unexpected locations: an archive built maliciously can contain entries like ../../home/flavio/.bashrc or a symlink pointing outside the extraction directory. Modern GNU tar refuses absolute paths by default and warns about suspicious members, but the -t check costs you two seconds and removes the guesswork. Never extract straight into / or your home directory from an archive you didn’t create.
Lesson completed