In an incremental backup, tar does not seem to be able to add new files :

$ tar -cvzf test.tar.gz -g test.snar a.txt
$ tar -cvzf test2.tar.gz -g test.snar a.txt b.txt

The second command returns nothing and the archive is empty. Yet it works if I specify the directory instead of the files. Anything I'm missing here ?


The snapshot file contains a.txt on the first tar command. On the second tar the snapshot does not know about b.txt. a.txt has not changed so the incremental archive is empty.

If the incremental archive is at directory level, it will detect the change (b.txt) because b.txt exists within the directory's heirarchy.

If the snapshot file exists, it determines which files are modified.

See GNU Tar reference incremental backups

The option ‘--listed-incremental’ instructs tar to operate on an incremental archive with additional metadata stored in a standalone file, called a snapshot file. The purpose of this file is to help determine which files have been changed, added or deleted since the last backup, so that the next incremental backup will contain only modified files. The name of the snapshot file is given as an argument to the option:

  • So tar only works well on directories for incremental backup then ? Feb 7 '14 at 13:16
  • In the way you are using it - yes. As an alternative you could remove the snapshot file if additional files are to be added.
    – suspectus
    Feb 7 '14 at 13:34

Have you looked at using the "–listed-incremental" option to tar ? It will allow you to incrementally add specific folders and helps to ensure you only compress the files changed since the last time they were added to tar with the --list-incremental option.

A more generic option is simply to append new files using -a or the append option, which puts the file onto the end of the archive.

If this is a backup situation, I'd suggest you look at rsync as a more feature rich option but again all depends on what you're trying to do with your backup procedure.

  • In my version, -g is a synonym for --listed-incremental. My question was more about why it works for directories and not for a list of files. Feb 7 '14 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.