File backup tools
Create and extract an archive
Package a directory with tar, inspect it before extraction, and restore into a separate destination.
An archive combines files and their metadata into one stream. That single file is easy to copy, checksum, and store. This is why tar has been the backbone of Unix backups for decades.
One thing to keep clear: compression changes the size, not the safety. A compressed archive on the same disk as the original protects you from nothing.
Create, inspect, extract
Let’s create a practice archive from a notes/ directory, look inside it, and restore it somewhere else:
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 creates, -z compresses with gzip, -f names the archive file. -t lists the contents, -x extracts, -C changes into a directory before extracting.
The -t listing is your inspection step. It prints every path in the archive:
notes/
notes/report.txt
notes/meetings/2026-07-14.md
Always look at this before extracting anything. You want relative paths under a single top-level directory. That way 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. Keep this habit: restore to a separate destination, verify, then decide what to move.
Verify the round trip
Compare the source and the restored files:
diff -r notes/ restored/notes/
No output means identical content. Silence is the success signal here.
Repeat the exercise with filenames containing spaces, symbolic links, and nested directories. These are exactly the cases where a naive backup script breaks. tar handles them all.
The failure mode
Inspect archives from untrusted sources before extracting. Paths and links can point at unexpected places. A malicious archive 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. Still, 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