$_ CLI In Depth
Learning progress 0%
build disks mounts archives

Build: An Incremental Backup with tar

5 min read Module 12: Disks, Mounts & Archives Updated Dec 5, 2026
Cheat Sheet
0:00 / 3:16

The shape of the backup

A backup strategy has three parts: a way to capture data, a record of what was captured, and a way to restore the captured data in the right order. A full backup captures everything and starts a chain. Each incremental backup captures the changes since the previous backup in the chain, and the chain is restored in order, starting from the full archive. The record is what lets the next run know what changed.

In GNU tar, the record is a snapshot file that you name with --listed-incremental. The first run with a new snapshot file is a full backup, because nothing is recorded yet. Later runs that reuse the file write only what changed and update the file as they go.

Step one: a full backup

Start with a directory of notes. Create two files, then run tar with a new snapshot file. The archive will contain the directory and both files, and the snapshot file will record their state.

BASH4 lines
mkdir -p notes
echo first > notes/a.txt
echo second > notes/b.txt
tar --listed-incremental=snap.snar -cf full.tar notes

The archive full.tar is a complete copy of the tree. The file snap.snar is plain text that tar wrote. Do not edit it by hand, and do not delete it, because deleting it makes the next run a full backup again.

Step two: an incremental backup

Change one file and add another. Reuse the same snapshot file. Tar compares the current state with the recorded state and includes only the entries that differ. The unchanged file is not written to the new archive.

BASH4 lines
sleep 1
echo updated >> notes/a.txt
echo third > notes/c.txt
tar --listed-incremental=snap.snar -cf incr.tar notes

The sleep 1 is a small guard. Snapshot comparisons use file times, and a change made within the same instant as the previous backup can be missed. A pause of a second makes the example reliable. Listing incr.tar should show a.txt and c.txt, and it should not show b.txt.

BASH1 lines
tar -tf incr.tar
Warning

Reusing one snapshot file for every run makes a chain that is only as good as its order. If you lose the full archive, the incremental archives cannot be restored correctly. Keep each archive and its snapshot together, and store copies off the machine.

Step three: restore the chain in order

Restore by extracting the full archive first and then the incremental archive into the same target directory. The incremental archive then overlays the changes. Extract into a new directory so that the original tree stays untouched, which is what makes the test meaningful.

BASH4 lines
mkdir -p restore
tar -xf full.tar -C restore
tar -xf incr.tar -C restore
diff -r notes restore/notes && echo restored

The final comparison is the proof. If the restored tree matches the current notes exactly, the chain is complete. If it does not, the difference shows which step is wrong. A backup that has not been restored and compared is not yet a backup.

Design choices that matter

The approach above is simple, and it has limits. A deleted file is recorded as deleted in the snapshot, but the plain extraction shown here does not remove files from the restore target, so a restore can keep a file that was deleted after the full backup. For a full restore of a changed tree, extract into an empty directory, as shown. Keep the snapshot file alongside the archives, because it is the only record of which files each run covered.

A second choice is the naming of archives. Put the date or a sequence number in each name, so the chain is visible. The tool does not need the names, but a person restoring a machine at night does.

Automating the chain

A backup you run by hand is a backup you eventually forget. A small script can run the same steps on a schedule and keep the snapshot file in one known place. The script should refuse to make an incremental when the full archive is missing, because an incremental without its base cannot be restored. It should also restore into a scratch directory and compare every time it runs, so a broken chain shows up on the day it breaks, not on the day you need it.

Choose a clear rule for when to start a new full backup, such as once a week or after a large change. Each new full archive gets a new snapshot file, so the old chain stays intact until you retire it. Keep at least one complete chain on a different disk or machine, because a backup on the same disk protects against mistakes but not against the failure of that disk.

Hands-on: build, change, and restore

Make the full and incremental archives from the steps above, then restore them into an empty directory and compare the result. Use the commands in order, and do not skip the comparison, because it is the part that proves the backup works.

BASH8 lines
tar --listed-incremental=snap.snar -cf full.tar notes
sleep 1
echo more >> notes/b.txt
tar --listed-incremental=snap.snar -cf incr.tar notes
mkdir -p check
tar -xf full.tar -C check
tar -xf incr.tar -C check
diff -r notes check/notes && echo verified

If the final line prints verified, the two archives together reproduce the notes tree. You have built the core of an incremental backup from the same tool you use to unpack a tarball.

Terminal lab · 3 steps · real Linux in your browser

Build an incremental backup

Make a full archive, an incremental archive that holds only changes, and restore the chain.

01
Make the full backup
Create a directory named notes with two files, a.txt and b.txt. Make a full archive named full.tar with a new snapshot file named snap.snar. The snapshot file is what makes the next run incremental. ``bash mkdir -p notes echo first > notes/a.txt echo second > notes/b.txt tar --listed-incremental=snap.snar -cf full.tar notes ``
Show hint for step 1
--listed-incremental=snap.snar records the state. Use the same file name for every run in the chain.
02
Make an incremental backup
Wait one second, then change a.txt and create c.txt. Run tar with the same snapshot file to make incr.tar. The archive should hold a.txt and c.txt, but not b.txt, which did not change. ``bash sleep 1 echo more >> notes/a.txt echo third > notes/c.txt tar --listed-incremental=snap.snar -cf incr.tar notes tar -tf incr.tar ``
Show hint for step 2
Reuse snap.snar exactly. A new snapshot file would make this a full backup again.
03
Restore the chain in order
Extract full.tar and then incr.tar into an empty directory named restore. Compare the restored notes with the current notes using diff -r. ``bash mkdir -p restore tar -xf full.tar -C restore tar -xf incr.tar -C restore diff -r notes restore/notes && echo restored ``
Show hint for step 3
Restore the full archive first. The incremental archive is applied on top of it in the same directory.
Check yourself Question 1 of 4
Concept Check The incremental option recall

Which GNU tar option names the snapshot file that makes a backup incremental?

Recap & Key Takeaways

A full backup starts a chain, and each incremental backup captures only what changed since the snapshot recorded by the previous run.
GNU tar uses --listed-incremental with a snapshot file, and reusing that file is what makes the next archive incremental.
Restore the full archive first and then the incremental archives, into an empty directory, and compare the result with diff -r.
Never delete or hand-edit the snapshot file, and keep it together with the archives it describes.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue